register auth blueprint

This commit is contained in:
Sorrel Bri 2019-10-04 23:29:43 -07:00
parent 75f244ae9f
commit c8d56b5e1e
3 changed files with 22 additions and 21 deletions

3
app.py
View file

@ -49,9 +49,10 @@ def hello_world():
# Blue prints # Blue prints
from api.api import api from api.api import api
from auth.auth import auth
app.register_blueprint(api) app.register_blueprint(api)
app.register_blueprint(auth)
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=DEBUG, port=PORT) app.run(debug=DEBUG, port=PORT)

View file

@ -1,14 +1,14 @@
from flask import Blueprint, request, jsonify, session from flask import Blueprint, request, jsonify, session
from ..models.User import User import models
auth = Blueprint('auth', __name__, url_prefix='/auth') auth = Blueprint('auth', __name__, url_prefix='/auth')
@api.route('/signup', methods=['POST']) @auth.route('/signup', methods=['POST'])
def auth_signup(): def auth_signup():
response = {"message": "signup post"} response = {"message": "signup post"}
return jsonify(response) return jsonify(response)
@api.route('/login', methods=['POST']) @auth.route('/login', methods=['POST'])
def auth_login(): def auth_login():
response = {"message": "login post"} response = {"message": "login post"}
return jsonify(response) return jsonify(response)

View file

@ -64,23 +64,23 @@ class User(db.Model):
self.admin = admin self.admin = admin
def encode_auth_token(self, user_id): def encode_auth_token(self, user_id):
""" """
Generates the Auth Token Generates the Auth Token
:return: string :return: string
""" """
try: try:
payload = { payload = {
'exp': datetime.datetime.utcnow() + datetime.timedelta(days=0, seconds=5), 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=0, seconds=5),
'iat': datetime.datetime.utcnow(), 'iat': datetime.datetime.utcnow(),
'sub': user_id 'sub': user_id
} }
return jwt.encode( return jwt.encode(
payload, payload,
app.config.get('SECRET_KEY'), app.config.get('SECRET_KEY'),
algorithm='HS256' algorithm='HS256'
) )
except Exception as e: except Exception as e:
return e return e
@staticmethod @staticmethod
def decode_auth_token(auth_token): def decode_auth_token(auth_token):