Initial commit - LEGO Instructions Manager v1.5.0
This commit is contained in:
135
check_admin.py
Normal file
135
check_admin.py
Normal file
@@ -0,0 +1,135 @@
|
||||
"""
|
||||
Admin Status Check & Set Script
|
||||
Checks if user 'jessikitty' is an admin, and can set admin status
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add parent directory to path so we can import app
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, script_dir)
|
||||
|
||||
def find_database():
|
||||
"""Find the database file in common locations."""
|
||||
possible_paths = [
|
||||
os.path.join(script_dir, 'instance', 'lego_instructions.db'),
|
||||
os.path.join(script_dir, 'lego_instructions.db'),
|
||||
os.path.join(script_dir, 'app', 'lego_instructions.db'),
|
||||
]
|
||||
|
||||
for path in possible_paths:
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
|
||||
return None
|
||||
|
||||
def main():
|
||||
# Find database
|
||||
db_path = find_database()
|
||||
|
||||
if not db_path:
|
||||
print("=" * 70)
|
||||
print("❌ Database not found!")
|
||||
print("=" * 70)
|
||||
print()
|
||||
print("Searched in:")
|
||||
print(" - E:\\LIM\\instance\\lego_instructions.db")
|
||||
print(" - E:\\LIM\\lego_instructions.db")
|
||||
print(" - E:\\LIM\\app\\lego_instructions.db")
|
||||
print()
|
||||
print("Please make sure:")
|
||||
print(" 1. You've run the app at least once to create the database")
|
||||
print(" 2. You're in the correct directory (E:\\LIM)")
|
||||
print()
|
||||
return
|
||||
|
||||
print(f"Found database: {db_path}")
|
||||
print()
|
||||
|
||||
# Set database URL to the found path
|
||||
db_uri = 'sqlite:///' + db_path.replace('\\', '/')
|
||||
os.environ['DATABASE_URL'] = db_uri
|
||||
|
||||
from app import create_app, db
|
||||
from app.models.user import User
|
||||
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
print("=" * 70)
|
||||
print("LEGO Instructions Manager - Admin Status Check")
|
||||
print("=" * 70)
|
||||
print()
|
||||
|
||||
# Find user
|
||||
user = User.query.filter_by(username='jessikitty').first()
|
||||
|
||||
if not user:
|
||||
print("❌ User 'jessikitty' not found!")
|
||||
print()
|
||||
print("Available users:")
|
||||
all_users = User.query.all()
|
||||
for u in all_users:
|
||||
admin_badge = "🛡️ ADMIN" if u.is_admin else "👤 User"
|
||||
print(f" - {u.username} ({u.email}) - {admin_badge}")
|
||||
print()
|
||||
return
|
||||
|
||||
print(f"Found user: {user.username}")
|
||||
print(f"Email: {user.email}")
|
||||
print(f"Member since: {user.created_at.strftime('%B %d, %Y')}")
|
||||
print()
|
||||
|
||||
if user.is_admin:
|
||||
print("✅ Status: ADMIN (Already has admin privileges)")
|
||||
print()
|
||||
print("Admin capabilities:")
|
||||
print(" ✓ Access admin panel at /admin/")
|
||||
print(" ✓ Manage all users")
|
||||
print(" ✓ Manage all sets")
|
||||
print(" ✓ View site statistics")
|
||||
print(" ✓ Delete any content")
|
||||
else:
|
||||
print("⚠️ Status: Regular User (Not an admin)")
|
||||
print()
|
||||
response = input("Would you like to grant admin privileges? (yes/no): ")
|
||||
|
||||
if response.lower() in ['yes', 'y']:
|
||||
user.is_admin = True
|
||||
db.session.commit()
|
||||
print()
|
||||
print("=" * 70)
|
||||
print("✅ SUCCESS! Admin privileges granted to jessikitty!")
|
||||
print("=" * 70)
|
||||
print()
|
||||
print("Admin capabilities:")
|
||||
print(" ✓ Access admin panel at /admin/")
|
||||
print(" ✓ Manage all users")
|
||||
print(" ✓ Manage all sets")
|
||||
print(" ✓ View site statistics")
|
||||
print(" ✓ Delete any content")
|
||||
print()
|
||||
print("Next steps:")
|
||||
print(" 1. Restart Flask (if running)")
|
||||
print(" 2. Login as jessikitty")
|
||||
print(" 3. Look for 'Admin' dropdown in navbar")
|
||||
print(" 4. Click Admin → Dashboard")
|
||||
else:
|
||||
print()
|
||||
print("No changes made.")
|
||||
|
||||
print()
|
||||
print("=" * 70)
|
||||
print("Current Admin Users:")
|
||||
print("=" * 70)
|
||||
admins = User.query.filter_by(is_admin=True).all()
|
||||
if admins:
|
||||
for admin in admins:
|
||||
print(f" 🛡️ {admin.username} ({admin.email})")
|
||||
else:
|
||||
print(" No admin users found!")
|
||||
print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user