Skip to content

Commit 2add579

Browse files
authored
Merge pull request #1 from entityc/bobgarner/fix-signup
Fixed issue where a newly signed up user couldn't login. Also now aut…
2 parents 8b476fb + cf33f42 commit 2add579

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

security/userdetails/PersistentUserDetailsService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
5151
${mapVariableName}.put(${usernameAttribute|domain:Model|name}, obj);
5252
return obj;
5353
}
54+
55+
public void updateUser(${modelClassName} user) {
56+
${mapVariableName}.put(user.get${usernameAttribute|domain:Model|name|capitalize}(), user);
57+
}
5458
}

web/thymeleaf-bootstrap/auth/LoginSignupWebPageController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public String signup(Model model) {
185185

186186
@PostMapping(value = "/signup")
187187
public String registerUserAccount(@ModelAttribute("user") @Valid UserSignupDto userDto,
188-
BindingResult result) throws ServiceException {
188+
BindingResult result, HttpServletResponse res) throws ServiceException {
189189

190190
${userEntity|domain:Model|name} existing = userDetailsService.findBy${usernameFieldName|capitalize}(userDto.getUsername());
191191
if (existing != null) {
@@ -197,7 +197,7 @@ public String registerUserAccount(@ModelAttribute("user") @Valid UserSignupDto u
197197
}
198198

199199
save(userDto);
200-
return "redirect:${urlPathPrefix}/signup?success";
200+
return login(userDto.getUsername(), userDto.getPassword(), res);
201201
}
202202

203203
public ${userEntity|domain:Model|name} save(UserSignupDto userSignupDto) throws ServiceException {
@@ -218,7 +218,9 @@ public String registerUserAccount(@ModelAttribute("user") @Valid UserSignupDto u
218218
$[/if]
219219
user.set${userEntity.attributeOfTypeTagged("role")|domain:Model|name|capitalize}(roles);
220220
$[/if]
221-
return userService.createUser(user);
221+
${userEntity|domain:Model|name} createdUser = userService.createUser(user);
222+
userDetailsService.updateUser(createdUser);
223+
return createdUser;
222224
}
223225
$[/if]
224226
}

0 commit comments

Comments
 (0)