Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 31 test and improve forgot password flow #45

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.digitalsanctuary.spring.user.exceptions.UserAlreadyExistException;
import com.digitalsanctuary.spring.user.persistence.model.User;
import com.digitalsanctuary.spring.user.service.DSUserDetails;
import com.digitalsanctuary.spring.user.service.UserEmailService;
import com.digitalsanctuary.spring.user.service.UserService;
import com.digitalsanctuary.spring.user.service.UserService.TokenValidationResult;
import com.digitalsanctuary.spring.user.util.JSONResponse;
Expand All @@ -38,6 +39,7 @@
@RequestMapping(path = "/user", produces = "application/json")
public class UserAPI {
private final UserService userService;
private final UserEmailService userEmailService;
private final MessageSource messages;
private final ApplicationEventPublisher eventPublisher;

Expand Down Expand Up @@ -138,7 +140,7 @@ public ResponseEntity<JSONResponse> resendRegistrationToken(final UserDto userDt
// Else send new token email
log.debug("UserAPI.resendRegistrationToken:" + "sending a new verification token email.");
String appUrl = UserUtils.getAppUrl(request);
userService.userEmailService.sendRegistrationVerificationEmail(user, appUrl);
userEmailService.sendRegistrationVerificationEmail(user, appUrl);
// Return happy path response
AuditEvent resendRegTokenAuditEvent = new AuditEvent(this, user, request.getSession().getId(), UserUtils.getClientIP(request),
request.getHeader("User-Agent"), "Resend Reg Token", "Success", "Success", null);
Expand Down Expand Up @@ -196,7 +198,7 @@ public ResponseEntity<JSONResponse> resetPassword(final UserDto userDto, final H

if (user != null) {
String appUrl = UserUtils.getAppUrl(request);
userService.userEmailService.sendForgotPasswordVerificationEmail(user, appUrl);
userEmailService.sendForgotPasswordVerificationEmail(user, appUrl);

AuditEvent resetPasswordAuditEvent = new AuditEvent(this, user, request.getSession().getId(), UserUtils.getClientIP(request),
request.getHeader("User-Agent"), "Reset Password", "Success", "Success", null);
Expand All @@ -209,7 +211,7 @@ public ResponseEntity<JSONResponse> resetPassword(final UserDto userDto, final H
eventPublisher.publishEvent(resetPasswordAuditEvent);
}

return new ResponseEntity<JSONResponse>(JSONResponse.builder().success(true).redirectUrl(forgotPasswordChangeURI)
return new ResponseEntity<JSONResponse>(JSONResponse.builder().success(true).redirectUrl(forgotPasswordPendingURI)
.message("If account exists, password reset email has been sent!").build(), HttpStatus.OK);
}

Expand Down
Loading