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

Skip to content

Commit 39ad3ac

Browse files
committed
Misc fixes
1 parent 65d9e2a commit 39ad3ac

File tree

8 files changed

+17
-15
lines changed

8 files changed

+17
-15
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/organization/model/Organization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public OrganizationCommonSettings getCommonSettings() {
8686
public static class OrganizationCommonSettings extends HashMap<String, Object> {
8787
public static final String USER_EXTRA_TRANSFORMER = "userExtraTransformer";
8888
public static final String USER_EXTRA_TRANSFORMER_UPDATE_TIME = "userExtraTransformer_updateTime";
89-
public static final String PASSWORD_RESET_EMAIL_TEMPLATE = "passwordRestEmailTemplate";
89+
public static final String PASSWORD_RESET_EMAIL_TEMPLATE = "passwordResetEmailTemplate";
9090
// custom branding configs
9191
public static final String CUSTOM_BRANDING_KEY = "branding";
9292
}

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/organization/service/OrganizationServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ public Mono<Organization> create(Organization organization, String creatorId) {
158158
if (organization == null || StringUtils.isNotBlank(organization.getId())) {
159159
return Mono.error(new BizException(BizError.INVALID_PARAMETER, "INVALID_PARAMETER", FieldName.ORGANIZATION));
160160
}
161-
organization.getCommonSettings().put(PASSWORD_RESET_EMAIL_TEMPLATE,
161+
organization.setCommonSettings(new OrganizationCommonSettings());
162+
organization.getCommonSettings().put("PASSWORD_RESET_EMAIL_TEMPLATE",
162163
PASSWORD_RESET_EMAIL_TEMPLATE_DEFAULT);
163164
organization.setState(ACTIVE);
164165
return Mono.just(organization);

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/user/service/EmailCommunicationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public boolean sendPasswordResetEmail(String to, String token, String message) {
3030
mimeMessageHelper.setSubject(subject);
3131

3232
// Construct the message with the token link
33-
String resetLink = config.getLowcoderPublicUrl() + "lost-password?token=" + token;
33+
String resetLink = config.getLowcoderPublicUrl() + "/lost-password?token=" + token;
3434
String formattedMessage = String.format(message, to, resetLink);
3535
mimeMessageHelper.setText(formattedMessage, true); // Set HTML to true to allow links
3636

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/user/service/UserServiceImpl.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,11 @@ public Mono<Boolean> resetLostPassword(String userEmail, String token, String ne
295295
return findByName(userEmail)
296296
.flatMap(user -> {
297297
if (Instant.now().until(user.getPasswordResetTokenExpiry(), ChronoUnit.MINUTES) <= 0) {
298-
return ofError(BizError.LOGIN_EXPIRED, "TOKEN_EXPIRED");
298+
return ofError(BizError.INVALID_PARAMETER, "TOKEN_EXPIRED");
299299
}
300300

301301
if (!StringUtils.equals(HashUtils.hash(token.getBytes()), user.getPasswordResetToken())) {
302-
return ofError(BizError.INVALID_PASSWORD, "INVALID_TOKEN");
303-
}
304-
305-
if (StringUtils.isBlank(newPassword)) {
306-
return ofError(BizError.INVALID_PASSWORD, "PASSWORD_NOT_SET_YET");
302+
return ofError(BizError.INVALID_PARAMETER, "INVALID_TOKEN");
307303
}
308304

309305
user.setPassword(encryptionService.encryptPassword(newPassword));

server/api-service/lowcoder-sdk/src/main/resources/locale_en.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ CANNOT_DELETE_SYSTEM_GROUP=System group cannot be deleted.
1717
NEED_DEV_TO_CREATE_RESOURCE=Invalid operation, workspace developers or admin required.
1818
UNABLE_TO_FIND_VALID_ORG=Cannot find a valid workspace for current user.
1919
USER_BANNED=Current account is frozen.
20+
SENDING_EMAIL_FAILED=Email could not be sent. Please check the smtp settings for the org.
21+
TOKEN_EXPIRED=Token to reset the password has expired
22+
INVALID_TOKEN=Invalid token received for password reset request
2023
# invitation
2124
INVALID_INVITATION_CODE=Invitation code not found.
2225
ALREADY_IN_ORGANIZATION=You are already in this workspace.

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/security/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
114114
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/me"),
115115
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/currentUser"),
116116
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, USER_URL + "/lost-password"),
117+
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, USER_URL + "/reset-lost-password"),
117118

118119
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, GROUP_URL + "/list"), // application view
119120
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, QUERY_URL + "/execute"), // application view
@@ -141,6 +142,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
141142
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/me"),
142143
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/currentUser"),
143144
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, NewUrl.USER_URL + "/lost-password"),
145+
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, NewUrl.USER_URL + "/reset-lost-password"),
144146
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.GROUP_URL + "/list"),
145147
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, NewUrl.QUERY_URL + "/execute"),
146148
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.MATERIAL_URL + "/**"),

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/usermanagement/UserController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ public Mono<ResponseView<Boolean>> lostPassword(@RequestBody LostPasswordRequest
156156
}
157157

158158
@Override
159-
public Mono<ResponseView<Boolean>> resetLostPassword(@PathVariable String token, @RequestBody ResetLostPasswordRequest request) {
160-
if (StringUtils.isBlank(request.userEmail()) || StringUtils.isBlank(token)
159+
public Mono<ResponseView<Boolean>> resetLostPassword(@RequestBody ResetLostPasswordRequest request) {
160+
if (StringUtils.isBlank(request.userEmail()) || StringUtils.isBlank(request.token())
161161
|| StringUtils.isBlank(request.newPassword())) {
162162
return ofError(BizError.INVALID_PARAMETER, "INVALID_PARAMETER");
163163
}
164164

165-
return userApiService.resetLostPassword(request.userEmail(), token, request.newPassword())
165+
return userApiService.resetLostPassword(request.userEmail(), request.token(), request.newPassword())
166166
.map(ResponseView::success);
167167
}
168168

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/usermanagement/UserEndpoints.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public interface UserEndpoints
124124
@PostMapping("/lost-password")
125125
public Mono<ResponseView<Boolean>> lostPassword(@RequestBody LostPasswordRequest request);
126126

127-
@PostMapping("/lost-password/{token}")
128-
public Mono<ResponseView<Boolean>> resetLostPassword(@PathVariable String token, @RequestBody ResetLostPasswordRequest request);
127+
@PostMapping("/reset-lost-password")
128+
public Mono<ResponseView<Boolean>> resetLostPassword(@RequestBody ResetLostPasswordRequest request);
129129

130130
@Operation(
131131
tags = TAG_USER_PASSWORD_MANAGEMENT,
@@ -160,7 +160,7 @@ public record ResetPasswordRequest(String userId) {
160160
public record LostPasswordRequest(String userEmail) {
161161
}
162162

163-
public record ResetLostPasswordRequest(String userEmail, String newPassword) {
163+
public record ResetLostPasswordRequest(String token, String userEmail, String newPassword) {
164164
}
165165

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

0 commit comments

Comments
 (0)