def register(): form = RegistrationForm() #hidden_tag(): Adds Cross Site Request Forgery Token if form.validate_on_submit(): flash(f'Account Created for {form.username.data}.', 'success') return redirect( url_for('home') ) #url_for takes the name of method like home, register, login not html page return render_template('register.html', title='Signup', form=form)
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, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f'Account created for {form.username.data},You can login now.') return redirect(url_for("login")) return render_template('register.html', title="register", form=form)
def register(): if current_user.is_authenticated: # this will check current user authenticated and re direct to home page if user logged in and click on register button 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, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f'Account created for {form.username.data} !!!', '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('homepage')) form = RegistrationForm() if form.validate_on_submit(): h_pass = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=h_pass) db.session.add(user) db.session.commit() flash('Account created for {}'.format(form.username.data), 'success') ### changed lates return redirect(url_for('login')) return render_template('register.html', title="Register", form=form)