def register(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = RegistrationForm() if form.validate_on_submit(): hashed = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed, confirmed=False) db.session.add(user) db.session.commit() session['reg_username'] = user.username token = generate_confirmation_token(form.email.data) confirm_url = url_for('users.confirm_email', token=token) html = render_template('confirmation_email.html', user=user, confirm_url=confirm_url) subject = "Welcome to Ask.it!" send_email(user.email, subject, html) flash('A confirmation email has been sent via email.', 'success') return redirect(url_for('users.tfa', user=user)) return render_template('register.html', form=form)
def register(): if current_user.is_authenticated: current_app.logger.info( "User is authenticated. Redirect to main page.") return redirect(url_for("main.index")) form = RegistrationForm() if form.validate_on_submit(): current_app.logger.info( "POST Request hit at /register and form has been validated") current_app.logger.info("Hashing password...") hashed = bcrypt.generate_password_hash( form.password.data).decode("utf-8") current_app.logger.info("Creating new user") user = User(username=form.username.data, password=hashed, interest1=form.firstInterest.data, interest2=form.secondInterest.data, interest3=form.thirdInterest.data) current_app.logger.info("Adding new user to database") db.session.add(user) db.session.commit() current_app.logger.info("Getting GIFS for User {user.username}") firstInterestGIFs = getGIFs(user.interest1) for url in firstInterestGIFs: userGIF = UserGIF(link=url, user=user) db.session.add(userGIF) secondInterestGIFs = getGIFs(user.interest2) for url in secondInterestGIFs: userGIF = UserGIF(link=url, user=user) db.session.add(userGIF) thirdInterestGIFs = getGIFs(user.interest3) for url in thirdInterestGIFs: userGIF = UserGIF(link=url, user=user) db.session.add(userGIF) db.session.commit() current_app.logger.info( "User has been added, as well as their GIF Interests. Redirect to login page." ) #return redirect(url_for("users.login")) session['reg_username'] = user.username return redirect(url_for('users.tfa')) return render_template("register.html", title="Register", form=form)
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) db.session.add(user) db.session.commit() #pass a one time message to front end, category is success flash('Your account have now been created, you are now able to login', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = RegistrationForm() if form.validate_on_submit(): hashed = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed) db.session.add(user) db.session.commit() return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)