Skip to content

Commit

Permalink
Resetting password and deleting account can be done with the UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Dec 17, 2024
1 parent 3ee9a49 commit b17a915
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nonononoki.alovoa.service;

import com.nonononoki.alovoa.component.ExceptionHandler;
import com.nonononoki.alovoa.entity.User;
import com.nonononoki.alovoa.model.AccountDeletionRequestDto;
import com.nonononoki.alovoa.model.AlovoaException;
Expand All @@ -14,6 +15,7 @@
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.UUID;

@Service
public class ImprintService {
Expand Down Expand Up @@ -53,6 +55,13 @@ public void deleteAccountRequest(AccountDeletionRequestDto dto) throws AlovoaExc
throw new AlovoaException(publicService.text("backend.error.captcha.invalid"));
}
User user = userRepository.findByEmail(dto.getEmail());

if (user == null) {
try{
UUID uuid = UUID.fromString(dto.getEmail());
user = userRepository.findByUuid(uuid);
} catch (IllegalArgumentException ignored){}
}
if (user != null) {
userService.deleteAccountRequestBase(user);
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/nonononoki/alovoa/service/PasswordService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Date;
import java.util.Objects;
import java.util.UUID;

import com.nonononoki.alovoa.component.ExceptionHandler;
import jakarta.mail.MessagingException;
Expand Down Expand Up @@ -61,7 +63,15 @@ public UserPasswordToken resetPassword(PasswordResetDto dto)
User u = userRepo.findByEmail(Tools.cleanEmail(dto.getEmail()));

if (u == null) {
throw new AlovoaException(ExceptionHandler.USER_NOT_FOUND);
try{
UUID uuid = UUID.fromString(dto.getEmail());
u = userRepo.findByUuid(uuid);
} catch (IllegalArgumentException exception){
throw new AlovoaException(ExceptionHandler.USER_NOT_FOUND);
}
if (u == null) {
throw new AlovoaException(ExceptionHandler.USER_NOT_FOUND);
}
}

if (u.isAdmin()) {
Expand Down Expand Up @@ -101,7 +111,8 @@ public void changePassword(PasswordChangeDto dto) throws AlovoaException {
}
User user = token.getUser();

if (!user.getEmail().equals(Tools.cleanEmail(dto.getEmail()))) {
if (!Objects.equals(user.getEmail(),Tools.cleanEmail(dto.getEmail())) &&
!Objects.equals(user.getUuid().toString(), Tools.cleanEmail(dto.getEmail()))) {
throw new AlovoaException("wrong_email");
}
if (user.isAdmin()) {
Expand Down

0 comments on commit b17a915

Please sign in to comment.