本文整理汇总了Python中forms.ChangePasswordForm类的典型用法代码示例。如果您正苦于以下问题:Python ChangePasswordForm类的具体用法?Python ChangePasswordForm怎么用?Python ChangePasswordForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChangePasswordForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_password
def change_password(request):
if request.method == 'POST':
changepasswordForm = ChangePasswordForm(request.POST)
if changepasswordForm.is_valid():
user = request.user
password_old = changepasswordForm.cleaned_data['password_old']
if user.check_password(password_old):
password_new_1 = changepasswordForm.cleaned_data['password_new_1']
password_new_2 = changepasswordForm.cleaned_data['password_new_2']
if password_new_1 == password_new_2:
user.set_password(password_new_1)
user.save()
messages.success(request,'Password successfully changed')
return HttpResponseRedirect(request.path)
else:
messages.error(request,'Passwords don\'t match')
return HttpResponseRedirect(request.path)
else:
messages.error(request,'Wrong password, try again')
return HttpResponseRedirect(request.path)
else:
messages.error(request,'Incorrect entry')
return HttpResponseRedirect(request.path)
else:
editprofileForm = ChangePasswordForm()
return_url=reverse('change_password')
to_return = {
'form' : editprofileForm,
'title' : 'Change Password',
'return_url' : return_url,
'button' : 'Change',
}
return render(request,'form.html',to_return,context_instance=RequestContext(request))
示例2: change_password
def change_password(request,form = None):
dajax = Dajax()
dajax.script("$(\'#dashboard #loading_dash_dajax\').hide();")
if not request.user.is_authenticated():
dajax.script('$.bootstrapGrowl("Login First!", {type:"danger",delay:10000} );')
return dajax.json()
# print deserialize_form(form)
if form is None:
dajax.script('$.bootstrapGrowl("Invalid password change request", {type:"danger",delay:10000} );')
return dajax.json()
form = ChangePasswordForm(deserialize_form(form))
if not form.is_valid():
errdict = dict(form.errors)
for error in form.errors:
# if str(errdict[error][0])!='This field is required.':
dajax.script('$.bootstrapGrowl("%s:: %s" , {type:"error",delay:10000} );'% (str(error),str(errdict[error][0])))
dajax.script("$(\'#form_change_password #id_new_password').val('');$('#form_change_password #id_new_password_again').val('');")
return dajax.json()
user = request.user
if not user.check_password(form.cleaned_data['old_password']):
dajax.script('$.bootstrapGrowl("Please check your old password" , {type:"error",delay:10000} );')
return dajax.json()
user.set_password(form.cleaned_data['new_password'])
profile = UserProfile.objects.get(user=request.user)
user.save()
profile.save()
dajax.script('$.bootstrapGrowl("Your password was changed successfully!" , {type:"success",delay:30000} );')
#TODO: why is the field not getting empty?????
dajax.script('$("#dashboard #form_change_password #id_old_password").val("");')
dajax.script('$("#dashboard #form_change_password #id_new_password").val("");')
dajax.script('$("#dashboard #form_change_password #id_new_password_again").val("");')
return dajax.json()
示例3: change_password
def change_password(request):
if request.user.is_authenticated():
# Gets user info of the current user logged in the system
if request.method == 'POST':
form = ChangePasswordForm(request.POST)
if form.is_valid():
old_password = request.POST['old_password'].strip()
print old_password
newpassword = request.POST['newpassword'].strip()
newpassword2 = request.POST['newpassword2'].strip()
if old_password and newpassword and newpassword2 == newpassword:
saveuser = User.objects.get(id=request.user.id)
if request.user.check_password(old_password):
saveuser.set_password(request.POST['newpassword']);
saveuser.save()
return HttpResponse('Your password was changed.')
else:
return HttpResponse('Your old password is incorrect. Please, try again.')
else:
return HttpResponse('Insert your old password and new password correctly.')
else:
form = ChangePasswordForm()
c = {'form': form}
return render_to_response("password_change.html", c, context_instance=RequestContext(request))
示例4: chpsw_doupdate
def chpsw_doupdate(request):
if request.method == "POST":
cpf = ChangePasswordForm(request.POST)
if cpf.is_valid():
username = cpf.cleaned_data['username']
hash_key = cpf.cleaned_data['hash_key']
newpswrd = cpf.cleaned_data['password']
try:
user = User.objects.get(username = username)
es = EmailHash.objects.get(holder = user)
except Exception:
raise Http404
if es and es.hash_str == hash_key:
user.set_password(newpswrd)
user.save()
user = authenticate(username = username,password = newpswrd)
login(request,user)
messages.success(request,"Change password succesfully!")
es.delete()
return HttpResponseRedirect(reverse("xadmin:inbox"))
else:
return render(request,"xadmin/change_password.html", {
"usr": request.POST['username'],
"key": request.POST['hash_key'],
'form': cpf,
})
raise Http404()
示例5: changePassword
def changePassword(request):
otherVars = {}
otherVars["pageType"] = "logon"
otherVars["UserInfo"] = request.user.first_name + " " + request.user.last_name
if request.method == "POST":
form1 = ChangePasswordForm(request.user, request.POST)
# input validation for change password
if form1.is_valid():
# update the user information
form1.save()
request.session["msgNote"] = [
"fileView",
{"sign": "ok", "msg": "Your password has been updated successfully!"},
]
return HttpResponseRedirect(reverse("fileView"))
else:
form1 = ChangePasswordForm(request.user)
# Define header groups
hgrps = ({"name": "Change Password", "lblwidth": "160"},)
# For first header group
form1.fields["oldPwd"].widget.attrs["hgrp"] = "0"
form1.fields["oldPwd"].widget.attrs["wsize"] = "300"
form1.fields["newPwd"].widget.attrs["hgrp"] = "0"
form1.fields["newPwd"].widget.attrs["wsize"] = "300"
form1.fields["cfmPwd"].widget.attrs["hgrp"] = "0"
form1.fields["cfmPwd"].widget.attrs["wsize"] = "300"
return render(request, "main/chgpasswd.html", {"otherVars": otherVars, "form1": form1, "hgrps": hgrps})
示例6: edit_account
def edit_account(request, entry=None):
if entry not in (None, 'email', 'username', 'password'):
raise Http404
if request.method=='POST' and entry=='email':
email_form = ChangeEmailForm(request.POST, instance=request.user)
if email_form.is_valid():
email_form.save()
return redirect('accounts:edit_account')
else:
email_form = ChangeEmailForm(instance=request.user)
if request.method=='POST' and entry=='username':
username_form = ChangeUsernameForm(request.POST, instance=request.user)
if username_form.is_valid():
username_form.save()
return redirect('accounts:edit_account')
else:
username_form = ChangeUsernameForm(instance=request.user)
if request.method=='POST' and entry=='password':
password_form = ChangePasswordForm(request.POST, instance=request.user)
if password_form.is_valid():
password_form.save()
return redirect('accounts:edit_account')
else:
password_form = ChangePasswordForm(instance=request.user)
return render(request, 'accounts/edit_account.html', {
'email_form': email_form,
'username_form': username_form,
'password_form': password_form,
})
示例7: change_password
def change_password():
user = None
if current_user.is_authenticated:
if not login_fresh():
return login_manager.needs_refresh()
user = current_user
elif 'activation_key' in request.values and 'email' in request.values:
activation_key = request.values['activation_key']
email = request.values['email']
user = User.query.filter_by(activation_key=activation_key) \
.filter_by(email=email).first()
if user is None:
abort(403)
form = ChangePasswordForm(activation_key=user.activation_key)
if form.validate_on_submit():
user.password = form.password.data
user.activation_key = None
db.session.add(user)
db.session.commit()
flash("Your password has been changed, please log in again", "success")
return redirect(url_for("frontend.login"))
return render_template("frontend/change_password.html", form=form)
示例8: put
def put(self, request, *args, **kwargs):
request.PUT = PUT_dict(request, ['password', 'new_password'])
user = request.user
form = ChangePasswordForm(request.PUT)
if form.is_valid():
print "form is valid"
password = request.PUT["password"]
new_password = request.PUT["new_password"]
if not user.check_password(password):
errors = form._errors.setdefault("password", ErrorList())
errors.append(u"The entered password is not correct.")
return HttpResponseBadRequest(json.dumps(form.errors), mimetype='application/json')
print "password is correct"
if password == new_password:
errors = form.NON_FIELD_ERRORS.setdefault("__all__", ErrorList())
errors.append(u"The old password equals new password.")
return HttpResponseBadRequest(json.dumps(form.errors), mimetype='application/json')
print "password equals new password"
user.set_password(new_password)
user.save()
return HttpResponse()
else:
return HttpResponseBadRequest(json.dumps(form.errors), mimetype='application/json')
示例9: password_change
def password_change(request):
"""
A view for changing a password
"""
if request.method == 'POST':
form = ChangePasswordForm(request.POST)
if form.is_valid():
email = form.cleaned_data.get('email')
if email == '[email protected]':
msg = 'The demo user cannot change the password'
messages.error(request, msg)
else:
# change the password
form.change_password(request.user)
# re-direct to information message
msg = """
Your password was successfully changed!
"""
messages.success(request, msg)
else:
form = ChangePasswordForm()
return render_to_response('account/password_change.html',
{ 'form' : form },
context_instance=RequestContext(request))
示例10: Change_Passwords
def Change_Passwords(request):
if not request.user.is_authenticated():
return redirect('/weblogin')
if request.method == "POST":
form = ChangePasswordForm(request.POST)
if form.is_valid():
username = request.user.username
oldpassord = form.cleaned_data['oldpassword']
newpassword = form.cleaned_data['newpassword']
newpassword1 = form.cleaned_data['newpassword1']
user = authenticate(username=username,password=oldpassord)
if user:
if newpassword == newpassword1:
user.set_password(newpassword)
user.save()
# After changing the password , messages saved in the browser is still the old password ,
# so if you want to stay log in status after changing password , log in with new password again!!!!!!!
user = authenticate(username=username,password=newpassword)
login(request, user)
messages.add_message(request, messages.SUCCESS, u'密码修改成功.')
else:
messages.add_message(request, messages.SUCCESS, u'两次输入新密码需要一致!!.')
return render(request, 'webuser/change_password.html', {'form': form})
else:
if newpassword == newpassword1:
messages.add_message(request, messages.SUCCESS, u'原密码错误!!!!')
return render(request, 'webuser/change_password.html', {'form': form})
else:
messages.add_message(request, messages.SUCCESS, u'原密码错误,并且两次输入新密码不一致!!!!')
return render(request, 'webuser/change_password.html', {'form': form})
else:
return render(request, 'webuser/change_password.html', {'form': form})
else:
form = ChangePasswordForm()
return render(request, 'webuser/change_password.html', {'form': form})
示例11: account_settings
def account_settings():
form = AccountForm()
formpass = ChangePasswordForm()
error = ''
sel_tab = 1
user = UserAccount.query.filter(UserAccount.id==g.user.id).one()
if form.validate_on_submit():
user.username = form.username.data
user.email = form.email.data
db.session.add(user)
db.session.commit()
flash ('Changes saved.')
form.username.data = user.username
form.email.data = user.email
if request.method == 'POST' and formpass.submit_pass:
sel_tab = 2
if formpass.validate_on_submit():
password = md5.md5(formpass.password.data).hexdigest()
user1 = UserAccount.query.filter(and_(UserAccount.id==g.user.id, UserAccount.password==password)).first()
if not user1:
error = 'Invalid password.'
else:
newpassword = md5.md5(formpass.newpassword.data).hexdigest()
user1.password = newpassword
db.session.add(user1)
db.session.commit()
flash ('New password saved.')
return render_template('account.html', form=form, formpass=formpass, site_data=site_data(), navigation=return_navigation(), error=error, sel_tab=sel_tab)
示例12: change_password
def change_password():
form = ChangePasswordForm(request.form)
if request.method == "POST" and form.validate():
user = User.query.filter_by(name=g.user.name).first()
user.password = hash_str(form.password.data)
user.save()
return redirect(url_for('user.settings'))
return redirect(url_for('user.settings'))
示例13: change_password
def change_password():
form = ChangePasswordForm()
if form.validate_on_submit():
current_user.password = form.new_password.data
db.session.add(current_user)
db.session.commit()
flash('your password change successful.')
return redirect(url_for('main.index'))
return render_template('auth/change_password.html', form=form)
示例14: change_password
def change_password():
if( request.method == "POST"):
form = ChangePasswordForm( request.form)
if( form.validate()):
current_user.set_password( form.password1.data)
flash( "Your password was changed successfully.", "success")
return redirect( "/")
else:
form = ChangePasswordForm()
return render_template( "auth/change_password.html", **locals())
示例15: index
def index():
form = ChangePasswordForm()
if form.validate_on_submit():
user = models.User.query.filter_by(name="Admin").first()
if user.check_password(form.current_password.data):
user.set_password(form.new_password.data)
db.session.commit()
else:
flash('Verify your password', 'error')
return render_template('index.html', form=form)