Exemple #1
0
def change_password():
    form = ChangePasswordForm(request.form)
    if request.method == 'POST' and form.validate():
        current_user.password = form.new_password1.data
        db.session.commit()
        flash('密码已更新成功')
        return redirect(url_for('web.personal'))
    return render_template('auth/change_password.html', form=form)
Exemple #2
0
def change_password():
    '''处理修改密码页面。'''
    form = ChangePasswordForm(request.form)
    if request.method == 'POST' and form.validate():
        with db.auto_commit():
            current_user.password = form.new_password1.data
        flash('密码已更新成功')
        return redirect(url_for('web.personal_center'))
    return render_template('auth/change_password.html', form=form)
Exemple #3
0
def change_password():
    wtform = ChangePasswordForm(request.form)

    if request.method == 'POST' and wtform.validate():
        user = User.query.get_or_404(current_user.id)
        if user.check_password(wtform.old_password.data):
            user.change_password(wtform.new_password1.data)
            return redirect(url_for('web.login'))

    return render_template('auth/change_password.html')
Exemple #4
0
def change_password():
    form = ChangePasswordForm(request.form)

    if request.method == 'POST' and form.validate():
        if current_user.check_password(form.old_password.data):
            current_user.change_password(form.password1.data)
            flash('您的密码已重置,请使用新密码登录')
            return redirect(url_for('web.login'))
        flash('密码更改失败')
    return render_template('auth/change_password.html')
Exemple #5
0
def change_password():
    form = ChangePasswordForm(request.form)
    if request.method == 'POST' and form.validate():
        if current_user.check_password(form.old_password.data):
            with db.auto_commit():
                current_user.password = form.new_password1.data
                return redirect(url_for('web.login'))
        else:
            flash('您的原密码输入错误,请重新输入')
    return render_template('auth/change_password.html', form=form)
Exemple #6
0
def change_password():
    # 只能由root用户修改密码
    form = ChangePasswordForm(request)
    if request.method == 'POST' and form.validate() and current_user.username == 'root':
        with db.auto_commit():
            user = User.query.filter_by(username=form.username.data).first()
            user.password = form.new_password1.data
        flash('密码已更新成功,请联系管理员重新激活账户')
        return redirect(url_for('web.login'))
    return render_template('auth/change_password.html', form=form)
Exemple #7
0
def change_password():
    form = ChangePasswordForm(request.form)
    if request.method == 'POST' and form.validate():
        if current_user.check_password(form.old_password.data):
            with db.auto_commit():
                current_user.password = form.new_password1.data
                flash('密码修改成功')
                return redirect(url_for('web.personal_center'))
        else:
            flash('原密码有误')
    return render_template('auth/change_password.html', form=form)
Exemple #8
0
def change_password():
    form = ChangePasswordForm(request.form)
    if request.method == 'POST' and form.validate():
        current_user.password = form.new_password1.data
        db.session.commit()
        # 查看 flash 和 get_flashed_messages 你就会发现,
        # 其实 flask message flashing 功能是基于一个名字叫做 session 的 cookie 实现的
        # 无状态 HTTP 请求如何解决 上次请求和本次请求的关联:
        # 就是把上次请求产生的结果回传到用户 cookie 中,
        # 然后下次用户请求是带上这个 cookie,从而实现两个请求的关联
        flash('密码已更新成功')
        return redirect(url_for('web.personal_center'))
    return render_template('auth/change_password.html', form=form)
Exemple #9
0
def change_password():
    form = ChangePasswordForm(request.form)
    if request.method == "POST" and form.validate():
        user = User.query.get(current_user.id)
        isSuccess = False
        if user and user.check_password(form.data["oldPassword"]):
            isSuccess = user.change_password(form.data["password1"])
        if isSuccess:
            flash("密码已经更新,请使用新密码登录")
            logout_user()
            return redirect(url_for("web.login"))
        else:
            flash("重置密码失败,请重新尝试")
    return render_template("auth/change_password.html", form=form)
Exemple #10
0
def change_password():
    form = ChangePasswordForm(request.form)
    if form.old_password.data == form.new_password1.data:
        flash('新密码与旧密码一致, 请确认后重新输入')
    else:
        if request.method == 'POST' and form.validate():
            success = current_user.check_password(form.old_password.data)
            if success:
                with db.auto_commit():
                    current_user.password = form.new_password1.data
                flash('你的密码已修改, 请使用新密码登录')
                return redirect(url_for('web.login'))
            else:
                flash('原密码输入有误')
    return render_template('auth/change_password.html', form=form)
Exemple #11
0
def change_password():
    form = ChangePasswordForm(request.form)
    if request.method == 'POST':
        if form.validate():
            user = User.query.filter_by(id=current_user.id).first_or_404()
            # old_password = form.old_password.data
            success = user.check_password(form.old_password.data)
            if success:
                with db.auto_commit():
                    user.password = form.new_password1.data
                    db.session.add(user)
                    flash('你的密码已修改, 请使用新密码登录')
                return redirect(url_for('web.login'))
            else:
                flash('密码修改失败, 原密码输入有误')
    return render_template('auth/change_password.html')
Exemple #12
0
from flask import render_template, request, redirect, url_for, flash, current_app