我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.contrib.auth.update_session_auth_hash()。
def get_context_data(self, **kwargs): context = super(LoginSignupView, self).get_context_data(**kwargs) context.update({ 'signup_form': RegistrationForm(), 'message':'' }) return context # def change_password(request): # if request.method == 'POST': # form = PasswordChangeForm(request.user, request.POST) # if form.is_valid(): # user = form.save() # update_session_auth_hash(request, user) # Important! # messages.success(request, 'Your password was successfully updated!') # return redirect('login:change_password') # else: # messages.error(request, 'Please correct the error below.') # else: # form = PasswordChangeForm(request.user) # response = render(request, 'password_change.html', { # 'form': form # }) # response.set_cookie('password_changed', 'true') # return response
def form_valid(self, form): form.save() if (update_session_auth_hash is not None and not app_settings.LOGOUT_ON_PASSWORD_CHANGE): update_session_auth_hash(self.request, form.user) get_adapter().add_message(self.request, messages.SUCCESS, 'account/messages/password_changed.txt') signals.password_changed.send(sender=self.request.user.__class__, request=self.request, user=self.request.user) return super(PasswordChangeView, self).form_valid(form)
def logout_on_password_change(request, user): if (update_session_auth_hash is not None and not settings.LOGOUT_ON_PASSWORD_CHANGE): update_session_auth_hash(request, user)
def change_password(self, form): user = self.request.user user.set_password(form.cleaned_data["password_new"]) user.save() # required on Django >= 1.7 to keep the user authenticated if hasattr(auth, "update_session_auth_hash"): auth.update_session_auth_hash(self.request, user)
def logout_on_password_change(request, user): # Since it is the default behavior of Django to invalidate all sessions on # password change, this function actually has to preserve the session when # logout isn't desired. if (update_session_auth_hash is not None and not app_settings.LOGOUT_ON_PASSWORD_CHANGE): update_session_auth_hash(request, user)