use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler in project aws-sdk-android by aws-amplify.
the class SignUpActivity method signUp.
/**
* Retrieve input and return to caller.
* @param view the Android View
*/
public void signUp(final View view) {
final String username = signUpView.getUserName();
final String password = signUpView.getPassword();
final String givenName = signUpView.getGivenName();
final String email = signUpView.getEmail();
final String phone = signUpView.getPhone();
Log.d(LOG_TAG, "username = " + username);
Log.d(LOG_TAG, "given_name = " + givenName);
Log.d(LOG_TAG, "email = " + email);
Log.d(LOG_TAG, "phone = " + phone);
if (username.isEmpty()) {
showError(getString(R.string.sign_up_username_missing));
return;
}
if (password.length() < 6) {
showError(getString(R.string.password_length_validation_failed));
return;
}
final CognitoUserAttributes userAttributes = new CognitoUserAttributes();
userAttributes.addAttribute(GIVEN_NAME, givenName);
userAttributes.addAttribute(EMAIL_ADDRESS, email);
if (!phone.isEmpty()) {
userAttributes.addAttribute(PHONE_NUMBER, phone);
}
final AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.sign_up_in_progress)).setMessage(getString(R.string.please_wait)).setNeutralButton(android.R.string.ok, null);
final AlertDialog alertDialog = builder.show();
mUserPool.signUpInBackground(username, password, userAttributes, null, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
alertDialog.dismiss();
final Intent intent = new Intent();
intent.putExtra(USERNAME, username);
intent.putExtra(PASSWORD, password);
intent.putExtra(IS_SIGN_UP_CONFIRMED, signUpResult.getUserConfirmed());
intent.putExtra(CONFIRMATION_DESTINATION, signUpResult.getCodeDeliveryDetails().getDestination());
setResult(RESULT_OK, intent);
finish();
}
@Override
public void onFailure(Exception exception) {
alertDialog.dismiss();
showError(exception.getLocalizedMessage() != null ? getErrorMessageFromException(exception) : "");
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpResourceNotFoundException.
// Register with invalid clientId
@Test
public void signUpResourceNotFoundException() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
ResourceNotFoundException exception = new ResourceNotFoundException("registration failed");
doThrow(exception).when(mockCSIClient).signUp(any(SignUpRequest.class));
testPool.signUp(TEST_USER_NAME, "null", TEST_IN_USER_ATTRIBUTES_LIST, TEST_IN_VALIDATION_DATA, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
assertNotNull(user);
assertEquals(TEST_USER_NAME, user.getUserId());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
assertTrue(exception instanceof ResourceNotFoundException);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpPasswordException.
// Register with invalid password
@Test
public void signUpPasswordException() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
InvalidParameterException exception = new InvalidParameterException("registration failed");
doThrow(exception).when(mockCSIClient).signUp(any(SignUpRequest.class));
testPool.signUp(TEST_USER_NAME, "null", TEST_IN_USER_ATTRIBUTES_LIST, TEST_IN_VALIDATION_DATA, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
assertNotNull(user);
assertNotNull(signUpResult.getUserConfirmed());
assertEquals(TEST_USER_NAME, user.getUserId());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
assertTrue(exception instanceof InvalidParameterException);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpUserInCurrentThread.
@Test
public void signUpUserInCurrentThread() throws Exception {
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
expected_result_boolean = true;
testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
// Verify the arguments
ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
verify(mockCSIClient).signUp(argumentCaptor.capture());
SignUpRequest requestSent = argumentCaptor.getValue();
assertNotNull(requestSent);
assertEquals(TEST_USER_NAME, requestSent.getUsername());
assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
assertNotNull(requestSent.getUserAttributes());
assertEquals(2, requestSent.getUserAttributes().size());
assertNull(requestSent.getValidationData());
// Verify results
assertNotNull(user);
assertNotNull(signUpResult.getUserConfirmed());
assertNotNull(signUpResult.getCodeDeliveryDetails());
assertEquals(TEST_USER_NAME, user.getUserId());
assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
}
@Override
public void onFailure(Exception exception) {
assertNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method signUpUserWithoutPPInCurrentThread.
@Test
public void signUpUserWithoutPPInCurrentThread() throws Exception {
// Test shared Pinpoint context
awsKeyValueStorageUtility.put(PP_UNIQUE_ID_KEY, TEST_PP_ENDPOINT_1);
// Test new user pool creation with PP app id.
CognitoUserPool testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
expected_result_boolean = true;
testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
// Verify the arguments
ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
verify(mockCSIClient).signUp(argumentCaptor.capture());
SignUpRequest requestSent = argumentCaptor.getValue();
assertNotNull(requestSent);
assertEquals(TEST_USER_NAME, requestSent.getUsername());
assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
assertNotNull(requestSent.getUserAttributes());
assertEquals(2, requestSent.getUserAttributes().size());
assertNull(requestSent.getValidationData());
assertNull(requestSent.getAnalyticsMetadata());
// Verify results
assertNotNull(user);
assertNotNull(signUpResult.getUserConfirmed());
assertNotNull(signUpResult.getCodeDeliveryDetails());
assertEquals(TEST_USER_NAME, user.getUserId());
assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
}
@Override
public void onFailure(Exception exception) {
assertNull(exception);
}
});
}
Aggregations