当前位置: 首页>>代码示例>>Python>>正文


Python tokens.PasswordResetTokenGenerator方法代码示例

本文整理汇总了Python中django.contrib.auth.tokens.PasswordResetTokenGenerator方法的典型用法代码示例。如果您正苦于以下问题:Python tokens.PasswordResetTokenGenerator方法的具体用法?Python tokens.PasswordResetTokenGenerator怎么用?Python tokens.PasswordResetTokenGenerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.tokens的用法示例。


在下文中一共展示了tokens.PasswordResetTokenGenerator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_password_reset_url

# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import PasswordResetTokenGenerator [as 别名]
def generate_password_reset_url(user_profile: UserProfile,
                                token_generator: PasswordResetTokenGenerator) -> str:
    token = token_generator.make_token(user_profile)
    uid = urlsafe_base64_encode(force_bytes(user_profile.id))
    endpoint = reverse('django.contrib.auth.views.password_reset_confirm',
                       kwargs=dict(uidb64=uid, token=token))
    return f"{user_profile.realm.uri}{endpoint}" 
开发者ID:zulip,项目名称:zulip,代码行数:9,代码来源:forms.py

示例2: setup_password_reset_confirm_tests

# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import PasswordResetTokenGenerator [as 别名]
def setup_password_reset_confirm_tests(self):
        from django.utils.encoding import force_bytes, force_str
        from django.utils.http import urlsafe_base64_encode

        # Get user
        self.user = get_user_model().objects.get(username='test')

        # Generate a password reset token
        self.password_reset_token = PasswordResetTokenGenerator().make_token(self.user)

        # Generate a password reset uid
        self.password_reset_uid = force_str(urlsafe_base64_encode(force_bytes(self.user.pk)))

        # Create url_args
        if DJANGO_VERSION >= (3, 0):
            token = auth_views.PasswordResetConfirmView.reset_url_token
        else:
            token = auth_views.INTERNAL_RESET_URL_TOKEN

        self.url_kwargs = dict(uidb64=self.password_reset_uid, token=token)

        # Add token to session object
        s = self.client.session
        s.update({
            auth_views.INTERNAL_RESET_SESSION_TOKEN: self.password_reset_token,
        })
        s.save() 
开发者ID:wagtail,项目名称:wagtail,代码行数:29,代码来源:test_account_management.py

示例3: valid

# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import PasswordResetTokenGenerator [as 别名]
def valid(self, user, token):
        """
        Verify that the activation token is valid and within the
        permitted activation time window.
        """

        token_generator = PasswordResetTokenGenerator()
        return user is not None and token_generator.check_token(user, token) 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:10,代码来源:views.py

示例4: send_activation_email

# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import PasswordResetTokenGenerator [as 别名]
def send_activation_email(user, site=None):
    """
    Send the activation email. The activation key is the username,
    signed using TimestampSigner.
    """
    token_generator = PasswordResetTokenGenerator()
    token = token_generator.make_token(user)

    uid = urlsafe_base64_encode(force_bytes(user.pk))

    activation_path = reverse('users:activate', kwargs={'uidb64': uid, 'token': token})

    context = {
        'user': user,
        'name': user.get_full_name(),
        'username': user.get_username(),
        'activation_path': activation_path,
        'timeout_days': settings.PASSWORD_RESET_TIMEOUT_DAYS,
        'org_long_name': settings.ORG_LONG_NAME,
    }

    if site:
        context.update(site=site)

    subject = 'Account details for {username} at {org_long_name}'.format(**context)
    # Force subject to a single line to avoid header-injection issues.
    subject = ''.join(subject.splitlines())
    message = render_to_string('users/activation/email.txt', context)
    user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL) 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:31,代码来源:utils.py

示例5: test_PasswordResetConfirmView_valid_token

# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import PasswordResetTokenGenerator [as 别名]
def test_PasswordResetConfirmView_valid_token(self):
        # PasswordResetConfirmView valid token
        client = PasswordResetConfirmClient()
        default_token_generator = PasswordResetTokenGenerator()
        token = default_token_generator.make_token(self.user)
        uidb64 = urlsafe_base64_encode(str(self.user.pk).encode()).decode()
        url = reverse('password_reset_confirm', kwargs={'uidb64': uidb64, 'token': token})
        response = client.get(url)
        self.assertContains(response, '<title>Enter new password</title>')
        self.assertContains(response, '<h1>Enter new password</h1>') 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:test_templates.py

示例6: test_PasswordResetConfirmView_valid_token

# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import PasswordResetTokenGenerator [as 别名]
def test_PasswordResetConfirmView_valid_token(self):
        # PasswordResetConfirmView valid token
        client = PasswordResetConfirmClient()
        default_token_generator = PasswordResetTokenGenerator()
        token = default_token_generator.make_token(self.user)
        uidb64 = urlsafe_base64_encode(str(self.user.pk).encode())
        url = reverse('password_reset_confirm', kwargs={'uidb64': uidb64, 'token': token})
        response = client.get(url)
        self.assertContains(response, '<title>Enter new password</title>')
        self.assertContains(response, '<h1>Enter new password</h1>') 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:test_templates.py


注:本文中的django.contrib.auth.tokens.PasswordResetTokenGenerator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。