убрал ограничения объекта для вашего проекта

This commit is contained in:
Anton Romanov 2023-12-05 16:19:45 +04:00
parent 928e7a1e30
commit 18827a9028
2 changed files with 21 additions and 3 deletions

View File

@ -51,6 +51,16 @@ public class UserDto {
roles = new LinkedHashSet<>(); roles = new LinkedHashSet<>();
} }
public UserDto(String login, String password) {
this();
this.login = login;
this.password = password;
this.passwordConfirm = password;
this.email = "email@email.ru";
this.firstName = "user";
this.lastName = "user";
}
public UserDto(User user) { public UserDto(User user) {
this(); this();
this.id = user.getId(); this.id = user.getId();

View File

@ -82,11 +82,14 @@ public class UserService implements UserDetailsService {
throw new UserPasswordsNotValidOrNotMatchException(); throw new UserPasswordsNotValidOrNotMatchException();
} }
User user = userMapper.userDtoToUserEntity(userDto); User user = userMapper.userDtoToUserEntity(userDto);
user.setActivated(false); user.setActivated(true);
user.setActivationKey(UserUtils.generateActivationKey());
user.setRoles(Collections.singleton(new UserRole(UserRoleConstants.USER)));
user.setPassword(passwordEncoder.encode(userDto.getPassword())); user.setPassword(passwordEncoder.encode(userDto.getPassword()));
user = userRepository.save(user); user = userRepository.save(user);
//user.setActivationKey(UserUtils.generateActivationKey());
Set<UserRole> set = new HashSet<>();
set.add(new UserRole(UserRoleConstants.USER));
user.setRoles(set);
user = userRepository.save(user);
//TODO: mailService.sendActivationEmail(user); //TODO: mailService.sendActivationEmail(user);
log.debug("Created Information for User: {}", user.getLogin()); log.debug("Created Information for User: {}", user.getLogin());
return userMapper.userEntityToUserDto(user); return userMapper.userEntityToUserDto(user);
@ -259,4 +262,9 @@ public class UserService implements UserDetailsService {
.map(role -> new SimpleGrantedAuthority(role.getName())) .map(role -> new SimpleGrantedAuthority(role.getName()))
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
public void createDefaultRoles() {
userRoleRepository.save(new UserRole(UserRoleConstants.USER));
userRoleRepository.save(new UserRole(UserRoleConstants.ADMIN));
}
} }