Search in sources :

Example 1 with ValidCredentials

use of io.divide.client.auth.credentials.ValidCredentials 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 2 with ValidCredentials

use of io.divide.client.auth.credentials.ValidCredentials 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)

Aggregations

BackendUser (io.divide.client.BackendUser)2 ValidCredentials (io.divide.client.auth.credentials.ValidCredentials)2 PublicKey (java.security.PublicKey)2