Search in sources :

Example 1 with CodeDeliveryDetailsType

use of com.amazonaws.services.cognitoidentityprovider.model.CodeDeliveryDetailsType in project aws-sdk-android by aws-amplify.

the class CognitoUser method updateAttributesInBackground.

/**
 * Updates attributes for a user. Runs in background.
 * <p>
 * Requires valid accessToken.
 * </p>
 *
 * @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
 *                       custom workflow.
 * @param attributes REQUIRED: All attributes and values that need to be
 *            updated for this user.
 * @param callback REQUIRED: {@link UpdateAttributesHandler} callback.
 */
public void updateAttributesInBackground(final Map<String, String> clientMetadata, final CognitoUserAttributes attributes, final UpdateAttributesHandler callback) {
    if (callback == null) {
        throw new CognitoParameterInvalidException("callback is null");
    }
    final CognitoUser user = this;
    new Thread(new Runnable() {

        @Override
        public void run() {
            final Handler handler = new Handler(context.getMainLooper());
            Runnable returnCallback;
            try {
                final CognitoUserSession session = user.getCachedSession();
                final UpdateUserAttributesResult updateUserAttributesResult = updateAttributesInternal(clientMetadata, attributes, session);
                final List<CognitoUserCodeDeliveryDetails> attributesVerificationList = new ArrayList<CognitoUserCodeDeliveryDetails>();
                if (updateUserAttributesResult.getCodeDeliveryDetailsList() != null) {
                    for (final CodeDeliveryDetailsType details : updateUserAttributesResult.getCodeDeliveryDetailsList()) {
                        attributesVerificationList.add(new CognitoUserCodeDeliveryDetails(details));
                    }
                }
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onSuccess(attributesVerificationList);
                    }
                };
            } catch (final Exception e) {
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onFailure(e);
                    }
                };
            }
            handler.post(returnCallback);
        }
    }).start();
}
Also used : CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) ArrayList(java.util.ArrayList) Handler(android.os.Handler) GetDetailsHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) VerificationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) ForgotPasswordHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler) RegisterMfaHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler) DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) CodeDeliveryDetailsType(com.amazonaws.services.cognitoidentityprovider.model.CodeDeliveryDetailsType) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CognitoInternalErrorException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException) UserNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException) CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException) UpdateUserAttributesResult(com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesResult)

Example 2 with CodeDeliveryDetailsType

use of com.amazonaws.services.cognitoidentityprovider.model.CodeDeliveryDetailsType in project aws-sdk-android by aws-amplify.

the class CognitoUser method updateAttributes.

/**
 * Updates attributes for a user. Runs in background.
 * <p>
 * Requires valid accessToken. <b>Note:</b> This method will perform network
 * operations. Calling this method in applications' main thread will cause
 * Android to throw NetworkOnMainThreadException.
 * </p>
 *  @param attributes REQUIRED: All attributes and values that need to be
 *            updated for this user.
 * @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
 *                       custom workflow.
 * @param callback REQUIRED: {@link UpdateAttributesHandler} callback.
 */
public void updateAttributes(final CognitoUserAttributes attributes, final Map<String, String> clientMetadata, final UpdateAttributesHandler callback) {
    if (callback == null) {
        throw new CognitoParameterInvalidException("callback is null");
    }
    try {
        final CognitoUserSession session = getCachedSession();
        final UpdateUserAttributesResult updateUserAttributesResult = updateAttributesInternal(clientMetadata, attributes, session);
        final List<CognitoUserCodeDeliveryDetails> attributesVerificationList = new ArrayList<CognitoUserCodeDeliveryDetails>();
        if (updateUserAttributesResult.getCodeDeliveryDetailsList() != null) {
            for (final CodeDeliveryDetailsType details : updateUserAttributesResult.getCodeDeliveryDetailsList()) {
                attributesVerificationList.add(new CognitoUserCodeDeliveryDetails(details));
            }
        }
        callback.onSuccess(attributesVerificationList);
    } catch (final Exception e) {
        callback.onFailure(e);
    }
}
Also used : CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) UpdateUserAttributesResult(com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesResult) ArrayList(java.util.ArrayList) CodeDeliveryDetailsType(com.amazonaws.services.cognitoidentityprovider.model.CodeDeliveryDetailsType) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CognitoInternalErrorException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException) UserNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException) CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)

Aggregations

CognitoInternalErrorException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException)2 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)2 CognitoParameterInvalidException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException)2 CodeDeliveryDetailsType (com.amazonaws.services.cognitoidentityprovider.model.CodeDeliveryDetailsType)2 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)2 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)2 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)2 UpdateUserAttributesResult (com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesResult)2 UserNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ArrayList (java.util.ArrayList)2 Handler (android.os.Handler)1 AuthenticationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler)1 DevicesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler)1 ForgotPasswordHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler)1 GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)1 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)1 RegisterMfaHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler)1 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)1 VerificationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler)1