Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>
Add routes and basic stuff for sign up and log in
src/__init__.py | 1 src/blueprints/auth.py | 46 ++++++++++++++++++++++++++++++++++++-------
diff --git a/src/__init__.py b/src/__init__.py index dc94a10d80692f62c5796298a8052a87368417b3..bea7a030950589d5fcc8cb20efe6a5a4faff47af 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -5,6 +5,7 @@ def create_app(): app = Flask(__name__) # Database + app.config['SECRET'] = '123456asckjnsac' app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost/ciclos_dev' from .types import db diff --git a/src/blueprints/auth.py b/src/blueprints/auth.py index 66327d4ff1a44976d6c4389fa590827174e19f24..5e39bf462bd4cead168db77f7234f15f2ee0cf0f 100644 --- a/src/blueprints/auth.py +++ b/src/blueprints/auth.py @@ -1,13 +1,43 @@ -from flask import Blueprint, render_template, jsonify +from flask import Blueprint, render_template, url_for, redirect from ..types.user import User +from werkzeug.security import generate_password_hash auth = Blueprint('auth', __name__, url_prefix = "/auth") -@auth.route('/') -def index(): - us = User.query.all() - users = [] - for usr in us: - users.append(usr.as_dict()) +@auth.route('/login', methods = ['GET', 'POST']) +def login(): + if request.method == 'GET': + return render_template('login.html', title = "Entrar - Feira Virtual Bem da Terra") + else: + return 'work' - return jsonify(users) +@auth.route('/sign_up', methods = ['GET', 'POST']) +def sign_up(): + if request.method == 'GET': + return render_template('sign_up.html', title = "Cadastrar - Feira Virtual Bem da Terra") + else: + email = request.form.get('email') + user = User.query.filter_by(email = email).first() + + if user: + # flash('You already have an account, perhaps log in?') + return redirect(url_for('auth.login')) + else: + username = request.form.get('username') + password = request.form.get('password') + first_name = request.form.get('first_name') + last_name = request.form.get('last_name') + + new_user = User( + username, + email, + generate_password_hash(password, method = 'sha256'), + first_name, + last_name + ) + + new_user.create() + + # flash('Account created successfully') + return redirect(url_for('auth.login')) +