Browse Source

sorting methods

drop_old_mail
Stephan Richter 3 years ago
parent
commit
ee8ed3b2e3
  1. 48
      src/main/java/de/srsoftware/widerhall/data/User.java

48
src/main/java/de/srsoftware/widerhall/data/User.java

@ -4,7 +4,6 @@ import de.srsoftware.widerhall.Util; @@ -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; @@ -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 { @@ -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 { @@ -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<String,String> map() {
return Map.of(EMAIL,email,NAME,name);
}

Loading…
Cancel
Save