make reset password Kotlin/Android app functional
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/pr-main This commit looks good

- small refactor for resetPassword
This commit is contained in:
Elias Harb
2026-02-23 18:30:15 +01:00
parent 57e9beb33f
commit 82014b1d9c
4 changed files with 13 additions and 12 deletions
@@ -13,8 +13,6 @@ import SuMoC.backend.user.models.User;
import SuMoC.backend.user.repository.UserRepository;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.MailException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -155,7 +153,6 @@ public class AuthenticationService {
});
String otp = generate_six_digit_OTP();
passwordResetTokenRepository.save(new PasswordResetToken(email, passwordEncoder.encode(otp))); //encoded otp
emailService.sendPasswordResetEmail(email, otp);
}
@@ -171,18 +168,17 @@ public class AuthenticationService {
}
//use .matches() so compare raw otp to (salted!) encoded otp
if(!passwordEncoder.matches(passwordResetDTO.getOtp_code(),token.getOtp_code())){
if(!passwordEncoder.matches(passwordResetDTO.getOtpCode(),token.getOtpCode())){
throw new InvalidTokenException("Code ist ungültig");
}
if(!isPasswordFormatCorrect(passwordResetDTO.getNew_password())) {
if(!isPasswordFormatCorrect(passwordResetDTO.getNewPassword())) {
throw new InvalidTokenException("Passwortformat ist nicht korrekt");
}
User user = userRepository.findByEmail(passwordResetDTO.getEmail())
.orElseThrow(() -> new UsernameNotFoundException("User existiert nicht"));
user.setPassword(passwordEncoder.encode(passwordResetDTO.getNew_password()));
user.setPassword(passwordEncoder.encode(passwordResetDTO.getNewPassword()));
userRepository.save(user);
passwordResetTokenRepository.delete(token);
}