Many api changes

- Added basic jwt auth
- Added keyword endpoints
- added share/symbol endpoints
- updated postman
- refactoring
This commit is contained in:
2022-03-14 17:10:00 +01:00
parent 412ec06144
commit 6923095939
8 changed files with 457 additions and 115 deletions

View File

@@ -1,6 +1,13 @@
import hashlib
import os
import uuid
import jwt
from flask import request
from webservice.db import db
from webservice.models import User
def hash_password(password):
salt = uuid.uuid4().hex
@@ -9,4 +16,28 @@ def hash_password(password):
def check_password(hashed_password, user_password):
password, salt = hashed_password.split(':')
return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest()
return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest()
def get_token():
token = None
if 'Authorization' in request.headers:
token = request.headers['Authorization'].split(" ")[1]
return token
def extract_token_data(token):
if token is not None:
try:
return jwt.decode(token, os.getenv('SECRET_KEY'), algorithms=["HS256"])
except:
return None
def get_username_from_token_data(token_data):
return token_data['username']
def get_user_id_from_username(username):
return db.session.query(User).filter_by(username=username).first().user_id