def register(): ''' Register endpoint ''' if current_user.is_authenticated: return redirect(url_for('index')) form_login = LoginForm() form_register = RegisterForm() if form_register.validate_on_submit(): query_email = DB.session.query(User.id).filter_by( email=form_register.email.data).scalar() is not None query_user = DB.session.query(User.id).filter_by( username=form_register.username.data).scalar() is not None if not query_email and not query_user: hashed_password = generate_password_hash( form_register.password.data, method='sha256') new = User(username=form_register.username.data, password=hashed_password, email=form_register.email.data) DB.session.add(new) DB.session.commit() return redirect(url_for('login')) else: flash('Username or Email already exist') return render_template('login.html', form_login=form_login, form_register=form_register)
def register(): form = RegisterForm() if form.validate_on_submit(): db.session.add(form.user) db.session.commit() login_user(form.user) flash('You are registered successfully.', 'info') return redirect(url_for('index')) return render_template('register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): hash_password = generate_password_hash(form.password.data, method='sha256') # put data into database new_user = User(username=form.username.data, password=hash_password, email=form.email.data) datab.session.add(new_user) datab.session.commit() # redirect to login page return redirect(url_for('login')) return render_template('register.html', form=form)