Пример #1
0
def register_user(**kwargs):
    kwargs.pop('password_confirm', None)
    user = User.create(**kwargs)

    signal_context = {'user': user}
    mail_context = {'user': user}

    if system_requires_confirmation():
        confirmation_token, confirmation_link = \
            generate_confirmation_token_and_link(user)
        signal_context['confirmation_token'] = confirmation_token
        mail_context['confirmation_link'] = confirmation_link

    user_registered.send(
        current_app._get_current_object(),
        **signal_context)

    send_mail(
        'Thank you for registering!',
        current_app.config['MAIL_DEFAULT_SENDER'],
        user.email,
        plain_template_path='users/emails/welcome.txt.html',
        html_template_path='users/emails/welcome.html',
        **mail_context)

    return user
Пример #2
0
def send_password_reset_notice(user):
    signal_context = {'user': user}

    send_mail(
        'Your password has been reset',
        current_app.config['MAIL_DEFAULT_SENDER'],
        user.email,
        plain_template_path='users/emails/reset_password_notice.txt.html',
        html_template_path='users/emails/reset_password_notice.html',
        user=user)

    reset_password_notice_sent.send(
        current_app._get_current_object(),
        **signal_context)
Пример #3
0
def send_reset_password_instructions(user):
    reset_password_token, reset_password_link = \
        generate_reset_password_token_and_link(user)

    signal_context = {'user': user,
                      'reset_password_token': reset_password_token}
    mail_context = {'user': user, 'reset_password_link': reset_password_link}

    send_mail(
        'Please reset your password',
        current_app.config['MAIL_DEFAULT_SENDER'],
        user.email,
        plain_template_path=('users/emails/'
                             'reset_password_instructions.txt.html'),
        html_template_path='users/emails/reset_password_instructions.html',
        **mail_context)

    reset_password_instructions_sent.send(
        current_app._get_current_object(),
        **signal_context)
Пример #4
0
def send_confirmation_instructions(user):
    """Sends confirmation instructions email to the specified user

    :param user: User to send instructions to
    """

    confirmation_token, confirmation_link = \
        generate_confirmation_token_and_link(user)

    signal_context = {'user': user, 'confirmation_token': confirmation_token}
    mail_context = {'user': user, 'confirmation_link': confirmation_link}

    send_mail(
        'Please confirm your email address',
        current_app.config['MAIL_DEFAULT_SENDER'],
        user.email,
        plain_template_path='users/emails/confirmation_instructions.txt.html',
        html_template_path='users/emails/confirmation_instructions.html',
        **mail_context)

    confirmation_instructions_sent.send(
        current_app._get_current_object(),
        **signal_context)