Skip to content

Commit

Permalink
Reverse commit-ish: Design fault, used email and not a username as lo…
Browse files Browse the repository at this point in the history
…gg in paramater. My bad
  • Loading branch information
AdrianBalunan committed Apr 16, 2026
1 parent d4198df commit 5c6db88
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ FOREIGN KEY (`user_id`)
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `apbaluna`.`User` (
`UUID_User` CHAR(36) NOT NULL,
`user_displayname` VARCHAR(255) NOT NULL,
`user_name` VARCHAR(255) NOT NULL,
`user_email` VARCHAR(255) NOT NULL,
`user_password` VARCHAR(255) NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,24 @@ public UserSelect(DatabaseConnection connection) {
this.connection = connection;
}

public boolean isUsernameTaken(String username){
public boolean isEmailTaken(String email){
if (email == null || email.isBlank() || !email.contains("@") || !email.contains(".")) {
throw new IllegalArgumentException(
"Email cannot be null or blank," + " and must contain '@' and '.'");
}
try (Connection conn = connection.getMySqlConnection();
Statement stmt = conn.createStatement()) {

String mysql =
"""
SELECT UUID_User FROM User WHERE user_name = ?
SELECT UUID_User FROM User WHERE user_email = ?
""";
PreparedStatement statement = conn.prepareStatement(mysql);
statement.setString(1, username);
statement.setString(1, email);
ResultSet rs = statement.executeQuery();

if (rs.next()) {
System.out.println("Username Taken already");
System.out.println("Email Taken already");
return true;
}

Expand Down Expand Up @@ -83,7 +87,7 @@ public User getUserFromDBUsernameAndPassword(String username, String password) {
String sql_query =
"""
SELECT
u.UUID_User, u.user_displayname, u.user_name, u.user_email, u.user_password, u.role,
u.UUID_User, u.user_name, u.user_email, u.user_password, u.role,
s.User_UUID_User, s.isAnonymous, s.language, s.lightmode,
m.UUID_message, m.message_title, m.message_content, m.message_date, m.sender_user_id, m.sender_charity_id, m.user_id
FROM User u
Expand All @@ -104,7 +108,6 @@ public User getUserFromDBUsernameAndPassword(String username, String password) {
user =
new User(
userId,
rs.getString("user_displayname"),
rs.getString("user_name"),
rs.getString("user_email"),
rs.getString("user_password"),
Expand Down Expand Up @@ -161,7 +164,7 @@ public User getUserFromDBUuid(String user_id) {
String sql_query =
"""
SELECT
u.UUID_User, u.user_displayname u.user_name, u.user_email, u.user_password, u.role,
u.UUID_User, u.user_name, u.user_email, u.user_password, u.role,
s.User_UUID_User, s.isAnonymous, s.language, s.lightmode,
m.UUID_message, m.message_title, m.message_content, m.message_date, m.sender_user_id, m.sender_charity_id, m.user_id
FROM User u
Expand All @@ -180,7 +183,6 @@ public User getUserFromDBUuid(String user_id) {
user =
new User(
userId,
rs.getString("user_displayname"),
rs.getString("user_name"),
rs.getString("user_email"),
rs.getString("user_password"),
Expand Down Expand Up @@ -237,7 +239,7 @@ public UserRegistry getUsersFromDB() {
String sql_query =
"""
SELECT
u.UUID_User, u.user_displayname u.user_name, u.user_email, u.user_password, u.role,
u.UUID_User, u.user_name, u.user_email, u.user_password, u.role,
s.User_UUID_User, s.isAnonymous, s.language, s.lightmode,
m.UUID_message, m.message_title, m.message_content, m.message_date, m.sender_user_id, m.sender_charity_id, m.user_id
FROM User u
Expand All @@ -257,7 +259,6 @@ public UserRegistry getUsersFromDB() {
currentUser =
new User(
userId,
rs.getString("user_displayname"),
rs.getString("user_name"),
rs.getString("user_email"),
rs.getString("user_password"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class User {
private static final PasswordHasher passwordHasher = new PasswordHasher();

private final UUID id;
private String displayName;
private String username;
private String email;
private String passwordHash;
Expand All @@ -28,7 +27,6 @@ public class User {
/**
* Creates a new user.
*
* @param displayName the name of the user that is shown
* @param username unqiue username used for login
* @param email the email of the user
* @param password the password for the user
Expand All @@ -37,12 +35,7 @@ public class User {
* @param inbox the user´s inbox
* @throws IllegalArgumentException if any required argument is invalid.
*/
public User(
String displayName, String username, String email, String password, Role role, Settings settings, Inbox inbox) {
if (displayName == null || username.isBlank()){
throw new IllegalArgumentException("displayName cannot be null or blank.");
}

public User(String username, String email, String password, Role role, Settings settings, Inbox inbox) {
if (username == null || username.isBlank()) {
throw new IllegalArgumentException("Name cannot be null or blank.");
}
Expand All @@ -65,7 +58,6 @@ public User(
}

this.id = UUID.randomUUID();
this.displayName = displayName;
this.username = username;
this.email = email;
this.passwordHash = passwordHasher.getHashPassword(password);
Expand All @@ -79,14 +71,13 @@ public User(
* later date throught another method in databaseManager class
*
* @param uuid gives the user a unique identifier with UUID
* @param displayName the name of the user that is shown
* @param username the name of the user
* @param email the email of the user
* @param password the password for the user
* @param role users role
* @throws IllegalArgumentException if any required argument is invalid.
*/
public User(String uuid, String displayName, String username, String email, String password, String role) {
public User(String uuid, String username, String email, String password, String role) {

if (uuid == null || uuid.isBlank()) {
throw new IllegalArgumentException("UUID cannot be null or blank.");
Expand All @@ -106,7 +97,6 @@ public User(String uuid, String displayName, String username, String email, Stri
}

this.id = UUID.fromString(uuid);
this.displayName = displayName;
this.username = username;
this.email = email;
this.passwordHash = password;
Expand All @@ -121,10 +111,6 @@ public UUID getId() {
return id;
}

public String getDisplayName() {
return displayName;
}

public String getUsername() {
return username;
}
Expand Down

0 comments on commit 5c6db88

Please sign in to comment.