-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_init.py
54 lines (41 loc) · 1.41 KB
/
db_init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from string import ascii_letters, digits
import random as rand
import sqlite3, json, bcrypt, cfg
conn = sqlite3.connect(cfg.DB_FILENAME)
conn.execute("DROP TABLE IF EXISTS users")
conn.execute( """CREATE TABLE users (
first text NOT NULL,
last text NOT NULL,
patronymic text NOT NULL,
email text NOT NULL UNIQUE,
phone text NOT NULL UNIQUE,
other text,
passwh BLOB NOT NULL,
role text NOT NULL)
""")
conn.commit()
conn.execute("DROP TABLE IF EXISTS videos")
conn.execute( """CREATE TABLE videos (
title text NOT NULL,
description text NOT NULL,
source text NOT NULL,
hls_path text NOT NULL,
status text NOT NULL)
""")
conn.commit()
admin_pass = "SECret21672"
passh = bcrypt.hashpw(admin_pass.encode('utf-8'), bcrypt.gensalt())
user = ('Аминистратор', 'Аминистраторов', 'Аминистраторович', '[email protected]',
'+79123456789', "Просто админ", passh, 'admin')
conn.execute( """INSERT INTO users
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""", user)
conn.commit()
conn.close()
with open("admin_auth.json", 'w') as f:
f.write(json.dumps({"admin_email": "[email protected]",
"admin_pass":admin_pass
}))
print("""Данные для авторизации администратора сохранены в файле admin_auth.json:
Email: [email protected]
Пароль: %s""" % admin_pass)