def password(request): ''' Password change / set form. ''' if settings.DEMO_SERVER and request.user.username == 'demo': return deny_demo(request) do_change = False if not request.user.has_usable_password(): do_change = True change_form = None elif request.method == 'POST': change_form = PasswordChangeForm(request.POST) if change_form.is_valid(): cur_password = change_form.cleaned_data['password'] do_change = request.user.check_password(cur_password) if not do_change: messages.error( request, _('You have entered an invalid password.') ) else: change_form = PasswordChangeForm() if request.method == 'POST': form = PasswordForm(request.POST) if form.is_valid() and do_change: # Clear flag forcing user to set password redirect_page = '#auth' if 'show_set_password' in request.session: del request.session['show_set_password'] redirect_page = '' request.user.set_password( form.cleaned_data['password1'] ) request.user.save() # Update session hash update_session_auth_hash(request, request.user) messages.success( request, _('Your password has been changed.') ) return redirect_profile(redirect_page) else: form = PasswordForm() return render( request, 'accounts/password.html', { 'title': _('Change password'), 'change_form': change_form, 'form': form, } )
def password(request): ''' Password change / set form. ''' if appsettings.DEMO_SERVER and request.user.username == 'demo': return deny_demo(request) do_change = False if not request.user.has_usable_password(): do_change = True change_form = None elif request.method == 'POST': change_form = PasswordChangeForm(request.POST) if change_form.is_valid(): cur_password = change_form.cleaned_data['password'] do_change = request.user.check_password(cur_password) if not do_change: messages.error( request, _('You have entered an invalid password.') ) else: change_form = PasswordChangeForm() if request.method == 'POST': form = PasswordForm(request.POST) if form.is_valid() and do_change: # Clear flag forcing user to set password redirect_page = '#auth' if 'show_set_password' in request.session: del request.session['show_set_password'] redirect_page = '' request.user.set_password( form.cleaned_data['password1'] ) request.user.save() # Update session hash update_session_auth_hash(request, request.user) messages.success( request, _('Your password has been changed.') ) return redirect_profile(redirect_page) else: form = PasswordForm() return render( request, 'accounts/password.html', { 'title': _('Change password'), 'change_form': change_form, 'form': form, } )
def password(request): ''' Password change / set form. ''' do_change = False if request.user.has_usable_password(): if request.method == 'POST': change_form = PasswordChangeForm(request.POST) if change_form.is_valid(): cur_password = change_form.cleaned_data['password'] if request.user.check_password(cur_password): do_change = True else: messages.error( request, _('You have entered an invalid password.') ) else: change_form = PasswordChangeForm() else: do_change = True change_form = None if request.method == 'POST': form = PasswordForm(request.POST) if form.is_valid() and do_change: # Clear flag forcing user to set password if 'show_set_password' in request.session: del request.session['show_set_password'] request.user.set_password( form.cleaned_data['password1'] ) request.user.save() messages.info( request, _('Your password has been changed.') ) return redirect('profile') else: form = PasswordForm() return render_to_response( 'accounts/password.html', RequestContext( request, { 'title': _('Change password'), 'change_form': change_form, 'form': form, } ) )
def password(request): ''' Password change / set form. ''' do_change = False if request.user.has_usable_password(): if request.method == 'POST': change_form = PasswordChangeForm(request.POST) if change_form.is_valid(): cur_password = change_form.cleaned_data['password'] if request.user.check_password(cur_password): do_change = True else: messages.error( request, _('You have entered an invalid password.') ) else: change_form = PasswordChangeForm() else: do_change = True change_form = None if request.method == 'POST': form = PasswordForm(request.POST) if form.is_valid() and do_change: # Clear flag forcing user to set password if 'show_set_password' in request.session: del request.session['show_set_password'] request.user.set_password( form.cleaned_data['password1'] ) request.user.save() messages.info( request, _('Your password has been changed.') ) return redirect('profile') else: form = PasswordForm() return render( request, 'accounts/password.html', { 'title': _('Change password'), 'change_form': change_form, 'form': form, } )
def password(request): """ Password change / set form. """ if appsettings.DEMO_SERVER and request.user.username == "demo": return deny_demo(request) do_change = False if not request.user.has_usable_password(): do_change = True change_form = None elif request.method == "POST": change_form = PasswordChangeForm(request.POST) if change_form.is_valid(): cur_password = change_form.cleaned_data["password"] do_change = request.user.check_password(cur_password) if not do_change: messages.error(request, _("You have entered an invalid password.")) else: change_form = PasswordChangeForm() if request.method == "POST": form = PasswordForm(request.POST) if form.is_valid() and do_change: # Clear flag forcing user to set password if "show_set_password" in request.session: del request.session["show_set_password"] request.user.set_password(form.cleaned_data["password1"]) request.user.save() # Update session hash for Django 1.7 if update_session_auth_hash: update_session_auth_hash(request, request.user) messages.success(request, _("Your password has been changed.")) return redirect("profile") else: form = PasswordForm() return render( request, "accounts/password.html", {"title": _("Change password"), "change_form": change_form, "form": form} )