Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Lost password feature #755

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

Merged
merged 21 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a2bd841
feature: Initial Implementation of `lost-password` api endpoint
irfan-ikhwa Feb 14, 2024
ceabd3b
feature: Initial Implementation of Email Sending Feature with dummy D…
irfan-ikhwa Feb 17, 2024
c4b18bd
feature: Initial Password reset flow implementation
irfan-ikhwa Feb 18, 2024
96081d3
feature: Added email template in OrganizationCommonSettings, Added pu…
irfan-ikhwa Feb 20, 2024
d5c63ea
feature: Added emailTemplate in common-settings.
irfan-ikhwa Feb 22, 2024
0a213f4
Merge branch 'dev' into lost-password-feature
aq-ikhwa-tech Feb 25, 2024
65d9e2a
Misc fixes
aq-ikhwa-tech Feb 25, 2024
39ad3ac
Misc fixes
aq-ikhwa-tech Feb 26, 2024
72518dc
Update application.props
aq-ikhwa-tech Feb 26, 2024
d384418
Update application.props to include smtp server auth
aq-ikhwa-tech Feb 26, 2024
810d669
Merge branch 'lowcoder-org:main' into lost-password-feature
aq-ikhwa-tech Feb 26, 2024
758f86f
Merge branch 'dev' into lost-password-feature
aq-ikhwa-tech Feb 26, 2024
0391d2a
feature: Added Env Variables for SMPT server
irfan-ikhwa Feb 27, 2024
bc74e8a
feature: Rename SMTP Env variable to ADMIN
irfan-ikhwa Feb 27, 2024
30dcd9c
Merge branch 'dev' into lost-password-feature
FalkWolsky Mar 5, 2024
5343945
changed the API response to empty in case user does not exist.
irfan-ikhwa Mar 13, 2024
833c22b
Added env Variables.
irfan-ikhwa Mar 13, 2024
c5447c3
Added ssl auth.
irfan-ikhwa Mar 14, 2024
e5613c5
updated email sender filed name
irfan-ikhwa Mar 14, 2024
a8b2ece
updated email sender filed name
irfan-ikhwa Mar 14, 2024
ac6eb29
Merge branch 'dev' into lost-password-feature
FalkWolsky Mar 14, 2024
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
Prev Previous commit
Next Next commit
feature: Initial Password reset flow implementation
  • Loading branch information
irfan-ikhwa committed Feb 18, 2024
commit c4b18bd65055c3a298b11faeadbbd33ee6cb8ffb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean sendMail(String to, String token, String message) {
mimeMessageHelper.setSubject(subject);

// Construct the message with the token link
String resetLink = "http://localhost:8080/lost-password?token=" + token;
String resetLink = "http://localhost:8080/api/users/lost-password/" + token;
String messageWithLink = message + "\n\nReset your password here: " + resetLink;
mimeMessageHelper.setText(messageWithLink, true); // Set HTML to true to allow links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public interface UserService {

Mono<Void> lostPassword(String userEmail);

Mono<Void> resetLostPassword(String userEmail, String token, String newPassword);

Mono<Boolean> setPassword(String userId, String password);

Mono<UserDetail> buildUserDetail(User user, boolean withoutDynamicGroups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,30 @@ public Mono<Void> lostPassword(String userEmail) {
}
user.setPasswordResetToken(HashUtils.hash(token.getBytes()));
user.setPasswordResetTokenExpiry(tokenExpiry);
return Mono.empty();
return repository.save(user).then(Mono.empty());
});
}

@Override
public Mono<Void> resetLostPassword(String userEmail, String token, String newPassword) {
return findByName(userEmail)
.flatMap(user -> {
if (Instant.now().until(user.getPasswordResetTokenExpiry(), ChronoUnit.MINUTES) <= 0) {
return ofError(BizError.LOGIN_EXPIRED, "TOKEN_EXPIRED");
}

if (!StringUtils.equals(HashUtils.hash(token.getBytes()), user.getPasswordResetToken())) {
return ofError(BizError.INVALID_PASSWORD, "INVALID_TOKEN");
}

if (StringUtils.isBlank(newPassword)) {
return ofError(BizError.INVALID_PASSWORD, "PASSWORD_NOT_SET_YET");
}

user.setPassword(encryptionService.encryptPassword(newPassword));
user.setPasswordResetToken(StringUtils.EMPTY);
user.setPasswordResetTokenExpiry(Instant.now());
return repository.save(user).then(Mono.empty());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public Mono<Void> lostPassword(String userEmail) {
return userService.lostPassword(userEmail);
}

public Mono<Void> resetLostPassword(String userEmail, String token, String newPassword) {
return userService.resetLostPassword(userEmail, token, newPassword);
}

// ========================== TOKEN OPERATIONS START ==========================

public Mono<Void> saveToken(String userId, String source, String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ public Mono<ResponseView<Void>> lostPassword(@RequestBody LostPasswordRequest re
.map(ResponseView::success);
}

@Override
public Mono<ResponseView<Void>> resetLostPassword(@PathVariable String token, @RequestBody ResetLostPasswordRequest request) {
if (StringUtils.isBlank(request.userEmail()) || StringUtils.isBlank(token)
|| StringUtils.isBlank(request.newPassword())) {
return ofError(BizError.INVALID_PARAMETER, "INVALID_PARAMETER");
}

return userApiService.resetLostPassword(request.userEmail(), token, request.newPassword())
.map(ResponseView::success);
}

@Override
public Mono<ResponseView<Boolean>> setPassword(@RequestParam String password) {
if (StringUtils.isBlank(password)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ public interface UserEndpoints
public Mono<ResponseView<String>> resetPassword(@RequestBody ResetPasswordRequest request);

@PostMapping("/lost-password")
public Mono<ResponseView<Void>> lostPassword(@RequestBody LostPasswordRequest userEmail);
public Mono<ResponseView<Void>> lostPassword(@RequestBody LostPasswordRequest request);

@PostMapping("/lost-password/{token}")
public Mono<ResponseView<Void>> resetLostPassword(@PathVariable String token, @RequestBody ResetLostPasswordRequest request);

@Operation(
tags = TAG_USER_PASSWORD_MANAGEMENT,
Expand Down Expand Up @@ -157,6 +160,9 @@ public record ResetPasswordRequest(String userId) {
public record LostPasswordRequest(String userEmail) {
}

public record ResetLostPasswordRequest(String userEmail, String newPassword) {
}

public record UpdatePasswordRequest(String oldPassword, String newPassword) {
}

Expand Down