def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hased_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username= form.username.data, email = form.email.data, password = hased_password) db.session.add(user) db.session.commit() flash(f'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: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): # generate password hash and create user 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('Account created !', 'success') return redirect(url_for('login')) return render_template("register.html", title="Register", form=form)
def register(): # Uses the Flask-login extension function that knows if a use has logged # in yet. if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): # Hash the password of the user. hash_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') # Create the user object with the given input from the form. user = User(username=form.username.data, email=form.email.data, password=hash_pw) # Add the user to the database. db.session.add(user) db.session.commit() # Display the a flash message flash(f'Account created for {form.username.data}, Try logging in!', 'success') # Redirect the user to the login. return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)