diff --git a/src/main/java/de/srsoftware/widerhall/data/User.java b/src/main/java/de/srsoftware/widerhall/data/User.java index bdd52de..9421a16 100644 --- a/src/main/java/de/srsoftware/widerhall/data/User.java +++ b/src/main/java/de/srsoftware/widerhall/data/User.java @@ -4,7 +4,6 @@ import de.srsoftware.widerhall.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.Serializable; import java.security.InvalidKeyException; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +12,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import static de.srsoftware.widerhall.Util.t; import static de.srsoftware.widerhall.data.Database.*; public class User { @@ -34,29 +32,7 @@ public class User { return new User(email,name,salt,hashedPass).save(); } - public static User load(String email, String password) throws InvalidKeyException, SQLException { - ResultSet rs = database - .query("SELECT * FROM Users") - .where(EMAIL,email) - .exec(); - try { - if (rs.next()) { - email = rs.getString(EMAIL); - var name = rs.getString(NAME); - var hashedPassword = rs.getString(HASHED_PASS); - var salt = rs.getString(SALT); - var loadedUser = new User(email, name, salt, hashedPassword); - if (loadedUser.matching(password)) return loadedUser; - } else if (noUsers()){ - return User.create(email,"Admin",password); - } - } finally { - rs.close(); - } - - throw new InvalidKeyException(); - } public String email() { return email; @@ -89,6 +65,30 @@ public class User { return userList; } + public static User load(String email, String password) throws InvalidKeyException, SQLException { + ResultSet rs = database + .query("SELECT * FROM Users") + .where(EMAIL,email) + .exec(); + + try { + if (rs.next()) { + email = rs.getString(EMAIL); + var name = rs.getString(NAME); + var hashedPassword = rs.getString(HASHED_PASS); + var salt = rs.getString(SALT); + var loadedUser = new User(email, name, salt, hashedPassword); + if (loadedUser.matching(password)) return loadedUser; + } else if (noUsers()){ + return User.create(email,"Admin",password); + } + } finally { + rs.close(); + } + + throw new InvalidKeyException(); + } + public Map map() { return Map.of(EMAIL,email,NAME,name); }