def password_change(request): extra_context = {} password_change_form = forms.PasswordChangeForm passform = password_change_form(user=request.user) if request.method == 'POST': passform = password_change_form(user=request.user, data=request.POST) if passform.is_valid(): passform.save() usable = request.user.has_usable_password() events = [] if not usable: from freenasUI.tools.alert import Alert alert = Alert() alert.perform() alert.write() del alert events.append("loadalert()") return JsonResp( request, message=_("Password successfully updated."), events=events, ) extra_context.update({ 'form': passform, 'inline': True, }) return render(request, 'account/passform.html', extra_context)
def password_change(request): extra_context = {} password_change_form = forms.PasswordChangeForm passform = password_change_form(user=request.user) if request.method == 'POST': passform = password_change_form(user=request.user, data=request.POST) if passform.is_valid(): if passform.cleaned_data['change_root']: root = models.bsdUsers.objects.get(bsdusr_username='******') new_password = passform.cleaned_data.get('new_password1') bsdpasswdform = forms.bsdUserPasswordForm(instance=root) bsdpasswdform.cleaned_data = {} bsdpasswdform.cleaned_data['bsdusr_password1'] = new_password bsdpasswdform.cleaned_data['bsdusr_password2'] = new_password bsdpasswdform.save() usable = request.user.has_usable_password() passform.save() events = [] if not usable: from freenasUI.tools.alert import Alert alert = Alert() alert.perform() alert.write() del alert events.append("loadalert()") return JsonResp(request, message=_("Password successfully updated."), events=events) extra_context.update({ 'form': passform, 'inline': True, }) return render(request, 'account/passform.html', extra_context)