def registration_page(): """ Enables new user registration.""" user_data = request.form form = UserRegForm(user_data) if form.validate_on_submit(): existing_user = UserRegistration.objects(email=form.email.data).first() if existing_user is None: form.populate_obj(UserRegistration) add_user_to_db = UserRegistration.save() login_user(add_user_to_db, remember=True) flash('You are now registered and can login in', 'success') return redirect(url_for('dashboard')) return render_template('home/register.html', form=form)
def registration_page(): user_data = request.form form = UserRegForm(user_data) if request.method == 'POST': existing_user = UserRegistration.objects(email=form.email.data).first() if existing_user is None: # hashpass = generate_password_hash(form.password.data, method='sha256') add_user_to_db = UserRegistration(form.firstName.data, form.lastName.data, form.address.data, form.city.data, form.email.data, form.password.data, form.confirm.data).save() login_user(add_user_to_db, remember=True) flash('You are now registered and can login in', 'success') return redirect(url_for('dashboard')) return render_template('register.html', form=form)
def login(): if current_user.is_authenticated == True: return redirect(url_for('dashboard')) user_data = request.form form = UserLoginForm(user_data) if request.method == 'POST': check_user = UserRegistration.objects(email=form.email.data).first() if check_user: if check_user['password'] == form.password.data: login_user(check_user) return redirect(url_for('dashboard')) return render_template('login.html')
def login(): """ Returns: Returns logged in user to dashboard. """ if current_user.is_authenticated: return redirect(url_for('dashboard')) user_data = request.form form = UserLoginForm(user_data) if form.validate_on_submit(): check_user = UserRegistration.objects(email=form.email.data).first() if check_user: if check_user['password'] == form.password.data: login_user(check_user) return redirect(url_for('dashboard')) return render_template('home/login.html')
def dashboard(): form = UserRegistration() name = form.firstName print(name) user = current_user return render_template('dashboard.html')
def load_user(user_id): return UserRegistration.objects(pk=user_id).first()