diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/user/User.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/user/User.java index 28c5934..ba4a298 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/user/User.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/user/User.java @@ -1,13 +1,15 @@ package ntnu.sytemutvikling.team6.models.user; -import ntnu.sytemutvikling.team6.security.PasswordHasher; - import java.util.UUID; - -// TODO: Enhetstesting mangler +import ntnu.sytemutvikling.team6.security.PasswordHasher; /** - * Represents a user. + * Represents a user in the system. + * + *

A user has a unique identifier, personal information, a hashed password, a role, + * settings and an inbox. + * + *

The password is never stored ad plain text. It is hashed using {@link PasswordHasher} * * @author Robin Strand Prestmo */ @@ -23,7 +25,7 @@ public class User { private final Inbox inbox; /** - * Creates a new user + * Creates a new user. * * @param id gives the user a unique identifier with UUID * @param name the name of the user @@ -32,7 +34,7 @@ public class User { * @param role users role * @param settings the user´s settings * @param inbox the user´s inbox - * + * @throws IllegalArgumentException if any required argument is invalid. */ public User(UUID id, String name, @@ -50,7 +52,8 @@ public User(UUID id, } if (email == null || email.isBlank() || !email.contains("@") || !email.contains(".")) { - throw new IllegalArgumentException("Email cannot be null or blank, and must contain '@' and '.'"); + throw new IllegalArgumentException("Email cannot be null or blank," + + " and must contain '@' and '.'"); } if (role == null) { @@ -102,6 +105,12 @@ public Inbox getInbox() { // Add Setters + /** + * Updates the users name. + * + * @param name the new name + * @throws IllegalArgumentException if the name is null or blank + */ public void setName(String name) { if (name == null || name.isBlank()) { throw new IllegalArgumentException("Name cannot be null or blank."); @@ -109,19 +118,39 @@ public void setName(String name) { this.name = name; } + /** + * Updates the users password. + * + *

The password is hashed before being stored. + * + * @param password the new password + */ public void setPassword(String password) { this.passwordHash = passwordHasher.getHashPassword(password); } + /** + * Updates the users email. + * + * @param email the new email + * @throws IllegalArgumentException if the email is null, blank, or does not contain '@' or '.' + */ public void setEmail(String email) { if (email == null || email.isBlank() || !email.contains("@") || !email.contains(".")) { - throw new IllegalArgumentException("Email cannot be null or blank, and must contains '@' and '.'"); + throw new IllegalArgumentException("Email cannot be null or blank," + + " and must contains '@' and '.'"); } this.email = email; } // Other methods + /** + * Checks if the provided password matches the stored password. + * + * @param password the password to verify + * @return true if the password is correct, false otherwise + */ public boolean checkPassword(String password) { return passwordHasher.isValidPassword(password, passwordHash); }