-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
573 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
2 changes: 2 additions & 0 deletions
2
helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Donation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Feedback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 0 additions & 92 deletions
92
helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/User.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...nu/sytemutvikling/team6/models/Inbox.java → ...temutvikling/team6/models/user/Inbox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.*; | ||
|
|
||
|
|
||
2 changes: 1 addition & 1 deletion
2
...sytemutvikling/team6/models/Language.java → ...utvikling/team6/models/user/Language.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../sytemutvikling/team6/models/Message.java → ...mutvikling/team6/models/user/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tnu/sytemutvikling/team6/models/Role.java → ...ytemutvikling/team6/models/user/Role.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
...sytemutvikling/team6/models/Settings.java → ...utvikling/team6/models/user/Settings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/user/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.