Data
This commit is contained in:
parent
8482aafcfa
commit
7f80451aab
8 changed files with 72 additions and 1 deletions
23
API/main.py
Normal file
23
API/main.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import configparser
|
||||||
|
import fastapi
|
||||||
|
from fastapi import HTTPException
|
||||||
|
import utils
|
||||||
|
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read('../configs/settings.conf', encoding='utf-8')
|
||||||
|
path = config['database']['path']
|
||||||
|
|
||||||
|
DB = utils.DataBase(path=path)
|
||||||
|
|
||||||
|
app = fastapi.FastAPI()
|
||||||
|
|
||||||
|
@app.post("/web/registration/")
|
||||||
|
def reg(email: str, passwd: str) :
|
||||||
|
code = DB.register_site(email, passwd)
|
||||||
|
if code == 0 :
|
||||||
|
return 200
|
||||||
|
else :
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=400,
|
||||||
|
detail="Этот email уже зарегистрирован"
|
||||||
|
)
|
||||||
45
API/utils.py
Normal file
45
API/utils.py
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
import sqlite3
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
class DataBase :
|
||||||
|
def __init__(self, path: str) :
|
||||||
|
self.connect = sqlite3.connect(path)
|
||||||
|
self.connect.row_factory = sqlite3.Row
|
||||||
|
self.cursor = self.connect.cursor()
|
||||||
|
self.cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS users_site (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
email TEXT NOT NULL UNIQUE,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
created TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
agreement_accepted TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
counts_url INTEGER DEFAULT 0,
|
||||||
|
data_pay TEXT
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
self.cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS users_tg (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
id_tg INTEGER NOT NULL UNIQUE,
|
||||||
|
agreement_accepted TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
counts_url INTEGER DEFAULT 0,
|
||||||
|
data_pay TEXT
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
self.connect.commit()
|
||||||
|
|
||||||
|
def register_site(self, email: str, password: str) -> int :
|
||||||
|
"""
|
||||||
|
Status code:
|
||||||
|
0 - Success
|
||||||
|
1 - Email is bussy
|
||||||
|
"""
|
||||||
|
try :
|
||||||
|
self.cursor.execute('''
|
||||||
|
INSERT INTO users_site (email, password_hash)
|
||||||
|
VALUES (?, ?)
|
||||||
|
''', (email.lower().strip(), hashlib.sha256(password.encode()).hexdigest()))
|
||||||
|
self.connect.commit()
|
||||||
|
return 0
|
||||||
|
except sqlite3.IntegrityError :
|
||||||
|
return 1
|
||||||
0
Data/secret.env
Normal file
0
Data/secret.env
Normal file
0
Frontend/JS/register.js
Normal file
0
Frontend/JS/register.js
Normal file
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Document</title>
|
<title>Document</title>
|
||||||
<link rel="stylesheet" href="../Styles/cp.css">
|
<link rel="stylesheet" href="../Styles/control-panel.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
|
||||||
2
configs/settings.conf
Normal file
2
configs/settings.conf
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
[database]
|
||||||
|
path =
|
||||||
1
requirments.txt
Normal file
1
requirments.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
fastapi[all]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue