File size: 1,555 Bytes
0a40ab8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# src/create_sample_users.py
import sys
import os

# Add project root to sys.path to allow imports from src
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

from src.main import app, db
from src.models.user import User

def create_users():
    """Creates sample users in the database."""
    with app.app_context():
        print("Creating sample users...")
        
        # Check if users already exist
        admin_user = User.query.filter_by(username="admin").first()
        analyst_user = User.query.filter_by(username="analyst").first()

        if not admin_user:
            admin = User(username="admin", full_name="Admin User", role="Administrator")
            admin.set_password("password123") # Use a more secure password in production
            db.session.add(admin)
            print("Created admin user (password: password123)")
        else:
            print("Admin user already exists.")

        if not analyst_user:
            analyst = User(username="analyst", full_name="Legal Analyst", role="Analyst")
            analyst.set_password("testpass") # Use a more secure password in production
            db.session.add(analyst)
            print("Created analyst user (password: testpass)")
        else:
            print("Analyst user already exists.")

        try:
            db.session.commit()
            print("Users committed to database.")
        except Exception as e:
            db.session.rollback()
            print(f"Error creating users: {e}")

if __name__ == "__main__":
    create_users()