Ejemplo n.º 1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password, role="Pending")
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('user/register_wtf.html', title='Register', form=form)
Ejemplo n.º 2
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    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()
        flash('Your password has been updated! You are now able to log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('user/reset_token.html', title='Reset Password', form=form)
Ejemplo n.º 3
0
from approot import create_app, db, bcrypt
from approot.models import User, Post, Expense

app = create_app()

db.app = app
db.drop_all()
db.create_all()

user = User()

user.username = '******'
user.email = '*****@*****.**'
user.role = 'Admin'
hashed_password = bcrypt.generate_password_hash("adminpassword").decode(
    'utf-8')

user.password = hashed_password

db.session.add(user)
db.session.commit()