Example #1
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_email(form.old_email.data):
            current_user.email = form.email.data
            db.session.add(current_user)
            flash('您的邮箱已经修改!')
            return redirect(url_for('main.index'))
        else:
            flash('原邮箱错误,操作无效!')
    return render_template('user/change_email.html', form=form)
Example #2
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        user = User.query.filter(User.username == current_user.username).first()
        if user.verify_password(form.password.data):
            current_user.email = form.email.data
            db.session.add(current_user)
            flash("修改成功")
            return redirect(url_for("users.information"))
        else:
            flash('用户名或密码输入错误')
    return render_template('user/change_email.html', form=form)
Example #3
0
def profile():
    form = ChangeEmailForm()
    form.email.data = current_user.email
    context = {
        'form': form
    }
    if form.validate_on_submit():  # need hidden field
        current_user.email = request.form.get('email')
        db.session.commit()
        flash('Email has been updated!', 'success')
        return redirect(url_for('profile'))

    return render_template('profile.html', **context)
Example #4
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       u'确认您的邮箱',
                       'change_email',
                       user=current_user,
                       token=token)
            flash(u'一封带有确认链接的邮件已经发往您的新邮箱,请查阅确认.')
            return redirect(url_for('index'))
        else:
            flash(u'无效的邮箱或密码')
    return render_template("change_email0.html", form=form)