当前位置: 首页>>代码示例>>Python>>正文


Python ChangePasswordForm.is_valid方法代码示例

本文整理汇总了Python中forms.ChangePasswordForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python ChangePasswordForm.is_valid方法的具体用法?Python ChangePasswordForm.is_valid怎么用?Python ChangePasswordForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.ChangePasswordForm的用法示例。


在下文中一共展示了ChangePasswordForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: change_password

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
def change_password(request):
    if request.method == "POST":
        # print request.POST
        form = ChangePasswordForm(user=request.user, data=request.POST)
        # print form
        print form.is_valid()
        if form.is_valid():
            form.save()
            ret = {"status": 1, "msg": "is ok"}
        else:
            ret = {"status": 0, "msg": "is over"}
        obj = json.dumps(ret)
        return HttpResponse(obj)
    else:
        obj = json.dumps({"status": -1, "msg": "error"})
        return HttpResponse(obj)
开发者ID:fuqiang89,项目名称:voilet_code,代码行数:18,代码来源:account.py

示例2: change_password

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
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))
开发者ID:harshaampar,项目名称:litsoc,代码行数:35,代码来源:views.py

示例3: changePassword

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
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})
开发者ID:Geraldlim91,项目名称:onDemandNetworkEncryption,代码行数:32,代码来源:views.py

示例4: change_password

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
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()
开发者ID:ShaastraWebops,项目名称:shaastra_temporary_mainsite,代码行数:37,代码来源:ajax.py

示例5: password_change

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
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)) 
开发者ID:metajungle,项目名称:jungletasks,代码行数:28,代码来源:views.py

示例6: put

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
    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')
开发者ID:maxrevilo,项目名称:barachiel-server,代码行数:27,代码来源:views.py

示例7: change_password

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
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))
开发者ID:daniel-almeida,项目名称:CMSReScheduler,代码行数:27,代码来源:views.py

示例8: chpsw_doupdate

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
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()
开发者ID:csimstu,项目名称:cornucopia,代码行数:34,代码来源:views.py

示例9: Change_Passwords

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
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})
开发者ID:fortisaqua,项目名称:xmqb,代码行数:37,代码来源:views.py

示例10: edit_account

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
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,
    })
开发者ID:liasquil,项目名称:couch,代码行数:35,代码来源:views.py

示例11: changepassword

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
def changepassword(request):
    user = request.user
    form = ChangePasswordForm(initial={'username':user.unitsn})
    if request.method == "POST":
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            newpassword = request.POST['newpassword']
            user.set_password(newpassword)
            user.save()
            return HttpResponseRedirect("/login/")
    return render_to_response('changepassword.html', {'form':form,}, context_instance=RequestContext(request))
开发者ID:iefan,项目名称:kfjz,代码行数:13,代码来源:views.py

示例12: pass_change

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
def pass_change(request):
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(user, request.POST)
        if form.is_valid():
            with transaction.commit_on_success():
                user.set_password(form.cleaned_data["novo"])
                user.save()
                return render_to_response ('private/mensagem_generica.html',{'link':'/home', 'msg':'Senha Alterada com sucesso!'},  context_instance=RequestContext(request))
    else:
        form = ChangePasswordForm(user)
    return render_to_response("private/change_pwd.html", {'form': form}, context_instance=RequestContext(request))
开发者ID:hozano,项目名称:quest,代码行数:14,代码来源:views.py

示例13: changePassword

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
def changePassword(request):
	if request.method == 'POST':
		form = ChangePasswordForm(request.POST)
		if form.is_valid():
			newpassword = request.POST.get('newPassword', '')
			request.user.set_password(newpassword)
			request.user.save()
			return HttpResponseRedirect('successful/')
	else:
		form = ChangePasswordForm()
	
	return render(request, 'changePassword.html', {'form':form})
开发者ID:allevitan,项目名称:olinbartering,代码行数:14,代码来源:views.py

示例14: changepassword

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
def changepassword(request):
    if request.method == "POST":
        form = ChangePasswordForm(user=request.user, data=request.POST)
        if form.is_valid():
            form.save()
        return HttpResponseRedirect("/accounts/logout/")
    else:
        form = password_change_form(user=request.user)

    return render_to_response('index.html', {
        "title": '主页',
        'username': request.user.username,
        'form': form}, context_instance=RequestContext(request))
开发者ID:liuyuantao-Python,项目名称:student_performance_platform,代码行数:15,代码来源:account.py

示例15: change_password

# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import is_valid [as 别名]
def change_password(request):
    redirect_url = reverse("account.views.home")

    if request.method == "POST":
        form = ChangePasswordForm(user=request.user, data=request.POST)
        if form.is_valid():
            form.save(commit=True)
            return redirect(redirect_url)
    else:
        form = ChangePasswordForm(user=request.user)

    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'修改密码'}]
    return render_template("change_password.html", request, form=form, breadcrumb=breadcrumb)
开发者ID:cjie888,项目名称:django-ppmsg,代码行数:15,代码来源:views.py


注:本文中的forms.ChangePasswordForm.is_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。