forked from s4l1hs/Database-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_user.py
More file actions
70 lines (54 loc) · 1.78 KB
/
Copy pathload_user.py
File metadata and controls
70 lines (54 loc) · 1.78 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Seed admin and editor user accounts."""
import logging
import os
import sys
from werkzeug.security import generate_password_hash
# Add project root to Python path
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path:
sys.path.insert(0, project_root)
from App.db import get_db # noqa: E402
from App.routes import create_app # noqa: E402 # type: ignore
logger = logging.getLogger(__name__)
DEFAULT_PASSWORD = "password"
def seed_students() -> None:
"""
Seed admin and editor users into the students table.
Admins: team_no = 1
Editor: student_number = 5454, team_no = 2
All accounts get a default hashed password.
"""
db = get_db()
cur = db.cursor()
hashed = generate_password_hash(DEFAULT_PASSWORD)
sql = """
INSERT INTO students (student_number, full_name, team_no, password_hash)
VALUES (%s, %s, %s, %s)
ON DUPLICATE KEY UPDATE
full_name = VALUES(full_name),
team_no = VALUES(team_no),
password_hash = VALUES(password_hash)
"""
rows = [
# Admin users (team_no = 1)
("820230313", "Salih Sefer", 1),
("820230334", "Atahan Evintan", 1),
("820230326", "Fatih Serdar Cakmak", 1),
("820230314", "Muhammet Tuncer", 1),
("150210085", "Gulbahar Karabas", 1),
# Editor user (team_no = 2)
("5454", "Editor User", 2),
]
for sn, name, team in rows:
cur.execute(sql, (sn, name, team, hashed))
db.commit()
cur.close()
logger.info(
"Successfully seeded %d student accounts (default password: %s).",
len(rows),
DEFAULT_PASSWORD,
)
if __name__ == "__main__":
app = create_app()
with app.app_context():
seed_students()