Compare commits

...
6 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
8 changed files with 45 additions and 80 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
+2 -1
View File
@@ -1,3 +1,4 @@
flask==3.1.2
python-dotenv
psycopg-binary==3.2.10
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}'}})
-79
View File
@@ -1,79 +0,0 @@
import psycopg
from PostgressConnect import PSQLConnect, PSQLCursor
from loadDotEnv import initializeENV
state = initializeENV()
conn = PSQLConnect()
cur = PSQLCursor(conn)
cur.execute('''
-- Пользователи системы
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
role VARCHAR(50) NOT NULL, -- 'operator', 'admin', 'viewer'
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Роботы
CREATE TABLE robots (
id VARCHAR(50) PRIMARY KEY, -- 'RB-001'
status VARCHAR(50) DEFAULT 'active',
battery_level INTEGER,
last_update TIMESTAMP,
current_zone VARCHAR(10),
current_row INTEGER,
current_shelf INTEGER
);
-- Товары
CREATE TABLE products (
id VARCHAR(50) PRIMARY KEY, -- 'TEL-4567'
name VARCHAR(255) NOT NULL,
category VARCHAR(100),
min_stock INTEGER DEFAULT 10,
optimal_stock INTEGER DEFAULT 100
);
-- История инвентаризации
CREATE TABLE inventory_history (
id SERIAL PRIMARY KEY,
robot_id VARCHAR(50) REFERENCES robots(id),
product_id VARCHAR(50) REFERENCES productsuid),
quantity INTEGER NOT NULL,
zone VARCHAR(10) NOT NULL,
row_number INTEGER,
shelf_number INTEGER,
status VARCHAR(50), -- 'OK', 'LOW_STOCK', 'CRITICAL'
scanned_at TIMESTAMP NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Прогнозы ИИ
CREATE TABLE ai_predictions (
id SERIAL PRIMARY KEY,
product_id VARCHAR(50) REFERENCES products(id),
prediction_date DATE NOT NULL,
days_until_stockout INTEGER,
recommended_order INTEGER,
confidence_score DECIMAL(3,2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Индексы для оптимизации
REATE INDEX idx_inventory_scanned ON inventory_history(scanned_at DESC);
CREATE INDEX idx_inventory_product ON inventory_history(product_id);
CREATE INDEX idx_inventory_zone ON inventory_history(zone);
''')
conn.commit()
cur.close()
conn.close()
print("DB is Initialized")
+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