Skip to content

Commit

Permalink
Handle anonymous users in reset password
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Dec 10, 2023
1 parent 068507b commit b5fcec6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ Please fill out the form below to change your account settings or your password.

</div>
</form>

<br>
<hr>

<br>
<h3>API Access</h3>

<p>This service provides a rich RestAPI to submit, monitor and download jobs.</p>
Expand All @@ -88,9 +88,9 @@ Please fill out the form below to change your account settings or your password.


{{/user.hasApiToken}}

<br>
<hr>

<br>
<h3>Delete Account</h3>

<p>Once you delete your user account, there is no going back. Please be certain.</p>
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/cloudgene/mapred/api/v2/users/ResetPassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Representation get(Representation entity) {
Form form = new Form(entity);
String username = form.getFirstValue("username");

if (username == null || username.isEmpty()) {
if (username == null || username.trim().isEmpty()) {
return new JSONAnswer("Please enter a valid username or email address.", false);
}

Expand Down Expand Up @@ -66,13 +66,17 @@ public Representation get(Representation entity) {
String body = getWebApp().getTemplate(Template.RECOVERY_MAIL, user.getFullName(), application, link);

try {
log.info(String.format("Password reset link requested for user '%s'", username));
MailUtil.notifySlack(getSettings(), "Hi! " + username + " asked for a new password :key:");

MailUtil.send(getSettings(), user.getMail(), subject, body);
if (user.getMail()!= null && !user.getMail().isEmpty()) {
log.info(String.format("Password reset link requested for user '%s'", username));
MailUtil.notifySlack(getSettings(), "Hi! " + username + " asked for a new password :key:");
MailUtil.send(getSettings(), user.getMail(), subject, body);

return new JSONAnswer(
"Email sent to " + user.getMail() + " with instructions on how to reset your password.", true);
return new JSONAnswer(
"We sent you an email with instructions on how to reset your password.", true);
} else {
return new JSONAnswer("No email address is associated with the provided username. Therefore, password recovery cannot be completed.", false);
}

} catch (Exception e) {

Expand Down

0 comments on commit b5fcec6

Please sign in to comment.