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