fixed login
This commit is contained in:
parent
b6add2aaf6
commit
8c1a0db920
2 changed files with 14 additions and 2 deletions
|
@ -45,6 +45,7 @@ public class AuthenticationController {
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public JWTResponse login(@Valid @RequestBody JWTRequest authenticationRequest)
|
public JWTResponse login(@Valid @RequestBody JWTRequest authenticationRequest)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
final UserDetails userDetails;
|
||||||
if (authenticationRequest.getUsernameOrEmail().contains("@")) {
|
if (authenticationRequest.getUsernameOrEmail().contains("@")) {
|
||||||
// usernameOrEmail contains an email, so fetch the corresponding username
|
// usernameOrEmail contains an email, so fetch the corresponding username
|
||||||
final User user =
|
final User user =
|
||||||
|
@ -54,16 +55,19 @@ public class AuthenticationController {
|
||||||
throw new UserNotFoundException();
|
throw new UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println(user);
|
||||||
|
System.out.println(authenticationRequest);
|
||||||
|
|
||||||
authenticate(user.getUsername(), authenticationRequest.getPassword());
|
authenticate(user.getUsername(), authenticationRequest.getPassword());
|
||||||
|
userDetails = userDetailsService.loadUserByUsername(user.getUsername());
|
||||||
} else {
|
} else {
|
||||||
// usernameOrEmail contains a username, authenticate with that then
|
// usernameOrEmail contains a username, authenticate with that then
|
||||||
authenticate(
|
authenticate(
|
||||||
authenticationRequest.getUsernameOrEmail(),
|
authenticationRequest.getUsernameOrEmail(),
|
||||||
authenticationRequest.getPassword());
|
authenticationRequest.getPassword());
|
||||||
|
userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsernameOrEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
final UserDetails userDetails =
|
|
||||||
userDetailsService.loadUserByUsername(authenticationRequest.getUsernameOrEmail());
|
|
||||||
final String token = jwtTokenUtil.generateToken(userDetails);
|
final String token = jwtTokenUtil.generateToken(userDetails);
|
||||||
return new JWTResponse(token);
|
return new JWTResponse(token);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,12 @@ public class JWTRequest {
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "JWTRequest{" +
|
||||||
|
"usernameOrEmail='" + usernameOrEmail + '\'' +
|
||||||
|
", password='" + password + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue