我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用django.contrib.auth.views.password_reset_confirm()。
def get(self, request, uidb64=None, token=None): if request.user.is_authenticated(): return redirect(get_redirect_url(request)) # Seo seo = Seo() seo.title = _('Password reset') seo.save(request) try: uid = urlsafe_base64_decode(uidb64) user = UserModel._default_manager.get(pk=uid) except (TypeError, ValueError, OverflowError, ObjectDoesNotExist): user = None if user is None or not default_token_generator.check_token(user, token): return redirect(resolve_url(settings.RESET_PASSWORD_REDIRECT_URL)) return password_reset_confirm(request, uidb64=uidb64, token=token, template_name='users/reset_confirm.html', set_password_form=SetPasswordForm, post_reset_redirect='users:reset_complete', )
def password_reset_confirm(request, initial=False, extra_context={}, **kwargs): extra_context.update({ 'password_policy': password_validators_help_text_html()}) response = auth_views.password_reset_confirm( request, extra_context=extra_context, **kwargs) if isinstance( response, HttpResponseRedirect) and response.status_code == 302: # Send password change confirmation email try: uid = force_text(urlsafe_base64_decode(kwargs['uidb64'])) user = MunchUser.objects.get(pk=uid) if initial: user.send_invitation_complete_email() else: user.send_password_reset_complete_email() except (TypeError, ValueError, OverflowError, MunchUser.DoesNotExist): pass return response
def do_view(self, request, uidb36, token, *args, **kwargs): context = super(ResetPasswordComfirmView, self).get_context() return password_reset_confirm(request, uidb36, token, template_name=self.password_reset_confirm_template, token_generator=self.password_reset_token_generator, set_password_form=self.password_reset_set_form, post_reset_redirect=self.get_admin_url('xadmin_password_reset_complete'), current_app=self.admin_site.name, extra_context=context)
def post(self, request, uidb64=None, token=None): # Seo seo = Seo() seo.title = _('Password reset') seo.save(request) if request.user.is_authenticated(): # ????? ?????? ??????, ???? ???????????? form = SetPasswordForm(request.user, request.POST) if form.is_valid(): form.save() return redirect(get_redirect_url(request, 'users:reset_complete')) else: return self.render_to_response({ 'form': form, }) else: if uidb64 is None or token is None: return redirect(resolve_url(settings.RESET_PASSWORD_REDIRECT_URL)) return password_reset_confirm(request, uidb64=uidb64, token=token, template_name='users/reset_confirm.html', set_password_form=SetPasswordForm, post_reset_redirect='users:reset_complete', )
def forgot_passwd_check(request, uidb64=None, token=None): """ Page that checks the hash in a password reset link, generates a new password which is send via SMS to the user. """ assert uidb64 is not None and token is not None try: user = User.objects.get(id=urlsafe_base64_decode(uidb64)) profile = user.userprofile except (ValueError, OverflowError, User.DoesNotExist): profile = None if profile and profile.email_token == token: # Email address is verified, we cant compare to token as register token is different to reset one. profile.email_token = '' profile.email_verified = True # This may look strange - setting the phone_verified before the user logs in. It is not :) We are sending new # password to phone number in profile, after the user logs in we would set phone_verified to True anyway. profile.phone_verified = True profile.save() return password_reset_confirm( request, uidb64=uidb64, token=token, template_name='gui/accounts/forgot_check.html', set_password_form=PasswordResetForm, post_reset_redirect=reverse('forgot_check_done'), current_app='gui')
def custom_password_reset_confirm(request, uidb64=None, token=None): if request.is_ajax(): return auth_view.password_reset_confirm(request, uidb64, token, set_password_form=CustSetPswForm) else: return render(request, 'registration/form_redirect.html', {'form_url': request.build_absolute_uri()})