提交 c0494124 authored 作者: Whispa's avatar Whispa

commit commit

上级 5ee8c47c
...@@ -71,26 +71,26 @@ public class AuthController extends Controller { ...@@ -71,26 +71,26 @@ public class AuthController extends Controller {
@PostMapping("/signin") @PostMapping("/signin")
public Result authenticateUser(@RequestBody LoginRequest loginRequest) { public Result authenticateUser(@RequestBody LoginRequest loginRequest) {
Optional<TbCfUserInfo> byAccount = userRepository.findByFirebaseUid(loginRequest.getAccount()); Optional<TbCfUserInfo> byAccount = userRepository.findFirstByAccount(loginRequest.getAccount());
Result<Object> notFound = new Result<>(ResultCodeEnum.VALIDATE_ERROR.getCode(), "User not found"); Result<Object> notFound = new Result<>(ResultCodeEnum.VALIDATE_ERROR.getCode(), "User not found");
if (!byAccount.isPresent()) { if (!byAccount.isPresent()) {
//
boolean b = userRepository.existsByAccount(loginRequest.getAccount()); // boolean b = userRepository.existsByAccount(loginRequest.getAccount());
//
if (b) { // if (b) {
Optional<TbCfUserInfo> firstByAccount = userRepository.findFirstByAccount(loginRequest.getAccount()); // Optional<TbCfUserInfo> firstByAccount = userRepository.findFirstByAccount(loginRequest.getAccount());
if (firstByAccount.isPresent()) { // if (firstByAccount.isPresent()) {
TbCfUserInfo userInfo = firstByAccount.get(); // TbCfUserInfo userInfo = firstByAccount.get();
userInfo.setFirebaseUid(loginRequest.getAccount()); // userInfo.setFirebaseUid(loginRequest.getAccount());
fixCode(userInfo); // fixCode(userInfo);
try { // try {
userRepository.save(userInfo); // userRepository.save(userInfo);
} catch (Exception e) { // } catch (Exception e) {
return notFound; // return notFound;
} // }
byAccount = Optional.of(userInfo); // byAccount = Optional.of(userInfo);
} else return notFound; // } else return notFound;
} else // } else
return notFound; return notFound;
} }
...@@ -106,9 +106,9 @@ public class AuthController extends Controller { ...@@ -106,9 +106,9 @@ public class AuthController extends Controller {
String jwt = jwtUtils.generateJwtToken(authentication); String jwt = jwtUtils.generateJwtToken(authentication);
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal(); UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
List<String> roles = userDetails.getAuthorities().stream() // List<String> roles = userDetails.getAuthorities().stream()
.map(GrantedAuthority::getAuthority) // .map(GrantedAuthority::getAuthority)
.collect(Collectors.toList()); // .collect(Collectors.toList());
TbCfUserInfo userInfo = byAccount.get(); TbCfUserInfo userInfo = byAccount.get();
...@@ -118,10 +118,6 @@ public class AuthController extends Controller { ...@@ -118,10 +118,6 @@ public class AuthController extends Controller {
userInfo.setFcm(loginRequest.getFcm()); userInfo.setFcm(loginRequest.getFcm());
} }
if (loginRequest.getVeryOldPassword() != null) {
userInfo.setPassword(loginRequest.getVeryOldPassword());
}
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfo.setUserType(UserTypeEnum.EMAIL.getCode()); userInfo.setUserType(UserTypeEnum.EMAIL.getCode());
...@@ -189,7 +185,7 @@ public class AuthController extends Controller { ...@@ -189,7 +185,7 @@ public class AuthController extends Controller {
} }
signUpRequest.setFirebaseUid(email); //signUpRequest.setFirebaseUid(email);
signUpRequest.setAccount(email); signUpRequest.setAccount(email);
signUpRequest.setUserId(IdUtil.createIdbyUUID()); signUpRequest.setUserId(IdUtil.createIdbyUUID());
...@@ -311,12 +307,6 @@ public class AuthController extends Controller { ...@@ -311,12 +307,6 @@ public class AuthController extends Controller {
} }
// // generate token codes has been moved downwards from if condition of checking if user doesn't exist in database, because even if
// // user exist we have to generate token also
// if (user.getPassword() == null || gotFromOld) {
// user.setFirebaseUid(firebaseUid);// Assign user from database to the user we have to return back to request
// // user.setPassword(encoder.encode(firebaseUid));// Assign user from database to the user we have to return back to request
// }
fixCode(user); fixCode(user);
......
...@@ -5,9 +5,7 @@ public class LoginRequest { ...@@ -5,9 +5,7 @@ public class LoginRequest {
private String account; private String account;
private String password; private String password;
private String veryOldPassword;
private String fcm; private String fcm;
private boolean fromUser = false;
public LoginRequest(){ public LoginRequest(){
...@@ -19,13 +17,6 @@ public class LoginRequest { ...@@ -19,13 +17,6 @@ public class LoginRequest {
this.password = password; this.password = password;
} }
public void setFromUser(boolean fromUser) {
this.fromUser = fromUser;
}
public boolean isFromUser() {
return fromUser;
}
public LoginRequest(String account, String password, String fcm){ public LoginRequest(String account, String password, String fcm){
this.account = account; this.account = account;
...@@ -33,13 +24,6 @@ public class LoginRequest { ...@@ -33,13 +24,6 @@ public class LoginRequest {
this.fcm = fcm; this.fcm = fcm;
} }
public void setVeryOldPassword(String veryOldPassword) {
this.veryOldPassword = veryOldPassword;
}
public String getVeryOldPassword() {
return veryOldPassword;
}
public String getAccount() { public String getAccount() {
return account; return account;
......
...@@ -20,7 +20,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { ...@@ -20,7 +20,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
@Override @Override
@Transactional @Transactional
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
TbCfUserInfo user = userRepository.findByFirebaseUid(username) TbCfUserInfo user = userRepository.findFirstByAccount(username)
.orElseThrow(() -> new UsernameNotFoundException("User Not Found with username: " + username)); .orElseThrow(() -> new UsernameNotFoundException("User Not Found with username: " + username));
return UserDetailsImpl.build(user); return UserDetailsImpl.build(user);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论