use of io.divide.client.BackendUser in project divide by HiddenStage.
the class AuthManager method signUp.
/**
* Syncronously attempt to create user account
* @param loginCreds Credentials used to create account.
* @return Response of the operation
*/
public SignUpResponse signUp(SignUpCredentials loginCreds) {
logger.debug("signUp(" + loginCreds + ")");
try {
setLoginState(LOGGING_IN);
PublicKey key = Crypto.pubKeyFromBytes(getWebService().getPublicKey());
loginCreds.encryptPassword(key);
logger.debug("Login Creds: " + loginCreds);
ServerResponse<ValidCredentials> response = ServerResponse.from(ValidCredentials.class, getWebService().userSignUp(loginCreds));
logger.debug("Response: " + response.getStatus());
BackendUser user;
if (response.getStatus().isSuccess()) {
user = setUser(response.get());
} else {
return new SignUpResponse(null, Status.SERVER_ERROR_INTERNAL, " null user returned");
}
return new SignUpResponse(user, response.getStatus(), response.getError());
} catch (Exception e) {
logger.error("SignUp Failure(" + loginCreds.getEmailAddress() + ")", e);
return new SignUpResponse(null, Status.SERVER_ERROR_INTERNAL, e.getLocalizedMessage());
}
}
use of io.divide.client.BackendUser in project divide by HiddenStage.
the class AuthManager method login.
/**
* Syncronously attempt to log into user account
* @param loginCreds Credentials used to login.
* @return Response of the operation
*/
public SignInResponse login(final LoginCredentials loginCreds) {
logger.debug("login(" + loginCreds + ")");
try {
setLoginState(LOGGING_IN);
if (!loginCreds.isEncrypted()) {
PublicKey key = Crypto.pubKeyFromBytes(getWebService().getPublicKey());
loginCreds.encryptPassword(key);
}
logger.debug("Login Creds: " + loginCreds);
ServerResponse<ValidCredentials> response = ServerResponse.from(ValidCredentials.class, getWebService().login(loginCreds));
BackendUser user;
if (response.getStatus().isSuccess()) {
user = setUser(response.get());
} else {
logger.error("Login Failure(" + loginCreds.getEmailAddress() + "): " + response.getStatus().getCode() + " " + response.getError());
setLoginState(LOGGED_OUT);
return new SignInResponse(null, Status.SERVER_ERROR_INTERNAL, "Login failed");
}
return new SignInResponse(user, response.getStatus(), response.getError());
} catch (Exception e) {
logger.error("Login Failure(" + loginCreds.getEmailAddress() + ")", e);
setLoginState(LOGGED_OUT);
return new SignInResponse(null, Status.SERVER_ERROR_INTERNAL, e.getLocalizedMessage());
}
}
use of io.divide.client.BackendUser in project divide by HiddenStage.
the class AuthManagerTest method testLoginASync.
@Test
public void testLoginASync() throws Exception {
SignUpCredentials signUpCredentials = new SignUpCredentials("name", "email", "");
String unEncryptedPW = signUpCredentials.getPassword();
BackendUser signInUser = authManager.signUp(signUpCredentials).get();
BackendUser user = authManager.loginASync(new LoginCredentials(signInUser.getEmailAddress(), unEncryptedPW)).toBlockingObservable().first();
assertEquals(signInUser.getUsername(), user.getUsername());
}
use of io.divide.client.BackendUser in project divide by HiddenStage.
the class AuthManagerTest method testSendGetUserData.
@Test
public void testSendGetUserData() throws Exception {
BackendUser user = authManager.signUp(new SignUpCredentials("name", "email", "11")).get();
user.put("key", "value");
System.out.println("BEFORE_USER: " + authManager.getUser());
System.out.println("BEFORE_ID: " + backend.getConfig().id);
// user.save();
authManager.sendUserData(user).toBlockingObservable().first();
// user.logout();
user = authManager.login(new LoginCredentials("email", "11")).get();
assertNotNull(user);
assertEquals("value", user.get(String.class, "key"));
}
use of io.divide.client.BackendUser in project divide by HiddenStage.
the class AuthManagerTest method testRecoverFromOneTimeToken.
@Test
public void testRecoverFromOneTimeToken() throws Exception {
SignUpResponse response = authManager.signUp(new SignUpCredentials("name", "email", ""));
BackendUser user = response.get();
assertEquals(user.getUsername(), "name");
BackendUser credentials = authManager.getUserFromRecoveryToken(user.getRecoveryToken()).toBlockingObservable().first();
assertNotNull(credentials);
assertEquals(credentials.getUsername(), "name");
}
Aggregations