From c8d56b5e1e46af34b1f16402e45c042395821d4c Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Fri, 4 Oct 2019 23:29:43 -0700 Subject: [PATCH] register auth blueprint --- app.py | 3 ++- auth/auth.py | 6 +++--- models/User.py | 34 +++++++++++++++++----------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app.py b/app.py index a689d04..10fb0ea 100644 --- a/app.py +++ b/app.py @@ -49,9 +49,10 @@ def hello_world(): # Blue prints from api.api import api +from auth.auth import auth app.register_blueprint(api) - +app.register_blueprint(auth) if __name__ == '__main__': app.run(debug=DEBUG, port=PORT) \ No newline at end of file diff --git a/auth/auth.py b/auth/auth.py index ffee7a5..94e1723 100644 --- a/auth/auth.py +++ b/auth/auth.py @@ -1,14 +1,14 @@ from flask import Blueprint, request, jsonify, session -from ..models.User import User +import models auth = Blueprint('auth', __name__, url_prefix='/auth') -@api.route('/signup', methods=['POST']) +@auth.route('/signup', methods=['POST']) def auth_signup(): response = {"message": "signup post"} return jsonify(response) -@api.route('/login', methods=['POST']) +@auth.route('/login', methods=['POST']) def auth_login(): response = {"message": "login post"} return jsonify(response) \ No newline at end of file diff --git a/models/User.py b/models/User.py index 4ae7c17..b71c9c6 100644 --- a/models/User.py +++ b/models/User.py @@ -64,23 +64,23 @@ class User(db.Model): self.admin = admin def encode_auth_token(self, user_id): - """ - Generates the Auth Token - :return: string - """ - try: - payload = { - 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=0, seconds=5), - 'iat': datetime.datetime.utcnow(), - 'sub': user_id - } - return jwt.encode( - payload, - app.config.get('SECRET_KEY'), - algorithm='HS256' - ) - except Exception as e: - return e + """ + Generates the Auth Token + :return: string + """ + try: + payload = { + 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=0, seconds=5), + 'iat': datetime.datetime.utcnow(), + 'sub': user_id + } + return jwt.encode( + payload, + app.config.get('SECRET_KEY'), + algorithm='HS256' + ) + except Exception as e: + return e @staticmethod def decode_auth_token(auth_token):