10 Commits
Author SHA1 Message Date
Kirill 7ccc9385e6 feat(app.py): Include Blueprint to app 2025-10-25 11:26:46 +03:00
Kirill 1bf9c69c2b feat(api/loginapi.py): Login Api
Blueprint with api login page with is get respons (form-data) and send JVT token and user id name and role
2025-10-25 11:24:31 +03:00
Kirill 2098719c82 feat(model/user.py): User model
User Dataclass with is get all user respons data
2025-10-25 11:23:01 +03:00
Kirill 0e668e1993 feat(utils/token.py): Create JVT token
Added function with is creating jvt tocken for user
2025-10-25 11:21:32 +03:00
Kirill da05ae96d2 fix(controllers/controller.py; model/example.py; utils/InitalizeDB.py): deleted exaple files 2025-10-25 11:19:20 +03:00
Kirill 061b7a86a3 fix(dependencies.txt): JVT tocken libs 2025-10-25 11:18:06 +03:00
Kirill eabc193d8b feat(utils/InitalizeDB.py): PSQL initializing
Add script with is connected to db and initialize it
2025-10-23 23:01:22 +03:00
Kirill 35f18853fc feat(utils/PostgressConnect.py): Postgress connect Functional
Added Functions with connect to postgress db by link from enviroment
2025-10-23 23:00:00 +03:00
Kirill a062d24b24 feat(utils/loadDotEnv.py): Enviroment
Function for download enviroment variables from .env to Enviroment
2025-10-23 22:57:07 +03:00
Kirill a87656274b feat(dependencies.txt): Lib fix
Added libs for working with PSQL and dot-env
2025-10-23 22:55:05 +03:00
9 changed files with 68 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
from flask import Blueprint, request
from model.user import user
loginBP = Blueprint("loginapi", __name__)
@loginBP.route('/api/login', methods = ['POST'])
def login():
email = request.form['email']
password = request.form['password']
#if(isvalid(email, password)):
us = user.initialize(email, password)
return us.toJSON()
+2
View File
@@ -1,4 +1,6 @@
from flask import Flask
from api.loginapi import loginBP
app = Flask(__name__)
app.register_blueprint(loginBP)
View File
+3
View File
@@ -1 +1,4 @@
flask==3.1.2
python-dotenv
psycopg-binary
pyjwt
View File
+22
View File
@@ -0,0 +1,22 @@
from dataclasses import dataclass
import json
from utils.token import generateKey
@dataclass
class user:
id: int
name: str
role: str
token: str
@classmethod
def initialize(cls, email:str, passwd:str):
#us = getUsModel() #возвращает словарь
id = 1#us['id']
name = 'Bob'#us['name']
role = 'Backend'#us['role']
token = generateKey(email, passwd)
return cls(id=id, name=name, role=role, token=token)
def toJSON(self):
return json.dumps({"token": f'{self.token}', "user": {"id": self.id, "role": f'{self.role}', "name": f'{self.name}'}})
+10
View File
@@ -0,0 +1,10 @@
import psycopg
import os
def PSQLConnect():
conn = psycopg.connect(os.getenv('POSTDRESS_CONNECTION'))
return conn
def PSQLCursor(conn):
cur = conn.cursor()
return cur
+12
View File
@@ -0,0 +1,12 @@
import os
from dotenv import load_dotenv
def initializeENV():
dotenv_path = '../.env'
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
print('.env is loaded')
return 1
else:
print('.env isn`t loaded')
return 0
+7
View File
@@ -0,0 +1,7 @@
import jwt
import os
def generateKey(email, passwd):
key = os.getenv('KEY')
encoded = jwt.encode({f"{email}": f"{passwd}"}, key, algorithm="HS256")
return encoded