Esempio n. 1
0
def change_password():
    logger.warning(f'{session["username"]} change password.')
    form = ChangePasswordForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User.query.filter_by(id=session['user_id']).first()
        if user.verify_password(form.old_password.data):
            user.password = form.new_password.data
            flash('change password success', 'alert-success')
            return redirect('auth.logout')
        flash('wrong old password', 'alert-danger')
    return render_template('change_password.html', form=form)
Esempio n. 2
0
def change_password():
    form = ChangePasswordForm()
    newpassword = form.newpassword.data
    if form.validate():
        if current_user.verify_password(password=form.oldpassword.data):
            current_user.password = newpassword
            db.session.add(current_user)
            db.session.commit()
            flash('密码修改成功')
            return redirect(url_for('main.index'))
        else:
            flash('修改失败')
    return render_template('users/change_password.html',form=form)
Esempio n. 3
0
    def settings(self):
        user = User.query.get(g.user.id)
        form = ChangePasswordForm(request.form)

        if request.method == 'POST' and form.validate():
            try:
                user.set_password(form.password.data)
                user.active = False
                db.session.commit()
            except Exception:
                flash('0Error setting password')
                return redirect(url_for('UserView:settings'))

            flash(
                '1Password set successfully! Please login with the new password.')
            session.pop('user_id')
            return redirect(url_for('UserView:login', next=url_for('UserView:settings')))

        helpers.flash_errors(form)
        return render_template('edit_user.html',
                               title='::Settings',
                               user=user,
                               form=form,
                               )