fixed bug that made registering a new user impossible

This commit is contained in:
delvh 2020-02-09 20:41:29 +01:00
parent aa52cddf6a
commit b6763384fd

View File

@ -92,7 +92,7 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
ConnectionManager connectionManager = ConnectionManager.getInstance(); ConnectionManager connectionManager = ConnectionManager.getInstance();
String userIdentifier = credentials.getIdentifier(); String userIdentifier = credentials.getIdentifier();
try { try {
//TODO will need to be replaced with the Identifier once implemented // TODO will need to be replaced with the Identifier once implemented
user = persistenceManager.getUserByName(userIdentifier); user = persistenceManager.getUserByName(userIdentifier);
// Checking if user is already online // Checking if user is already online
if (connectionManager.isOnline(user.getId())) { if (connectionManager.isOnline(user.getId())) {
@ -120,19 +120,23 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
* @since Envoy Server Standalone v0.1-alpha * @since Envoy Server Standalone v0.1-alpha
*/ */
private envoy.server.data.User newUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException { private envoy.server.data.User newUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException {
// Checking that no user already has this identifier TODO change to identifier once implemented try {
if (PersistenceManager.getPersistenceManager().getUserByName(credentials.getIdentifier()) != null) // Checking that no user already has this identifier
PersistenceManager.getPersistenceManager().getUserByName(credentials.getIdentifier());
// this code only gets executed if this user already exists
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.USER_EXISTS_ALREADY)); writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.USER_EXISTS_ALREADY));
// Creation of a new user return null;
envoy.server.data.User user; } catch (NoResultException e) {
user = new envoy.server.data.User(); // Creation of a new user
//TODO needs to be replaced later on envoy.server.data.User user;
user.setName(credentials.getIdentifier()); user = new envoy.server.data.User();
user.setLastSeen(new Date()); user.setName(credentials.getIdentifier());
user.setStatus(User.UserStatus.ONLINE); user.setLastSeen(new Date());
user.setPasswordHash(credentials.getPasswordHash()); user.setStatus(User.UserStatus.ONLINE);
user.setContacts(PersistenceManager.getPersistenceManager().getContacts(user)); user.setPasswordHash(credentials.getPasswordHash());
persistenceManager.addUser(user); user.setContacts(PersistenceManager.getPersistenceManager().getContacts(user));
return user; persistenceManager.addUser(user);
return user;
}
} }
} }