mirror of
https://github.com/Xevion/runnerspace.git
synced 2025-12-15 16:12:58 -06:00
added auth for email signups
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
from flask import Blueprint
|
from flask import Blueprint, render_template, redirect, url_for, request
|
||||||
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
from .models import User
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
auth = Blueprint('auth', __name__)
|
auth = Blueprint('auth', __name__)
|
||||||
@@ -10,14 +12,40 @@ as right now `login`, `signup`, and `logout` only return text
|
|||||||
There will also be routes for handling POST requests from login and signup
|
There will also be routes for handling POST requests from login and signup
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
@auth.route('/login')
|
@auth.route('/login')
|
||||||
def login():
|
def login():
|
||||||
return 'Login'
|
# return render_template('login.html')
|
||||||
|
return 'Login' # placeholder
|
||||||
|
|
||||||
|
|
||||||
@auth.route('/signup')
|
@auth.route('/signup')
|
||||||
def signup():
|
def signup():
|
||||||
return 'Signup'
|
# return render_template('signup.html')
|
||||||
|
return 'Signup' # placeholder
|
||||||
|
|
||||||
|
|
||||||
|
@auth.route('/signup', methods=['POST'])
|
||||||
|
def signup_post():
|
||||||
|
# validate and add user to db
|
||||||
|
email = request.form.get('email')
|
||||||
|
name = request.form.get('name')
|
||||||
|
password = request.form.get('password')
|
||||||
|
|
||||||
|
user = User.query.filter_by(email=email).first() # Check if the email exists
|
||||||
|
if user: # redirect back to sign-up page
|
||||||
|
return(redirect(url_for('auth.signup')))
|
||||||
|
|
||||||
|
# Create new user with form data
|
||||||
|
new_user = User(email=email, name=name, password=generate_password_hash(password, method='sha256'))
|
||||||
|
|
||||||
|
# Add new user to db
|
||||||
|
db.session.add(new_user)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return redirect(url_for('auth.login'))
|
||||||
|
|
||||||
|
|
||||||
@auth.route('/logout')
|
@auth.route('/logout')
|
||||||
def logout():
|
def logout():
|
||||||
return 'Logout'
|
return 'Logout' # placeholder
|
||||||
|
|||||||
Reference in New Issue
Block a user