|
|
|
import sys |
|
import os |
|
|
|
|
|
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...") |
|
|
|
|
|
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") |
|
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") |
|
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() |
|
|
|
|