-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_user.py
More file actions
48 lines (40 loc) · 1.58 KB
/
add_user.py
File metadata and controls
48 lines (40 loc) · 1.58 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
#!/usr/bin/env python3
import sys
import os
# Add current directory to path so we can import app
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from app import app, db, User
from werkzeug.security import generate_password_hash
def create_test_user():
with app.app_context():
try:
# Ensure tables exist
db.create_all()
# Check if user exists
user = User.query.filter_by(username='testuser').first()
if user:
print('User already exists, updating password...')
user.password_hash = generate_password_hash('testpass')
db.session.commit()
else:
# Create user
print('Creating new user...')
user = User(username='testuser', email='test@example.com')
user.password_hash = generate_password_hash('testpass')
db.session.add(user)
db.session.commit()
print('Test user created successfully')
# Verify the user
user = User.query.filter_by(username='testuser').first()
if user and user.check_password('testpass'):
print('✓ User verification successful')
return True
else:
print('✗ User verification failed')
return False
except Exception as e:
print(f'Error: {e}')
return False
if __name__ == '__main__':
success = create_test_user()
sys.exit(0 if success else 1)