update python seed
This commit is contained in:
@ -6,14 +6,14 @@ PAYU_MERCHANT_SALT=DusXSSjqqSMTPSpw32hlFXF6LKY2Zm3y
|
|||||||
PAYU_SUCCESS_URL=http://localhost:4200/payment-success
|
PAYU_SUCCESS_URL=http://localhost:4200/payment-success
|
||||||
PAYU_FAILURE_URL=http://localhost:4200/payment-failure
|
PAYU_FAILURE_URL=http://localhost:4200/payment-failure
|
||||||
|
|
||||||
FLASK_ENV=production
|
FLASK_ENV=development
|
||||||
|
|
||||||
MYSQL_HOST=db
|
MYSQL_HOST=db
|
||||||
MYSQL_USER=vendinguser
|
MYSQL_USER=vendinguser
|
||||||
MYSQL_PASSWORD=vendingpass
|
MYSQL_PASSWORD=vendingpass
|
||||||
MYSQL_DATABASE=vending
|
MYSQL_DATABASE=vending
|
||||||
|
|
||||||
SQLITE_DB_PATH=machines
|
SQLITE_DB_PATH=machines.db
|
||||||
|
|
||||||
BREVO_SMTP_EMAIL=smukeshsn2000@gmail.com
|
BREVO_SMTP_EMAIL=smukeshsn2000@gmail.com
|
||||||
BREVO_SMTP_KEY=your-brevo-smtp-key
|
BREVO_SMTP_KEY=your-brevo-smtp-key
|
||||||
|
|||||||
Binary file not shown.
BIN
Machine-Backend/app/instance/machines
Normal file
BIN
Machine-Backend/app/instance/machines
Normal file
Binary file not shown.
@ -1,52 +1,115 @@
|
|||||||
from app import create_app, db
|
from app import create_app, db
|
||||||
from app.models import User
|
from app.models.models import User
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def seed_sample_user():
|
def seed_sample_users():
|
||||||
"""Create a sample user for testing login"""
|
"""Create sample users for testing login with correct roles"""
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
try:
|
try:
|
||||||
# Check if user already exists
|
# Sample users with correct role names (must match database roles exactly)
|
||||||
existing_user = User.query.filter_by(email='admin@vending.com').first()
|
sample_users = [
|
||||||
if existing_user:
|
{
|
||||||
print("Sample user already exists!")
|
'username': 'Super Admin',
|
||||||
print(f"Email: admin@vending.com")
|
'email': 'superadmin@vending.com',
|
||||||
print(f"Password: admin123")
|
'password': 'admin123',
|
||||||
return
|
'role': 'SuperAdmin', # MUST MATCH DATABASE EXACTLY
|
||||||
|
'contact': '+1234567890'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'username': 'Management User',
|
||||||
|
'email': 'management@vending.com',
|
||||||
|
'password': 'management123',
|
||||||
|
'role': 'Management',
|
||||||
|
'contact': '+1234567891'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'username': 'Admin User',
|
||||||
|
'email': 'admin@vending.com',
|
||||||
|
'password': 'admin123',
|
||||||
|
'role': 'Admin',
|
||||||
|
'contact': '+1234567892'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'username': 'Client User',
|
||||||
|
'email': 'client@vending.com',
|
||||||
|
'password': 'client123',
|
||||||
|
'role': 'Client',
|
||||||
|
'contact': '+1234567893'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'username': 'Refiller User',
|
||||||
|
'email': 'refiller@vending.com',
|
||||||
|
'password': 'refiller123',
|
||||||
|
'role': 'Refiller',
|
||||||
|
'contact': '+1234567894'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'username': 'Servicer User',
|
||||||
|
'email': 'servicer@vending.com',
|
||||||
|
'password': 'servicer123',
|
||||||
|
'role': 'Servicer',
|
||||||
|
'contact': '+1234567895'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
# Create sample admin user
|
print("=" * 70)
|
||||||
sample_user = User(
|
print("SEEDING SAMPLE USERS")
|
||||||
user_id=User.generate_user_id('admin', 'admin@vending.com'),
|
print("=" * 70)
|
||||||
username='Admin User',
|
|
||||||
email='admin@vending.com',
|
|
||||||
contact='+1234567890',
|
|
||||||
roles='admin',
|
|
||||||
user_status='active'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set password
|
created_count = 0
|
||||||
sample_user.set_password('admin123')
|
|
||||||
|
|
||||||
# Add to database
|
for user_data in sample_users:
|
||||||
db.session.add(sample_user)
|
# Check if user already exists
|
||||||
|
existing_user = User.query.filter_by(email=user_data['email']).first()
|
||||||
|
if existing_user:
|
||||||
|
print(f"⚠️ User {user_data['email']} already exists - skipping")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Create new user
|
||||||
|
new_user = User(
|
||||||
|
user_id=User.generate_user_id(user_data['username'], user_data['email']),
|
||||||
|
username=user_data['username'],
|
||||||
|
email=user_data['email'],
|
||||||
|
contact=user_data['contact'],
|
||||||
|
roles=user_data['role'], # CORRECT ROLE NAME
|
||||||
|
user_status='active'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set password
|
||||||
|
new_user.set_password(user_data['password'])
|
||||||
|
|
||||||
|
# Add to database
|
||||||
|
db.session.add(new_user)
|
||||||
|
created_count += 1
|
||||||
|
|
||||||
|
print(f"✓ User: {user_data['username']} ({user_data['role']})")
|
||||||
|
|
||||||
|
# Commit all changes
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
print("✅ Sample user created successfully!")
|
print("\n" + "=" * 70)
|
||||||
print("=" * 50)
|
print(f"✓ Successfully created {created_count} sample user(s)")
|
||||||
print(f"User ID: {sample_user.user_id}")
|
print("=" * 70)
|
||||||
print(f"Username: {sample_user.username}")
|
|
||||||
print(f"Email: admin@vending.com")
|
# Display all created users
|
||||||
print(f"Password: admin123")
|
print("\nCREATED USERS - USE THESE TO LOGIN:")
|
||||||
print(f"Role: {sample_user.roles}")
|
print("=" * 70)
|
||||||
print(f"Status: {sample_user.user_status}")
|
all_users = User.query.all()
|
||||||
print("=" * 50)
|
for user in all_users:
|
||||||
|
print(f"\nUsername: {user.username}")
|
||||||
|
print(f"Email: {user.email}")
|
||||||
|
print(f"Role: {user.roles}")
|
||||||
|
print(f"Status: {user.user_status}")
|
||||||
|
print("-" * 70)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
print(f"❌ Error creating sample user: {str(e)}")
|
print(f"\n❌ Error creating sample users: {str(e)}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
seed_sample_user()
|
seed_sample_users()
|
||||||
Reference in New Issue
Block a user