def change_password(): form = ChangePassword() if current_user.is_authenticated: user = User.query.filter_by(username=current_user.username).first() if form.validate_on_submit(): user.set_password(form.password.data) user.password_reset_key = "" db.session.commit() flash('Password succesfully updated') return redirect(url_for('index')) return render_template('change_password.html', title='Change Password', form=form) else: user = User.query.filter_by( password_reset_key=request.args.get("key")).first() if user is not None and request.args.get("key") != "": if form.validate_on_submit(): user.set_password(form.password.data) user.password_reset_key = "" db.session.commit() flash('Password succesfully updated') return redirect(url_for('login')) return render_template('change_password.html', title='Change Password', form=form) else: return render_template('404.html')
def account(): if not current_user.is_authenticated: return render_template('error-page.html', title='Error') password_form = ChangePassword() message = None if request.method == 'POST': if password_form.validate_on_submit(): if not bcrypt.check_password_hash(current_user.password, password_form.old_password.data): message = 'Incorrect password.' return render_template('account.html', title='Account', user_data=current_user, password_form=password_form, message=message) user = User.query.get(current_user.id) user.password = bcrypt.generate_password_hash( password_form.new_password.data).decode('utf-8') db.session.commit() return redirect(url_for('index')) return render_template('account.html', title='Account', user_data=current_user, password_form=password_form, message=message)
def account(): num_entries = func.count(Entry.id).label('num_entries') day = func.strftime('%m/%d/%Y', Entry.created_on).label('day') # Get a count of all top level entries # by the current user, and the date of # the first entry. my_entries = db.session.query(num_entries, day).filter_by( user_id=current_user.get_id(), parent_id=0, entry_type=0).order_by(Entry.created_on.asc()).first() form = ChangePassword() # We validate the form and make sure it was # the change-password form that was submitted if form.validate_on_submit() and (request.form.get('form_id') == 'change-password'): current_user.password = generate_password_hash( request.form.get('password'), method='sha256') db.session.commit() flash('Password updated') return render_template('account.html', title='Your Account', my_entries=my_entries, form=form)
def change_password(): form = ChangePassword() if form.validate_on_submit(): password = current_user.password_hash user = User.query.filter(User.password_hash == password).first() user.password_hash = form.new_password.data db.session.add(user) flash("密码已经被修改") return redirect(url_for("main.index")) return render_template("user/change_password.html", form=form)
def change_password(): form = ChangePassword() if form.validate_on_submit(): user = User.query.filter_by(username=current_user.username).first() if user is None or not user.check_password(form.password.data): flash('invalid password') return redirect(url_for('change_password')) user.set_password(form.new_password.data) db.session.commit() flash('password changed') return redirect(url_for('edit_profile')) return render_template('change_password.html', form=form)
def changepassword(): form = ChangePassword() u = User.query.filter_by(username=current_user.username).first() password = form.password.data if form.validate_on_submit(): if u.verify_password(password): flash('密码修改成功') u.password = form.newPassword.data db.session.commit() return redirect(url_for('user.changepassword')) else: flash('原密码错误') return render_template('user/changepassword.html', form=form)
def change_password(): form = ChangePassword() if form.validate_on_submit(): user = current_user if bcrypt.check_password_hash(user.password, form.password.data): hashed_password = bcrypt.generate_password_hash( form.new_password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash('Deine Änderungen wurden gespeichert!', 'success') return redirect(url_for('mgb')) else: flash('Das Passwort ist falsch.', 'no-success') return render_template('pages/change_password.html', title='Account bearbeiten', form=form)
def change_password(): form = ChangePassword() if form.validate_on_submit(): change = change_user_password(form, current_user.username) if change == False: flash('Invalid Current Password') return redirect(url_for('change_password')) elif change == True: flash('Your new password should be different from the current one') return redirect(url_for('change_password')) else: flash(change) return redirect(url_for('logout')) return render_template('change_password.html', title='Change Password', form=form)
def change_password(): """ The endpoint that helps the user to change his password """ form = ChangePassword() if form.validate_on_submit(): if current_user.check_password(form.old_password.data): current_user.set_password(form.new_password.data) db.session.commit() flash("Your changes have been saved.") return redirect(url_for('change_password')) flash("Old password isn't valid") return redirect(url_for('change_password')) return render_template('change_password.html', title='Edit Password', form=ChangePassword())
def change_password(): if not current_user.is_authenticated: return (redirect(url_for('proute.index'))) contributor = Contributor.query.get(current_user.id) form = ChangePassword() if form.validate_on_submit(): if contributor.check_password(form.password.data): contributor.set_password(form.new_password.data) db.session.commit() flash("Thanks for the update!") return (redirect(url_for('proute.index'))) else: flash("Error Invalid Password") return (redirect(url_for('prof.change_password'))) return render_template('change_password.html', title='Change Password', form=form)
def post(self): form = UpdatePasswordForm(request.form) if form.validate(): old_pass = form.current_password.data new_pass = form.new_password.data account = session_util.get_account() if account.check_password(old_pass): account.set_password(new_pass) account.save() flash("New password saved", 'success') else: # flash("That's not your current password.", 'error') form.current_password.errors.append( "That's not your current password.") return self.render_template(form=form)
def change_password(): if not authorize(): return redirect('/User/SignIn') form = ChangePassword() row = get_user() if form.validate_on_submit(): old_pwd, new_pwd = form.old_password.data, form.password.data if check_password_hash(row["PasswordHash"], old_pwd): with db.cursor() as cursor: cursor.execute( "UPDATE User " "SET PasswordHash = %s " "WHERE UserId = %s", (generate_password_hash(new_pwd), row["UserId"])) db.commit() flash('Mise à jour du mot de passe réussie') return redirect('/') flash('Mot de passe actuel incorrect') return View('change_password.html', title='Modifier son mot de passe', form=form)