Skip to content

Wrote javadoc to User #35

Merged
merged 1 commit into from
Mar 3, 2026
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>A user has a unique identifier, personal information, a hashed password, a role,
* settings and an inbox.
*
* <p>The password is never stored ad plain text. It is hashed using {@link PasswordHasher}
*
* @author Robin Strand Prestmo
*/
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -102,26 +105,52 @@ 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.");
}
this.name = name;
}

/**
* Updates the users password.
*
* <p>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);
}
Expand Down