Exemplo n.º 1
0
def change_password_view():

    if not session["is_auth"]:
        return redirect(url_for('main_view'))

    form = ChangePasswordForm()

    if request.method == "POST":

        if form.validate_on_submit():

            user = db.session.query(User).get(session["user"]["id"])

            if user.password_valid(form.password.data):
                form.password.errors.append("Вы используете старый пароль!")
                return render_template("change_password.html", form=form)

            user.set_password(form.password.data)

            db.session.add(user)
            db.session.commit()

            return redirect(url_for('account_view'))

    return render_template("change_password.html", form=form)
Exemplo n.º 2
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if form.selecttype.data == 'admin':
            admin = Admin.query.filter_by(name=form.name.data).first()
            if admin is None:
                flash(u'用户不存在')
                return render_template('changePassword.html', form=form)
            admin.password = md5(form.password.data).hexdigest()
        elif form.selecttype.data == 'teacher':
            teacher = None
            if form.name.data.isdigit():
                teacher = Teacher.query.filter_by(id=int(form.name.data) +
                                                  DEFAULT).first()
            if teacher is None:
                flash(u'用户不存在')
                return render_template('changePassword.html', form=form)
            teacher.password = md5(form.password.data).hexdigest()
        else:
            student = None
            if form.name.data.isdigit():
                student = Student.query.filter_by(
                    id=int(form.name.data)).first()
            if student is None:
                flash(u'用户不存在')
                return render_template('changePassword.html', form=form)
            student.password = md5(form.password.data).hexdigest()
        db.session.commit()
        flash(u'修改密码成功')
        return redirect(url_for('change_password'))
    return render_template('changePassword.html', form=form)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def changePassword():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if form.newPassword.data != form.newPassword2.data:
            flash("Passwords must match")
            return redirect(url_for('changePassword'))
        connection = sqlite3.connect('data/site.db')
        cur = connection.cursor()
        for row in cur.execute("SELECT username, password from user_data"):
            if (current_user.id == row[0]):
                presentPassword = row[1]
                if bcrypt.checkpw(form.currentPassword.data.encode(),
                                  presentPassword):
                    id = current_user.id
                    salt = bcrypt.gensalt()
                    newPassword = bcrypt.hashpw(
                        form.newPassword2.data.encode(), salt)
                    cur.execute(
                        "Update user_data set password=? where username=?",
                        (newPassword, id))
                    connection.commit()
                    cur.close()
                    logout_user()
                    flash(
                        "You have been logged out. Your password has been changed !"
                    )
                    return redirect('/')
                else:
                    flash("Wrong Password")
                    return redirect('/changePassword')
    return render_template('changePassword.html', form=form)
Exemplo n.º 5
0
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))
Exemplo n.º 6
0
    def post(self):
        old_password = self.get_argument("old_password")
        new_password = self.get_argument("new_password")
        confirm_password = self.get_argument("confirm_password")

        form = ChangePasswordForm(self.request.arguments)

        password_error = password_validation(self.session, self.uid,
                                             old_password)

        if form.validate():
            if password_error == "":
                change_password(self.session, self.uid, new_password)
                self.redirect("/")
            else:
                self.render("changepassword.html",
                            username=self.username,
                            group=self.group,
                            form=form,
                            db_error=password_error)
        else:
            self.render("changepassword.html",
                        username=self.username,
                        group=self.group,
                        form=form,
                        db_error=None)
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()
Exemplo n.º 8
0
def edit_profile():
    user = User.query.get(current_user.id)
    form = EditProfileForm(request.form, phone=user.phone, email=user.email)
    passform = ChangePasswordForm(request.form)
    if request.method == 'POST':
        #if the user clicked button to update profile
        if request.form['submit'] == 'Update' and form.validate_on_submit():
            phone = form.phone.data
            email = form.email.data
            user.phone = phone
            user.email = email
            db.session.commit()
            return redirect('home')
        #if user clicked change password
        if request.form[
                'submit'] == 'Change Password' and passform.validate_on_submit(
                ):
            #generate hash
            newpass = generate_password_hash(passform.password.data)
            user.password_hash = newpass
            db.session.commit()
            return redirect('edit_profile')
    return render_template('edit_profile.html',
                           form=form,
                           passform=passform,
                           user=user)
Exemplo n.º 9
0
def render_admin_change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        old_password = form.oldPassword.data
        new_password = form.newPassword.data
        confirm_password = form.confirmPassword.data
        if new_password != confirm_password:
            form.confirmPassword.errors.append(
                "newPassword must be the same as the confirmPassword!")
        else:
            query = "SELECT password FROM users WHERE uname = '{}'".format(
                current_user.uname)
            password = db.session.execute(query).fetchone()[0]
            if password != old_password:
                form.oldPassword.errors.append("old password is incorrect!")
            else:
                query = "UPDATE users SET password = '******' WHERE uname = '{}'".format(
                    new_password, current_user.uname)
                db.session.execute(query)
                db.session.commit()
                form.confirmPassword.errors.append("password updated!")
                form.oldPassword.data = ''
                form.newPassword.data = ''
                form.confirmPassword.data = ''
    return render_template("admin_profile_change_password.html",
                           username=current_user.uname,
                           form=form)
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
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})
Exemplo n.º 12
0
def recover_password(token):
    s = URLSafeSerializer(app.config['SECRET_KEY'])
    try:
        token_data = s.loads(token)
    except BadSignature:
        flash('Failed to validate token.')
        return redirect(url_for('index'))
    if token_data['time'] + 600 < int(time.time()):
        flash('That link has expired')
        return redirect(url_for('forgot'))
    form = ChangePasswordForm()
    if form.validate_on_submit():
        try:
            user = User.get(User.email == token_data['email'])
        except User.DoesNotExist:
            flash('That user does not exist.')
            return redirect(url_for('index'))
        user.password = generate_password_hash(form.password.data)
        user.save()
        flash('Your password has been updated.')
        return redirect(url_for('login'))
    else:
        return render_template(
            'recover_password.html',
            form=form,
            token_data=token_data,
            token=token,
        )
Exemplo n.º 13
0
def change_password():
    form = ChangePasswordForm()

    if form.validate_on_submit():
        old_password = form.password.data
        new_password = form.new_password.data
        cfm_password = form.confirm_password.data

        user = User.query.filter_by(user_id=current_user.user_id,
                                    password=old_password).first()

        if user is not None:
            if new_password == cfm_password:
                # update admin password
                insertSql = "UPDATE users SET password = :password WHERE user_id = :id"
                insertParams = {
                    "password": new_password,
                    "id": current_user.user_id
                }
                db.engine.execute(text(insertSql), insertParams)

                flash('Password changed successful!', 'success')
            else:
                flash('New Password and Confirm Password not match!')
        else:
            flash('incorrect password. please try again!')

    return render_template('change-password.html',
                           auth=current_user,
                           form=form,
                           active='password')
Exemplo n.º 14
0
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))
Exemplo n.º 15
0
def changePassword():
    """
    Change the users password
    """
    form2 = ChangePasswordForm()
    email = form2.email.data
    if form2.validate_on_submit():

        # check whether employee exists in the database and whether
        user = User.query.filter_by(email=email).first()
        if user is not None:
            user = User.query.filter_by(email=email).first_or_404()

            user.password_hash = generate_password_hash(form2.password.data)
            db.session.commit()

            flash(
                'You have successfully changed your password! You may now login.'
            )
            return redirect(url_for('auth.login'))
        # when email doesn't exist
        else:
            flash('Invalid email')

    return render_template('auth/change-password-email.html',
                           form=form2,
                           title='Change Password')
Exemplo n.º 16
0
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,
    })
Exemplo n.º 17
0
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})
Exemplo n.º 18
0
def home():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        authResult = authenticateTACACS(form.username.data, form.password.data)
        if "status: FAIL" in str(authResult):
            form.errors.update({'generalErrors': ["Wrong username/password"]})
        else:
            if (form.newPassword.data != form.confirmNewPassword.data):
                form.errors.update(
                    {'generalErrors': ["New password fields don't match"]})
            else:
                userID = getUserID(form.username.data)
                result = changePassword(userID, form.username.data,
                                        form.newPassword.data)
                if result != "OK":
                    form.errors.update({'generalErrors': [result]})
                else:
                    form.errors.update({
                        'messages':
                        ["Password has been successsfully updated"]
                    })

    else:
        print(form.errors)
    return render_template("template.html", form=form)
Exemplo n.º 19
0
def render_student_change_password():
    if session['is_admin']:
        return redirect("/admin_panel")
    query = "SELECT si.rname, s.bid_point FROM student s NATURAL JOIN studentinfo si WHERE s.uname = '{}'".format(
        current_user.uname)
    real_name, bid_point = db.session.execute(query).fetchone()
    form = ChangePasswordForm()
    if form.validate_on_submit():
        old_password = form.oldPassword.data
        new_password = form.newPassword.data
        confirm_password = form.confirmPassword.data
        if new_password != confirm_password:
            form.confirmPassword.errors.append(
                "newPassword must be the same as the confirmPassword!")
        else:
            query = "SELECT password FROM users WHERE uname = '{}'".format(
                current_user.uname)
            password = db.session.execute(query).fetchone()[0]
            if password != old_password:
                form.oldPassword.errors.append("old password is incorrect!")
            else:
                query = "UPDATE users SET password = '******' WHERE uname = '{}'".format(
                    new_password, current_user.uname)
                db.session.execute(query)
                db.session.commit()
                form.confirmPassword.errors.append("password updated!")
    return render_template("student_profile_change_password.html",
                           username=real_name,
                           bid_point=bid_point,
                           form=form)
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
def change_password():
    """Change user's password."""

    form = ChangePasswordForm()

    if form.validate_on_submit() and User.authenticate(
            g.user.username, form.current_password.data):
        data = {
            'new_password': form.new_password.data,
            'new_password_confirmed': form.new_password_confirmed.data
        }
        if g.user.change_password(**data):
            g.user.change_password(**data)
            db.session.commit()
            flash("Password changed!", "success")
            return redirect(url_for('profile'))
        else:
            flash("Invalid password", "danger")
            return render_template('users/change_password.html',
                                   form=form,
                                   user=g.user)
    else:
        return render_template('users/change_password.html',
                               form=form,
                               user=g.user)
Exemplo n.º 22
0
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 == '*****@*****.**':
          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)) 
Exemplo n.º 23
0
def change_password(username):

    # Make sure the logged in user is the authorized user to view this page.
    if "username" not in session or username != session['username']:
        raise Unauthorized()

    user = User.query.filter_by(username=username).first()

    user_id = user.id

    form = ChangePasswordForm()

    if form.validate_on_submit():
        current_password = form.current_password.data
        new_password = form.new_password.data

        # If user's current password is true, update password.
        if User.change_password(user_id, current_password, new_password):
            User.change_password(user_id, current_password, new_password)
            flash("Password updated.", "success")
            return redirect('/')
        else:
            flash("Incorrect Password.", "danger")
            return render_template('/user/change_password.html', form=form)
    else:
        return render_template('/user/change_password.html', form=form)
Exemplo n.º 24
0
    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')
Exemplo n.º 25
0
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)
Exemplo n.º 26
0
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'))
Exemplo n.º 27
0
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'))
Exemplo n.º 28
0
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)
Exemplo n.º 29
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        current_user.password = form.password.data
        db.session.add(current_user)
        db.session.commit()
        flash('Password changed successfully', 'success')
        return redirect(url_for('.index', name=current_user.name))
    return render_template('user/change_password.html', form=form)
Exemplo n.º 30
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        current_user.password = form.password.data
        db.session.add(current_user)
        db.session.commit()
        send_mail(current_user.email, 'Password was change', 'mail/change_password_mail', user = current_user)
        flash('Email about changing password has been sent to you by email.')
        return redirect(url_for('login'))
    return render_template('change_password.html', form = form)
Exemplo n.º 31
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_hash(form.current_password.data,
                                    current_user.password):
            current_user.set_password(form.new_password.data)
            current_user.save_to_db(db)

            return redirect("/profile")
    return render_template("change_password.html", form=form)
Exemplo n.º 32
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user and current_user.verify_password(
                current_user.password_hash, form.old_password.data):
            current_user.password = form.password.data
            flash(u"Change password successfully!", 'success')
            return redirect(url_for('admin.index'))
        flash(u"Old Password error!", 'error')
    return render_template('admin/change_password.html', form=form)
Exemplo n.º 33
0
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())
Exemplo n.º 34
0
def change_password():
    changePass = ChangePasswordForm()
    if changePass.validate_on_submit():
        if login_db.verify(session["username"], changePass.oldPassword.data):
            login_db.update(session["username"], changePass.newPassword.data)
            flash("pass-updated")
        else:
            flash("bad-old")
    return render_template("change_pass.html", subheading="Account Settings", message=None, changePass=changePass,
                           page="settings")
Exemplo n.º 35
0
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)
Exemplo n.º 36
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if check_password_hash(current_user.password, form.old_password.data):
            return password_change(form.new_password.data)
        else:
            flash("The old password does not match.")
    return render_template('config.html',
                           form=form,
                           config_func='login_system.change_password')
Exemplo n.º 37
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.check_password(form.old_password.data):
            current_user.password = form.password.data
            current_user.save()
            flash('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/change_password.html", form=form)
Exemplo n.º 38
0
def profile():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.current_password.data):
            current_user.password = form.new_password.data
            db.session.commit()
            flash('Your password has been updated.', 'success')
            return redirect(url_for('main.profile'))
        else:
            flash('Original password is invalid.', 'danger')
    return render_template("profile.html", form=form)
Exemplo n.º 39
0
Arquivo: views.py Projeto: iefan/kfjz
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))
Exemplo n.º 40
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.check_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("change_password.html", form=form)
Exemplo n.º 41
0
def change_password():
	form = ChangePasswordForm()
	if form.validate_on_submit():
		if current_user.verify_password(form.old_password.data):
			current_user.password = form.password.data
			db.session.add(current_user)
			flash('You password have been update','success')
			return redirect(url_for('main.index'))
		else:
			flash('Invalid password')
	return render_template('auth/change_password.html',form = form)
Exemplo n.º 42
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash('你的密码已经更改了')
            return redirect(url_for('main.index'))
        else:
            flash('密码错误')
    return render_template('auth/change_password.html', form=form)
Exemplo n.º 43
0
def change_password(user_id):
    form = ChangePasswordForm()

    if form.validate_on_submit():
        current_password = form.current_password.data
        new_password = form.new_password.data
        User.change_password(user_id, current_password, new_password)
        flash("Password updated.", "success")
        return redirect('/')
    else:
        return render_template('/users/change_password.html', form=form)
Exemplo n.º 44
0
def profile():
	form = ChangePasswordForm()
	if form.validate_on_submit():
		g.user.set_password(form.new_password.data)
		db.session.add(g.user)
		db.session.commit()
		flash('password has been changed')
		return redirect(url_for('index'))
	return render_template('profile.html',
		title='Profile',
		form=form)
Exemplo n.º 45
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.check_password(form.oldpassword.data):
            current_user.set_password(form.password.data)
            db.session.commit()
            flash('Your password has been reset.')
            return redirect(url_for('edit_profile'))
        flash('Old password incorrect', 'error')

    return render_template('change_password.html', form=form)
Exemplo n.º 46
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if check_password_hash(current_user.password, form.last_password.data):
            current_user.password = generate_password_hash(
                form.new_password1.data, method="pbkdf2:sha256", salt_length=8)
            flash("Password changed successfully.")
            db.session.commit()
        else:
            form.last_password.errors.append("Your password is invalid.")
    return render_template("chat/change_password.html", form=form)
Exemplo n.º 47
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if check_password_hash(current_user.password, form.old_password.data):
            current_user.update_password(form.new_password.data)
            db.session.commit()
            message = "Your password has been changed."
            return render_template("message.html", active_page='none', message=message)
        else:
            form.old_password.errors = ["Old password incorrect."]
    return render_template('change_password.html', active_page='none', form=form)
Exemplo n.º 48
0
def changepassword():
    
    form= ChangePasswordForm() 
    
    if form.validate_on_submit():
        user = User.query.filter_by(user_name = form.username.data).first()
        user.password=form.password.data
        db.session.merge(user)
        db.session.commit()
        
        return redirect(url_for('home'))
    return render_template('changepassword.html', form=form)
Exemplo n.º 49
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.check_password(form.current_password.data):
            current_user.password = form.new_password.data
            db.session.add(current_user)
            db.session.commit()
            flash(u'新密码已设置。', 'success')
            return redirect(url_for('.index'))
        else:
            flash(u'原密码有误,请重新输入。', 'warning')
    return render_template('settings/change-password.html', form=form)
Exemplo n.º 50
0
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))
Exemplo n.º 51
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        current_user.password = form.password.data
        current_user.password = generate_password_hash(current_user.password,
                                                       method='sha256')
        db.session.add(current_user)
        db.session.commit()
        flash('Your password has been updated.')
        return redirect(url_for('main.index'))

    return render_template("change_password.html", form=form)
Exemplo n.º 52
0
def change_password():
    '''
        application for changing the password of a user
    '''
    form = ChangePasswordForm()
    if form.validate_on_submit():
        password = request.form['password']
        functions.edit_password(password, session['id'])
        return redirect('/profile/settings/')
    return render_template('change_password.html',
                           form=form,
                           username=session['username'])
Exemplo n.º 53
0
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})
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))
Exemplo n.º 55
0
def accessrights():
    form = ChangePasswordForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=g.user.email).first()
        if user:
            user.password = bcrypt.generate_password_hash(form.password.data)
            db.session.commit()
            flash('Password successfully changed.', 'success')
            return redirect(url_for('edit'))
        else:
            flash('Password change was unsuccessful.', 'danger')
            return redirect(url_for('edit'))
    return redirect(url_for('edit'))
Exemplo n.º 56
0
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)
Exemplo n.º 57
0
def change_password():
    """Changing password """
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if form.password.data != form.retype_password.data:
            flash('Passwords are not same')
        else:
            user = current_user
            user.password = bcrypt.generate_password_hash(form.password.data)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for("logout"))
    return render_template("change_password.html", form=form)