def register(): if current_user.is_authenticated: return redirect(url_for('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, firstName=form.firstName.data, address=form.address.data ,email=form.email.data, password=hashed_password) 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('login')) return render_template('register.html', title='Register', form=form)
def setUp(self): # this gets called before every test so there's always the same data for the program to test db.session.commit() db.drop_all() db.create_all() # this ensures that the databse is completely empty by destroying and rebuilding it hashed_pw = bcrypt.generate_password_hash("admin") admin = Users(first_name="admin", last_name="admin", email="*****@*****.**", password=hashed_pw) # creates the first (admin) test user hashed_pw_2 = bcrypt.generate_password_hash("password") avguser = Users(first_name="test", last_name="user", email="*****@*****.**", password=hashed_pw_2) # creates the second (non-admin) test user db.session.add(admin) db.session.add(avguser) db.session.commit()
def reset_token(token): user = User.verify_reset_token(token) if user is None: flash('The reset token you are using is invalid or expired.') return redirect(url_for('password_retrieval')) 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('Password has been updated.', 'success') return redirect(url_for('login')) return render_template('reset_token.html', title='Reset Password', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for("home")) form = RegistrationForm() if form.validate_on_submit(): hash_pw = bcrypt.generate_password_hash(form.password.data) user = Users(email=form.email.data, password=hash_pw, first_name=form.first_name.data, last_name=form.last_name.data) db.session.add(user) db.session.commit() return redirect(url_for("home")) return render_template("register.html", title="Register", form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('game')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') # encrypt password user = User(username=form.username.data, email=form.email.data, password=hashed_password, games_won=0) # create object db.session.add(user) # add to db db.session.commit() # update db flash('Account creation succesful!', 'success') # notify user return redirect(url_for('login')) # so you user can now log in return render_template('register.html', title='Register', form=form)