Ejemplo n.º 1
0
def send_create_account_email(email):
    """Sends an email through GovNotify to the specified address with an encoded link to verify their email

    :param email: The email address to send to
    """
    url_safe_serializer = URLSafeSerializer(app.config["SECRET_KEY"])

    response = uaa_controller.get_user_by_email(email)
    if response is None:
        return render_template("request-new-account-error.html")

    if response["totalResults"] == 0:
        internal_url = app.config["RESPONSE_OPERATIONS_UI_URL"]
        verification_url = f"{internal_url}/account/create-account/{token_decoder.generate_email_token(email)}"

        logger.info("Sending create account email", verification_url=verification_url)

        personalisation = {"CREATE_ACCOUNT_URL": verification_url, "EMAIL": email}

        try:
            NotifyController().request_to_notify(
                email=email, template_name="request_create_account", personalisation=personalisation
            )
        except NotifyError as e:
            logger.error("Error sending create account request email to Notify Gateway", msg=e.description)
            return render_template("request-new-account-error.html")

        logger.info("Successfully sent create account request email", encoded_email=url_safe_serializer.dumps(email))
    else:
        logger.info(
            "Requested account creation for email already in UAA", encoded_email=url_safe_serializer.dumps(email)
        )
        return render_template("request-new-account-exists.html", email=email)

    return render_template("request-new-account-check-email.html", email=email)
Ejemplo n.º 2
0
def send_update_account_email(token_dict, first_name):
    """Sends an email through GovNotify to the specified address with an encoded
     link to verify their email when it has been changed

    :param token_dict: A dictionary containing the email address to send to and user id
    :param first_name: the name of the user the email is being sent to, used in email
    """
    response = uaa_controller.get_user_by_email(token_dict["email"])
    if response is None:
        return render_template("request-new-account-error.html")

    if response["totalResults"] == 0:
        internal_url = app.config["RESPONSE_OPERATIONS_UI_URL"]
        verification_url = (
            f"{internal_url}/account/verify-email/{token_decoder.generate_email_token(json.dumps(token_dict))}"
        )

        logger.info("Sending update account verification email", verification_url=verification_url)
        personalisation = {"CONFIRM_EMAIL_URL": verification_url, "first_name": first_name}
        NotifyController().request_to_notify(
            email=token_dict["email"], template_name="update_email", personalisation=personalisation
        )
    else:
        url_safe_serializer = URLSafeSerializer(app.config["SECRET_KEY"])
        logger.info(
            "Requested account creation for email already in UAA",
            encoded_email=url_safe_serializer.dumps(token_dict["email"]),
        )
        flash("Email already in use", category="error")
def send_confirm_change_email(email):
    user = uaa_controller.get_user_by_email(email)
    first_name = user['resources'][0]['name']['givenName']
    if first_name != "":
        personalisation = {'FIRST_NAME': first_name}

        try:
            NotifyController().request_to_notify(
                email=email,
                template_name='confirm_password_change',
                personalisation=personalisation)
        except NotifyError as e:
            # This shouldn't show the client an error - the password change was still successful.
            # They just won't get a confirmation email
            logger.error(
                'Error sending password change confirmation email to Notify Gateway',
                msg=e.description)
def send_password_change_email(email):
    url_safe_serializer = URLSafeSerializer(app.config['SECRET_KEY'])

    response = uaa_controller.get_user_by_email(email)
    if response is None:
        return render_template('forgot-password-error.html')

    if response['totalResults'] > 0:
        first_name = response['resources'][0]['name']['givenName']
        internal_url = app.config['RESPONSE_OPERATIONS_UI_URL']
        verification_url = f'{internal_url}/passwords/reset-password/{token_decoder.generate_email_token(email)}'

        logger.info('Sending password change email',
                    verification_url=verification_url)

        personalisation = {
            'RESET_PASSWORD_URL': verification_url,
            'FIRST_NAME': first_name
        }

        try:
            NotifyController().request_to_notify(
                email=email,
                template_name='request_password_change',
                personalisation=personalisation)
        except NotifyError as e:
            logger.error(
                'Error sending password change request email to Notify Gateway',
                msg=e.description)
            return render_template('forgot-password-error.html')

        logger.info('Successfully sent password change request email',
                    email=url_safe_serializer.dumps(email))
    else:
        # We still want to render the template for an email without an account to avoid
        # people fishing for valid emails
        logger.info('Requested password reset for email not in UAA',
                    email=url_safe_serializer.dumps(email))

    return redirect(
        url_for('passwords_bp.forgot_password_check_email',
                email=url_safe_serializer.dumps(email)))
Ejemplo n.º 5
0
def send_password_change_email(email):
    url_safe_serializer = URLSafeSerializer(app.config["SECRET_KEY"])

    response = uaa_controller.get_user_by_email(email)
    if response is None:
        return render_template("forgot-password-error.html")

    if response["totalResults"] > 0:
        first_name = response["resources"][0]["name"]["givenName"]
        internal_url = app.config["RESPONSE_OPERATIONS_UI_URL"]
        verification_url = f"{internal_url}/passwords/reset-password/{token_decoder.generate_email_token(email)}"

        logger.info("Sending password change email",
                    verification_url=verification_url)

        personalisation = {
            "RESET_PASSWORD_URL": verification_url,
            "FIRST_NAME": first_name
        }

        try:
            NotifyController().request_to_notify(
                email=email,
                template_name="request_password_change",
                personalisation=personalisation)
        except NotifyError as e:
            logger.error(
                "Error sending password change request email to Notify Gateway",
                msg=e.description)
            return render_template("forgot-password-error.html")

        logger.info("Successfully sent password change request email",
                    email=url_safe_serializer.dumps(email))
    else:
        # We still want to render the template for an email without an account to avoid
        # people fishing for valid emails
        logger.info("Requested password reset for email not in UAA",
                    email=url_safe_serializer.dumps(email))

    return redirect(
        url_for("passwords_bp.forgot_password_check_email",
                email=url_safe_serializer.dumps(email)))