Search in sources :

Example 6 with BackendUser

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());
    }
}
Also used : PublicKey(java.security.PublicKey) ValidCredentials(io.divide.client.auth.credentials.ValidCredentials) BackendUser(io.divide.client.BackendUser)

Example 7 with BackendUser

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());
    }
}
Also used : PublicKey(java.security.PublicKey) ValidCredentials(io.divide.client.auth.credentials.ValidCredentials) BackendUser(io.divide.client.BackendUser)

Example 8 with BackendUser

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());
}
Also used : LoginCredentials(io.divide.client.auth.credentials.LoginCredentials) SignUpCredentials(io.divide.client.auth.credentials.SignUpCredentials) BackendUser(io.divide.client.BackendUser) ClientTest(io.divide.client.ClientTest) Test(org.junit.Test)

Example 9 with BackendUser

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"));
}
Also used : LoginCredentials(io.divide.client.auth.credentials.LoginCredentials) SignUpCredentials(io.divide.client.auth.credentials.SignUpCredentials) BackendUser(io.divide.client.BackendUser) ClientTest(io.divide.client.ClientTest) Test(org.junit.Test)

Example 10 with BackendUser

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");
}
Also used : SignUpCredentials(io.divide.client.auth.credentials.SignUpCredentials) BackendUser(io.divide.client.BackendUser) ClientTest(io.divide.client.ClientTest) Test(org.junit.Test)

Aggregations

BackendUser (io.divide.client.BackendUser)11 ClientTest (io.divide.client.ClientTest)6 SignUpCredentials (io.divide.client.auth.credentials.SignUpCredentials)6 Test (org.junit.Test)6 LoginListener (io.divide.client.auth.LoginListener)3 LoginCredentials (io.divide.client.auth.credentials.LoginCredentials)3 ValidCredentials (io.divide.client.auth.credentials.ValidCredentials)2 PublicKey (java.security.PublicKey)2 Handler (android.os.Handler)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 BackendObject (io.divide.client.BackendObject)1 CredentialView (io.divide.client.android.CredentialView)1 Storage (io.divide.shared.file.Storage)1 XmlStorage (io.divide.shared.file.XmlStorage)1 Query (io.divide.shared.transitory.query.Query)1 QueryBuilder (io.divide.shared.transitory.query.QueryBuilder)1