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

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

项目:LDERP    作者:Ignoramuss    | 项目源码 | 文件源码
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
项目:Provo-Housing-Database    作者:marcopete5    | 项目源码 | 文件源码
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)
项目:planet-b-saleor    作者:planet-b    | 项目源码 | 文件源码
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)
项目:wagtail_room_booking    作者:Tamriel    | 项目源码 | 文件源码
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)
项目:django-twilio-tfa    作者:rtindru    | 项目源码 | 文件源码
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)