def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): # hash the password they created in the form hashed_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') # initialize the user, using the hashed password, not what they entered user = User(username=form.username.data, email=form.email.data, password=hashed_pw) # database commands to insert the user object and commit changes db.session.add(user) db.session.commit() # flash success message flash(f'Account created for {form.username.data}!', 'success') # redirect to login screen return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): 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) db.session.add(user) db.session.commit() flash(f'Account created for { form.username.data}!', 'success') return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) 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) 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 register(): if current_user.is_authenticated: # if the user is already logged in return redirect(url_for('main.home')) form = RegistrationForm() if request.method == "POST" and form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode( 'utf-8') # hash the password the user enters into the website user = User(fname=form.fname.data, lname=form.lname.data, student_id=form.student_id.data, email=form.email.data, password=hashed_password ) # adds the users data into the variable user db.session.add(user) # adds the users data to the database db.session.commit() flash('account created ', 'success') return redirect(url_for( 'users.login')) # redirect to home one user session is done return render_template("register.html", title="Register", form=form)
def reset_token(token): if current_user.is_authenticated: # if the current user is logged in return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: # if there is no flash('That is an invalid or expired token', 'text-warning') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if request.method == "POST" and form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode( 'utf-8') # hash the password the user enters into the website user.password = hashed_password db.session.commit() flash('your password has been changed', 'success') return redirect(url_for( 'users.login')) # redirect to home one user session is done return render_template('reset_token.html', title='reset_password', form=form)