Skip to content

Commit

Permalink
new version 0.2.0
Browse files Browse the repository at this point in the history
stats get updated every 5min
switched account and ip verification
  • Loading branch information
de-luxe committed Jun 17, 2016
1 parent 9a34e80 commit 4e5cfb7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<name>burstcoin-faucet</name>
<groupId>burstcoin</groupId>
<artifactId>burstcoin-faucet</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.0-RELEASE</version>

<properties>
<java.version>1.8</java.version>
Expand Down
77 changes: 43 additions & 34 deletions src/main/java/burstcoin/faucet/controller/FaucetController.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public String index(Model model)
model.addAttribute("faucetBalance", (Long.valueOf(balance.getUnconfirmedBalanceNQT()) / 100000000) + " BURST");
model.addAttribute("reCaptchaPublicKey", BurstcoinFaucetProperties.getPublicKey());

if(lastStatsUpdate == null || lastStatsUpdate.getTime() < new Date().getTime() - (1000 * 60 /* 30 sec. */))
if(lastStatsUpdate == null || lastStatsUpdate.getTime() < new Date().getTime() - (1000 * 60 * 5 /* 5 minutes */))
{
stats = getStats(numericFaucetAccountId);
lastStatsUpdate = new Date();
Expand Down Expand Up @@ -146,53 +146,62 @@ public String claim(@RequestParam("accountId") String accountId, HttpServletRequ
}
}

// get client ip
String ip = request.getHeader("X-FORWARDED-FOR");
if(ip == null)
{
ip = request.getRemoteAddr();
}

IPAddress ipAddress = null;
if(ip != null)
// check account
Account account = getAccount(accountId);
if(account.getLastClaim() == null || new Date().getTime() > (account.getLastClaim().getTime() + claimInterval))
{
ipAddress = getIPAddress(ip);
}
boolean ipCanClaim = ipAddress == null || ipAddress.getLastClaim() == null || new Date().getTime() > (ipAddress.getLastClaim().getTime() + claimInterval);
// check ip
String ip = request.getHeader("X-FORWARDED-FOR");
if(ip == null)
{
ip = request.getRemoteAddr();
}

Account account = getAccount(accountId);
boolean addressCanClaim = account.getLastClaim() == null || new Date().getTime() > (account.getLastClaim().getTime() + claimInterval);
IPAddress ipAddress = null;
if(ip != null)
{
ipAddress = getIPAddress(ip);
}

if(ipCanClaim && addressCanClaim)
{
if(recaptchaValidator.validate(request).isSuccess())
if(ipAddress == null || ipAddress.getLastClaim() == null || new Date().getTime() > (ipAddress.getLastClaim().getTime() + claimInterval))
{
SendMoneyResponse sendMoneyResponse = networkComponent
.sendMoney(BurstcoinFaucetProperties.getClaimAmount(), accountId, BurstcoinFaucetProperties.getPassPhrase());
if(sendMoneyResponse != null)
// check recaptcha
if(recaptchaValidator.validate(request).isSuccess())
{
if(ipAddress != null)
SendMoneyResponse sendMoneyResponse = networkComponent.sendMoney(BurstcoinFaucetProperties.getClaimAmount(), accountId,
BurstcoinFaucetProperties.getPassPhrase());
if(sendMoneyResponse != null)
{
ipAddress.setLastClaim(new Date());
ipAddressRepository.save(ipAddress);
}
// update ip
if(ipAddress != null)
{
ipAddress.setLastClaim(new Date());
ipAddressRepository.save(ipAddress);
}

account.setLastClaim(new Date());
accountRepository.save(account);
// update account
account.setLastClaim(new Date());
accountRepository.save(account);

return "redirect:/?success=" + BurstcoinFaucetProperties.getClaimAmount() + " BURST send to " + account.getAccountId();
}
else
{
return "redirect:/?error=Sry, faucet could not access Wallet, to send your BURST.";
return "redirect:/?success=" + BurstcoinFaucetProperties.getClaimAmount() + " BURST send to " + account.getAccountId();
}
else
{
return "redirect:/?error=Sry, faucet could not access Wallet, to send your BURST.";
}
}
}
else
{
long ipTime = (ipAddress.getLastClaim().getTime() + claimInterval) - new Date().getTime();
return "redirect:/?error=No BURST send. Please wait at least " + ((ipTime) / (60 * 1000))
+ " minutes, before claim again with your accounts.";
}
}
else
{
long accountTime = (account.getLastClaim().getTime() + claimInterval) - new Date().getTime();
long ipTime = (ipAddress.getLastClaim().getTime() + claimInterval) - new Date().getTime();
return "redirect:/?error=No BURST send. Please wait at least " + ((ipTime > accountTime ? ipTime : accountTime) / (60 * 1000))
return "redirect:/?error=No BURST send. Please wait at least " + ((accountTime) / (60 * 1000))
+ " minutes, before claim again.";
}
return "redirect:/?error=Unexpected problem ... could not send BURST.";
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/burstcoin/faucet/network/NetworkComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public Balance getBalance(String accountId)
}
catch(Exception e)
{
LOG.warn("Error: Failed to 'getBalance' for accountId '" + accountId + "' : " + e.getMessage());

LOG.warn("Error: Failed to 'getBalance' for accountId '" + accountId + "' : " + e.getMessage(), e);
}
return balance;
}
Expand Down

0 comments on commit 4e5cfb7

Please sign in to comment.