Python django.contrib.auth.tokens 模块,PasswordResetTokenGenerator() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用django.contrib.auth.tokens.PasswordResetTokenGenerator()

项目:portailva    作者:BdEINSALyon    | 项目源码 | 文件源码
def save(self):
        """
        Generates a one-use only link for resetting password and sends to the
        user.
        """
        email = self.cleaned_data["email"]
        for user in self.get_users(email):

            # For each user, we generate a token
            uid = urlsafe_base64_encode(force_bytes(user.pk))
            token = PasswordResetTokenGenerator().make_token(user)

            # We make the reset URL to be sent by mail
            reset_url = settings.PORTAILVA_APP['site']['url'] + reverse('member-reset-password-confirm', kwargs={
                'uidb64': uid,
                'token': token
            })

            # Then we send the mail
            context = {
                'reset_url': reset_url
            }

            send_mail(
                template_html_name='mail/member/reset_password.html',
                template_text_name='mail/member/reset_password.text',
                context=context,
                subject="Réinitialisation du mot de passe",
                to=user.email
            )