-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_user_direct.py
More file actions
30 lines (23 loc) · 923 Bytes
/
Copy pathcreate_user_direct.py
File metadata and controls
30 lines (23 loc) · 923 Bytes
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
import sqlite3
from passlib.context import CryptContext
from datetime import datetime
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
hashed = pwd_context.hash("password")
conn = sqlite3.connect("dev_local.db")
cursor = conn.cursor()
email = "tsmluky@gmail.com"
# Check existence
cursor.execute("SELECT id FROM users WHERE email=?", (email,))
exists = cursor.fetchone()
if exists:
print("User exists. Updating password...")
cursor.execute("UPDATE users SET hashed_password=?, role='admin' WHERE email=?", (hashed, email))
else:
print("Creating user...")
cursor.execute("""
INSERT INTO users (email, hashed_password, name, role, plan, disabled_strategies, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (email, hashed, "Lukx", "admin", "OWNER", "[]", datetime.utcnow()))
conn.commit()
conn.close()
print("Done. User tsmluky@gmail.com password set to 'password'.")