コード例 #1
0
def email_verification(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    user = User.verify_token(token, timed=False)
    if user is None:
        flash('The token is invalid.', 'warning')
        return redirect_next_page()
    #submit user details to db
    user.verified = True
    db.session.commit()
    #make a account activated page
    return _render_template('accounts/account_activated.html')
コード例 #2
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_token(token, timed=True)
    if user is None:
        flash('The token is invalid or has expired.', 'warning')
        return redirect_next_page()

    reset_password_form = ResetPasswordForm()
    if request.method == "POST":
        if reset_password_form.validate_on_submit():
            print('reset form submitted')
            hashed_password = bcrypt.generate_password_hash(
                reset_password_form.password.data).decode('utf-8')
            user.password = hashed_password
            db.session.commit()
            flash('Password has been updated!', 'success')
            #redirect does not work with ajax, so instead return json then use js to switch url
            return redirect_json(route="main.home")
        else:
            return form_errors_400(reset_password_form)
    return _render_template('accounts/reset_password.html')