Esempio n. 1
0
def send_reset_password_token_email(user, domain):
    """
    Send reset password token to user email

    Args:
        user (object): The user instance
        domain (string): The current domain
    """

    # Get activate link
    reset_password_link = domain + \
        reverse('reset_password_confirm', \
            kwargs=generate_uid_and_token(user, reset_password_token))

    # Default template message
    default_message = \
        DEFAULT_EMAIL_BODY['RESET_PASSWORD'].format(reset_password_link=reset_password_link)

    html_template = drfr_settings.RESET_PASSWORD_EMAIL_TEMPLATE

    html_message = render_to_string(html_template, {
        'reset_password_link': reset_password_link,
        'domain': domain
    }) if html_template else None

    send_mail(subject=drfr_settings.RESET_PASSWORD_EMAIL_SUBJECT,
              message='',
              from_email=settings.DEFAULT_FROM_EMAIL,
              recipient_list=[
                  user.email,
              ],
              html_message=html_message or default_message)
Esempio n. 2
0
def send_activate_token_email(user, domain):
    """
    Send activate token to user email

    Args:
        user (object): The user instance
        domain (string): The current domain
    """

    # Get activate link
    activate_link = domain + \
        reverse('activate', kwargs=generate_uid_and_token(user, activation_token))

    # Default template message
    default_message = DEFAULT_EMAIL_BODY['ACTIVATE'].format(
        activate_link=activate_link)

    html_template = drfr_settings.USER_ACTIVATE_EMAIL_TEMPLATE

    html_message = render_to_string(html_template, {
        'activate_link': activate_link,
        'domain': domain
    }) if html_template else None

    send_mail(subject=drfr_settings.USER_ACTIVATE_EMAIL_SUBJECT,
              message='',
              from_email=settings.DEFAULT_FROM_EMAIL,
              recipient_list=[
                  user.email,
              ],
              html_message=html_message or default_message)
Esempio n. 3
0
 def test_register_activate_token_success_views(self):
     uid_token = generate_uid_and_token(self.user, activation_token)
     uid = uid_token['uidb64']
     token = uid_token['token']
     resp = self.get_json_ok(f'activate/{uid}/{token}/')
     self.assertContains(resp,
                         'Your account has been activate successfully.')
Esempio n. 4
0
 def test_generate_uid_and_token(self):
     uid_token = users.generate_uid_and_token(self.user)
     self.assertHasProps(uid_token, ['uidb64', 'token'])