예제 #1
0
def register_account_token(token):
    user = User.verify_reset_token(token)
    if not user or user.active:
        flash('That is an invalid or an expired token.', 'warning')
        return redirect(url_for('auth.reset_password'))

    user.active = True
    user.activated_on = datetime.utcnow()
    db.session.commit()
    app.logger.info('[INFO] - [{}] Account activated'.format(user.id))
    flash('Your account has been activated.', 'success')

    return redirect(url_for('auth.home'))
예제 #2
0
def email_update_token(token):
    user = User.verify_reset_token(token)

    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('auth.home'))

    if user.id != current_user.id:
        return redirect(url_for('auth.home'))

    old_email = user.email
    user.email = user.transition_email
    user.transition_email = None

    db.session.commit()
    app.logger.info('[{}] Email successfully changed from {} to {}'.format(
        user.id, old_email, user.email))
    flash('Email successfully updated!', 'success')

    return redirect(url_for('auth.home'))
예제 #3
0
def reset_password_token(token):
    user = User.verify_reset_token(token)
    if not user:
        flash('That is an invalid or an expired token.', 'warning')
        return redirect(url_for('auth.reset_password'))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        app.logger.info(
            '[INFO] - [{}] Password reset via reset password email.'.format(
                user.id))
        flash('Your password has been updated! You are now able to log in.',
              'success')
        return redirect(url_for('auth.home'))

    return render_template('reset_password_token.html',
                           title='Reset Password',
                           form=form)