working on user settings

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-21 23:57:42 +02:00
parent 03a0ba139f
commit f078491344
13 changed files with 252 additions and 17 deletions

View File

@@ -62,6 +62,8 @@ public class FileStore implements ClientService, SessionService, UserService {
return this;
}
@Override
public List<User> list() {
return List.of();
@@ -98,6 +100,11 @@ public class FileStore implements ClientService, SessionService, UserService {
}
}
@Override
public boolean passwordMatches(String password, String hashedPassword) {
return passwordHasher.matches(password,hashedPassword);
}
@Override
public FileStore save(User user) {
JSONObject users;
@@ -110,6 +117,14 @@ public class FileStore implements ClientService, SessionService, UserService {
return save();
}
@Override
public FileStore updatePassword(User user, String plaintextPassword) {
var oldHashedPassword = user.hashedPassword();
var salt = passwordHasher.salt(oldHashedPassword);
user.hashedPassword(passwordHasher.hash(plaintextPassword,salt));
return save(user);
}
private Optional<User> userOf(JSONObject json, String userId){
var user = new User(json.getString(USERNAME), json.getString(PASSWORD), json.getString(REALNAME), json.getString(EMAIL), userId);
var perms = json.getJSONArray(PERMISSIONS);
@@ -132,7 +147,7 @@ public class FileStore implements ClientService, SessionService, UserService {
public Session createSession(User user) {
var now = Instant.now();
var endOfSession = now.plus(sessionDuration);
return save(new Session(user, endOfSession, UUID.randomUUID().toString()));
return save(new Session(user, endOfSession, java.util.UUID.randomUUID().toString()));
}
@Override