def front_reset_pwd(request): if request.method == 'GET': return render(request, 'front_reset_pwd.html') else: username = request.user form = ResetpwdForm(request.POST, user=username) if form.is_vaild(): oldpwd = form.cleaned_data.get('oldpwd') newpwd = form.cleaned_data.get('newpwd') user = FrontUserModel.objects.filter(username=username, password=oldpwd).first() if user: is_vaild = user.check_password() if is_vaild: user.set_password(newpwd) user.save() return myjson.json_result() else: return myjson.json_params_error(message=u'密码验证错误!') else: user = user.create(username=username, password=newpwd) return myjson.json_result() else: return render(request, 'front_reset_pwd.html', {'error': form.get_error()})
def cms_reset_pwd(request): if request.method == 'GET': return render(request, 'cms_reset_pwd.html') else: username = request.user ## 使用cleaned_password方法 # form = ResetpwdForm(request.POST,username=username) # return render(request,'cms_reset_pwd.html',{'error':form.errors}) # 使用save_password方法 form = ResetpwdForm(request.POST, user=username) if form.is_vaild(): oldpwd = form.cleaned_data.get('oldpwd') user = authenticate(username=username, password=oldpwd) if user: is_vaild = form.save_password() if is_vaild: return myjson.json_result() else: return myjson.json_params_error(message=u'密码验证错误!') else: user = user.create(username=username, password=newpwd) return myjson.json_result() else: return render(request, 'cms_reset_pwd.html', {'error': form.get_error()})