Skip to content

Commit

Permalink
fixed possible spamming by resending confirmation emails
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Aug 1, 2021
1 parent 6e66044 commit 043be60
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main/java/com/erudika/scoold/controllers/SigninController.java
Expand Up @@ -182,9 +182,20 @@ public String signup(@RequestParam String name, @RequestParam String email, @Req
}

@PostMapping("/signin/register/resend")
public String signup(@RequestParam String email, HttpServletRequest req, HttpServletResponse res, Model model) {
if (!utils.isAuthenticated(req) && isAccountLocked(email)) {
utils.sendVerificationEmail(email, req);
public String resend(@RequestParam String email, HttpServletRequest req, HttpServletResponse res, Model model) {
if (!utils.isAuthenticated(req)) {
Sysprop ident = pc.read(email);
// confirmation emails can be resent once every 6h
if (ident != null && !StringUtils.isBlank((String) ident.getProperty(Config._EMAIL_TOKEN)) &&
(!ident.hasProperty("confirmationTimestamp") || Utils.timestamp() >
((long) ident.getProperty("confirmationTimestamp") + TimeUnit.HOURS.toMillis(6)))) {
User u = pc.read(Utils.type(User.class), ident.getCreatorid());
if (u != null && !u.getActive()) {
utils.sendVerificationEmail(email, req);
ident.addProperty("confirmationTimestamp", Utils.timestamp());
pc.update(ident);
}
}
}
return "redirect:" + SIGNINLINK + "/register?verify=true";
}
Expand Down Expand Up @@ -303,7 +314,7 @@ private boolean isEmailRegistered(String email) {
return ident != null && ident.hasProperty(Config._PASSWORD);
}

public boolean isAccountLocked(String email) {
private boolean isAccountLocked(String email) {
Sysprop ident = pc.read(email);
if (ident != null && !StringUtils.isBlank((String) ident.getProperty(Config._EMAIL_TOKEN))) {
User u = pc.read(Utils.type(User.class), ident.getCreatorid());
Expand Down

0 comments on commit 043be60

Please sign in to comment.