Merge branch '17-email-login-does-not-work' into 'dev'
Resolve "Email login does not work" Closes #17 See merge request sa4-2020/the-sanmarinoes/backend!22
This commit is contained in:
commit
033b52af18
2 changed files with 14 additions and 2 deletions
|
@ -45,6 +45,7 @@ public class AuthenticationController {
|
|||
@PostMapping("/login")
|
||||
public JWTResponse login(@Valid @RequestBody JWTRequest authenticationRequest)
|
||||
throws Exception {
|
||||
final UserDetails userDetails;
|
||||
if (authenticationRequest.getUsernameOrEmail().contains("@")) {
|
||||
// usernameOrEmail contains an email, so fetch the corresponding username
|
||||
final User user =
|
||||
|
@ -54,16 +55,19 @@ public class AuthenticationController {
|
|||
throw new UserNotFoundException();
|
||||
}
|
||||
|
||||
System.out.println(user);
|
||||
System.out.println(authenticationRequest);
|
||||
|
||||
authenticate(user.getUsername(), authenticationRequest.getPassword());
|
||||
userDetails = userDetailsService.loadUserByUsername(user.getUsername());
|
||||
} else {
|
||||
// usernameOrEmail contains a username, authenticate with that then
|
||||
authenticate(
|
||||
authenticationRequest.getUsernameOrEmail(),
|
||||
authenticationRequest.getPassword());
|
||||
userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsernameOrEmail());
|
||||
}
|
||||
|
||||
final UserDetails userDetails =
|
||||
userDetailsService.loadUserByUsername(authenticationRequest.getUsernameOrEmail());
|
||||
final String token = jwtTokenUtil.generateToken(userDetails);
|
||||
return new JWTResponse(token);
|
||||
}
|
||||
|
|
|
@ -19,4 +19,12 @@ public class JWTRequest {
|
|||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JWTRequest{" +
|
||||
"usernameOrEmail='" + usernameOrEmail + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue