diff --git a/backend/src/main/java/com/example/backend/core/security/UserPrincipal.java b/backend/src/main/java/com/example/backend/core/security/UserPrincipal.java index b81ce30..d51cf25 100644 --- a/backend/src/main/java/com/example/backend/core/security/UserPrincipal.java +++ b/backend/src/main/java/com/example/backend/core/security/UserPrincipal.java @@ -12,7 +12,6 @@ public class UserPrincipal implements UserDetails { private final long id; private final String username; private final String password; - private final boolean isAdmin; private final Set roles; private final boolean active; @@ -20,7 +19,6 @@ public class UserPrincipal implements UserDetails { this.id = user.getId(); this.username = user.getLogin(); this.password = user.getPassword(); - this.isAdmin = user.getIsAdmin(); this.roles = Set.of(user.getRole()); this.active = true; } @@ -39,10 +37,6 @@ public class UserPrincipal implements UserDetails { return password; } - public boolean getIsAdmin() { - return isAdmin; - } - @Override public Collection getAuthorities() { return roles; diff --git a/backend/src/main/java/com/example/backend/users/api/UserDTO.java b/backend/src/main/java/com/example/backend/users/api/UserDTO.java index 8b756f7..01d359a 100644 --- a/backend/src/main/java/com/example/backend/users/api/UserDTO.java +++ b/backend/src/main/java/com/example/backend/users/api/UserDTO.java @@ -23,9 +23,6 @@ public class UserDTO { @NotNull private UserRole role; - @NotNull - private boolean isAdmin; - @JsonProperty(access = JsonProperty.Access.READ_ONLY) public Integer getId() { return id; @@ -58,12 +55,4 @@ public class UserDTO { public void setRole(UserRole role) { this.role = role; } - - public boolean getIsAdmin() { - return isAdmin; - } - - public void setIsAdmin(boolean isAdmin) { - this.isAdmin = isAdmin; - } } diff --git a/backend/src/main/java/com/example/backend/users/api/UserSignupController.java b/backend/src/main/java/com/example/backend/users/api/UserSignupController.java index b464e8e..88f40c2 100644 --- a/backend/src/main/java/com/example/backend/users/api/UserSignupController.java +++ b/backend/src/main/java/com/example/backend/users/api/UserSignupController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import com.example.backend.core.configurations.Constants; import com.example.backend.users.model.UserEntity; +import com.example.backend.users.model.UserRole; import com.example.backend.users.service.UserService; import jakarta.validation.Valid; @@ -26,17 +27,19 @@ public class UserSignupController { private static final String USER_ATTRIBUTE = "user"; private final UserService userService; - private final ModelMapper modelMapper; public UserSignupController( UserService userService, ModelMapper modelMapper) { this.userService = userService; - this.modelMapper = modelMapper; } private UserEntity toEntity(UserSignupDTO dto) { - return modelMapper.map(dto, UserEntity.class); + final UserEntity entity = new UserEntity(); + entity.setLogin(dto.getLogin()); + entity.setPassword(dto.getPassword()); + entity.setRole(dto.getIsAdmin() ? UserRole.ADMIN : UserRole.USER); + return entity; } @GetMapping diff --git a/backend/src/main/java/com/example/backend/users/model/UserEntity.java b/backend/src/main/java/com/example/backend/users/model/UserEntity.java index b29fc03..f6b551d 100644 --- a/backend/src/main/java/com/example/backend/users/model/UserEntity.java +++ b/backend/src/main/java/com/example/backend/users/model/UserEntity.java @@ -4,7 +4,6 @@ import java.util.Objects; import com.example.backend.core.model.BaseEntity; -import io.micrometer.common.lang.NonNull; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Table; @@ -19,19 +18,15 @@ public class UserEntity extends BaseEntity { @Column(nullable = false, length = 90) private String password; - @NonNull - private boolean isAdmin; - private UserRole role; public UserEntity() { } - public UserEntity(Integer id, String login, String password, boolean isAdmin) { + public UserEntity(Integer id, String login, String password) { this.login = login; this.password = password; - this.isAdmin = isAdmin; this.role = UserRole.USER; } @@ -51,14 +46,6 @@ public class UserEntity extends BaseEntity { this.password = password; } - public boolean getIsAdmin() { - return isAdmin; - } - - public void setIsAdmin(boolean isAdmin) { - this.isAdmin = isAdmin; - } - public UserRole getRole() { return role; } @@ -82,7 +69,6 @@ public class UserEntity extends BaseEntity { return Objects.equals(other.getId(), id) && Objects.equals(other.getLogin(), login) && Objects.equals(other.getRole(), role) && - Objects.equals(other.getIsAdmin(), isAdmin) && Objects.equals(other.getPassword(), password); } } diff --git a/backend/src/main/java/com/example/backend/users/service/UserService.java b/backend/src/main/java/com/example/backend/users/service/UserService.java index d9c6a0f..8e073b0 100644 --- a/backend/src/main/java/com/example/backend/users/service/UserService.java +++ b/backend/src/main/java/com/example/backend/users/service/UserService.java @@ -17,7 +17,6 @@ import com.example.backend.core.configurations.Constants; import com.example.backend.core.errors.NotFoundException; import com.example.backend.core.security.UserPrincipal; import com.example.backend.users.model.UserEntity; -import com.example.backend.users.model.UserRole; import com.example.backend.users.repository.UserRepository; @Service @@ -59,16 +58,10 @@ public class UserService implements UserDetailsService { if (entity == null) { throw new IllegalArgumentException("Entity is null"); } - entity.setLogin(null); checkLogin(null, entity.getLogin()); final String password = Optional.ofNullable(entity.getPassword()).orElse(""); entity.setPassword( passwordEncoder.encode(StringUtils.hasText(password.strip()) ? password : Constants.DEFAULT_PASSWORD)); - if (entity.getIsAdmin() == true) { - entity.setRole(UserRole.ADMIN); - } else { - entity.setRole(UserRole.USER); - } repository.save(entity); return repository.save(entity); } diff --git a/backend/src/main/resources/templates/signup.html b/backend/src/main/resources/templates/signup.html index 3218d1b..bafefbb 100644 --- a/backend/src/main/resources/templates/signup.html +++ b/backend/src/main/resources/templates/signup.html @@ -46,7 +46,7 @@
- +
diff --git a/data.mv.db b/data.mv.db index 0b45ea5..4c50f24 100644 Binary files a/data.mv.db and b/data.mv.db differ