Login - LOMENT-SDK/sdk-cashew-android GitHub Wiki
Once the new account has been created the next step is to login to the Cashew server. This is accomplished by calling authenticate() with the username and password:
new UserManager().authenticate(context, username, password, new AuthenticationCallback() {...}
The authenticate call is asynchronous, the result of the call is triggered via two callbacks. To handle the callback, override the onAuthenticationSuccess() and onAuthenticationError() methods:
@Override
public void onAuthenticationSuccess(CNUser user){
// Handle login success
}
@Override
public void onAuthenticationError(CNError error){
// Handle login error
}
At this point we need to understand a tiny bit about the Loment Cashew architecture. The Cashew architecture allows a single user to have multiple independent accounts. In this way a single user can have a work account, a friends account, a family account, etc. But to use the system a user must have at least one account. Here we are creating a single account for this user. This only needs to be called once, not every time we login. But it does need to be called after we login because we need to know what user to add the account to:
new UserManager().addCashewAccount(context, cnUser, accountName, new AddAccountCallback() {...}
Not surprisingly, the account creation results are handled in callbacks:
@Override
public void onAddAccountSuccess(CNCashewAccount account){
//Handle account creation success
}
@Override
public void onAddAccountError(CNError error){
//Handle account creation error
}
If we want to change the password of the user on the server, we need to enter old password and new password. This is accomplished by calling UserManager().changePassword().
new UserManager().changePassword( context, email, password, this);
The Change password results are handled in the following callbacks:
@Override
public void onSuccess(Context context, Bundle bundle) {
//Handle Change Password Success
}
@Override
public void onError(final Context context, CNError error, Bundle bundle) {
//Handle Change Password Error
}