Пример #1
0
def change_email(token):
    if validate_token(user=current_user, token=token, operation=Operations.CHANGE_EMAIL):
        flash('邮箱已更新。', 'success')
        return redirect(url_for('.index', username=current_user.username))
    else:
        flash('无效或者过时的令牌', 'warning')
        return redirect(url_for('.change_email_request'))
Пример #2
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is None:
            return redirect(url_for('main.index'))
        if validate_token(user=user,
                          token=token,
                          operation=Operations.RESET_PASSWORD,
                          new_password=form.password.data):
            flash('密码已更新', 'success')
            form.email.data = ""
            return redirect(url_for('.login'))
        else:
            flash('链接无效或者超时。', 'danger')
            return redirect(url_for('.forget_password'))
    return render_template('auth/reset_password.html', form=form)