Skip to content

Commit

Permalink
Merge: Merge with feat/workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Mar 5, 2026
2 parents b2c1072 + 9b40a55 commit e2161b7
Show file tree
Hide file tree
Showing 28 changed files with 573 additions and 97 deletions.
20 changes: 20 additions & 0 deletions helpmehelpapplication/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: ci

on:
push:
branches: main
pull_request:
branches: main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribition: temurin
java-version: "25"
cache: maven
- run:
mvn -B test
6 changes: 6 additions & 0 deletions helpmehelpapplication/helpmehelpapplication.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="CheckStyle-IDEA-Module" serialisationVersion="2">
<option name="activeLocationsIds" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ntnu.sytemutvikling.team6.models;

import ntnu.sytemutvikling.team6.models.user.User;

import java.time.LocalDateTime;
import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ntnu.sytemutvikling.team6.models;

import ntnu.sytemutvikling.team6.models.user.User;

import java.time.LocalDateTime;
import java.util.UUID;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.sytemutvikling.team6.models;
package ntnu.sytemutvikling.team6.models.user;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.sytemutvikling.team6.models;
package ntnu.sytemutvikling.team6.models.user;

/**
* Supported application languages.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.sytemutvikling.team6.models;
package ntnu.sytemutvikling.team6.models.user;

import java.time.LocalDateTime;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.sytemutvikling.team6.models;
package ntnu.sytemutvikling.team6.models.user;

/**
* Available users
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.sytemutvikling.team6.models;
package ntnu.sytemutvikling.team6.models.user;

// Mangler Enhetstesting

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package ntnu.sytemutvikling.team6.models.user;

import java.util.UUID;
import ntnu.sytemutvikling.team6.security.PasswordHasher;

/**
* 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
*/
public class User {
private static final PasswordHasher passwordHasher = new PasswordHasher();

private final UUID id;
private String name;
private String email;
private String passwordHash;
private final Role role;
private final Settings settings;
private final Inbox inbox;

/**
* Creates a new user.
*
* @param id gives the user a unique identifier with UUID
* @param name the name of the user
* @param email the email of the user
* @param password the password for the 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,
String email,
String password,
Role role,
Settings settings,
Inbox inbox) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null.");
}

if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Name cannot be null or blank.");
}

if (email == null || email.isBlank() || !email.contains("@") || !email.contains(".")) {
throw new IllegalArgumentException("Email cannot be null or blank,"
+ " and must contain '@' and '.'");
}

if (role == null) {
throw new IllegalArgumentException("Role cannot be null");
}

if (settings == null) {
throw new IllegalArgumentException("Settings cannot be null");
}

if (inbox == null) {
throw new IllegalArgumentException("Inbox cannot be null");
}

this.id = id;
this.name = name;
this.email = email;
this.passwordHash = passwordHasher.getHashPassword(password);
this.role = role;
this.settings = settings;
this.inbox = inbox;
}

// Add Getters

public UUID getId() {
return id;
}

public String getName() {
return name;
}

public String getEmail() {
return email;
}

public Role getRole() {
return role;
}

public Settings getSettings() {
return settings;
}

public Inbox getInbox() {
return inbox;
}

// 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 '.'");
}
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);
}
}
Loading

0 comments on commit e2161b7

Please sign in to comment.