Example usage for com.amazonaws.services.cognitoidp.model DeliveryMediumType EMAIL

List of usage examples for com.amazonaws.services.cognitoidp.model DeliveryMediumType EMAIL

Introduction

In this page you can find the example usage for com.amazonaws.services.cognitoidp.model DeliveryMediumType EMAIL.

Prototype

DeliveryMediumType EMAIL

To view the source code for com.amazonaws.services.cognitoidp.model DeliveryMediumType EMAIL.

Click Source Link

Usage

From source file:com.kdgregory.example.cognito.servlets.SignUp.java

License:Apache License

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String emailAddress = request.getParameter(Constants.RequestParameters.EMAIL);
    if (StringUtil.isBlank(emailAddress)) {
        reportResult(response, Constants.ResponseMessages.INVALID_REQUEST);
        return;//from   w  w  w .  j  a v a  2s .  co  m
    }

    logger.debug("creating user {}", emailAddress);

    try {
        AdminCreateUserRequest cognitoRequest = new AdminCreateUserRequest().withUserPoolId(cognitoPoolId())
                .withUsername(emailAddress)
                .withUserAttributes(new AttributeType().withName("email").withValue(emailAddress),
                        new AttributeType().withName("email_verified").withValue("true"))
                .withDesiredDeliveryMediums(DeliveryMediumType.EMAIL).withForceAliasCreation(Boolean.FALSE);

        cognitoClient.adminCreateUser(cognitoRequest);
        reportResult(response, Constants.ResponseMessages.USER_CREATED);
    } catch (UsernameExistsException ex) {
        logger.debug("user already exists: {}", emailAddress);
        reportResult(response, Constants.ResponseMessages.USER_ALREADY_EXISTS);
    } catch (TooManyRequestsException ex) {
        logger.warn("caught TooManyRequestsException, delaying then retrying");
        ThreadUtil.sleepQuietly(250);
        doPost(request, response);
    }
}