-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_admin.py
More file actions
49 lines (40 loc) · 1.18 KB
/
Copy pathcreate_admin.py
File metadata and controls
49 lines (40 loc) · 1.18 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
import sqlite3
import os
from werkzeug.security import generate_password_hash
from datetime import datetime
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
DB_PATH = os.path.join(BASE_DIR, 'diabetes.db')
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# Create users table if app.py has not been run yet
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
role TEXT NOT NULL,
date TEXT
)
''')
conn.commit()
admin_email = "admin@gmail.com"
cursor.execute("SELECT id FROM users WHERE email = ?", (admin_email,))
existing_admin = cursor.fetchone()
if existing_admin:
print("Admin already exists. No new admin was created.")
else:
hashed_password = generate_password_hash("admin123")
cursor.execute("""
INSERT INTO users (name, email, password, role, date)
VALUES (?, ?, ?, ?, ?)
""", (
"Admin",
admin_email,
hashed_password,
"admin",
datetime.now().strftime("%Y-%m-%d %H:%M:%S")
))
conn.commit()
print("Admin created successfully!")
conn.close()