deploy: Update frontend build for deployment
This commit is contained in:
1 parent
f18b6ce2df
commit
b3e233bf76
6 files changed
+306
-2266
No files matched your search
@@ -10,15 +10,18 @@ with app.app_context():
|
||||
print(f"Found admin user. Current role: {admin.role}")
|
||||
if admin.role != 'admin':
|
||||
admin.role = 'admin'
|
||||
db.session.commit()
|
||||
print("Updated admin user role to 'admin'")
|
||||
# Always update password to ensure it's set correctly
|
||||
admin.set_password('Hxit@54321')
|
||||
db.session.commit()
|
||||
print("Updated admin user password to 'Hxit@54321'")
|
||||
else:
|
||||
print("Admin user not found. Creating...")
|
||||
admin = User(username='admin', email='admin@example.com', role='admin')
|
||||
admin.set_password('Hxit@54321')
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
print("Created admin user with role 'admin'")
|
||||
print("Created admin user with role 'admin' and password 'Hxit@54321'")
|
||||
|
||||
# Also check if there are other users that should be admin but aren't
|
||||
users = User.query.all()
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
密码重置脚本
|
||||
用途:用于重置用户密码,特别是在用户忘记密码时
|
||||
使用方法:python3 reset_password.py <username> <new_password>
|
||||
"""
|
||||
import sys
|
||||
from app import create_app, db
|
||||
from app.models import User
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python3 reset_password.py <username> <new_password>")
|
||||
print("Example: python3 reset_password.py admin Hxit@54321")
|
||||
sys.exit(1)
|
||||
|
||||
username = sys.argv[1]
|
||||
new_password = sys.argv[2]
|
||||
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
# 查找用户
|
||||
user = User.query.filter_by(username=username).first()
|
||||
if user:
|
||||
print(f"Found user: {user.username}, Role: {user.role}")
|
||||
# 设置新密码
|
||||
user.set_password(new_password)
|
||||
db.session.commit()
|
||||
print(f"✅ SUCCESS: Password reset for user '{username}' to '{new_password}'")
|
||||
else:
|
||||
print(f"❌ FAILURE: User '{username}' not found")
|
||||
# 列出所有可用用户
|
||||
print("\nAvailable users:")
|
||||
users = User.query.all()
|
||||
for u in users:
|
||||
print(f" - {u.username} (Role: {u.role})")
|
||||
@@ -0,0 +1,24 @@
|
||||
from app import create_app, db
|
||||
from app.models import User
|
||||
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
# 测试 admin 用户登录
|
||||
admin = User.query.filter_by(username='admin').first()
|
||||
if admin:
|
||||
print(f"Testing admin user login...")
|
||||
# 测试新密码
|
||||
password = 'Hxit@54321'
|
||||
if admin.check_password(password):
|
||||
print(f"✅ SUCCESS: Admin user can login with password '{password}'")
|
||||
else:
|
||||
print(f"❌ FAILURE: Admin user cannot login with password '{password}'")
|
||||
|
||||
# 测试错误密码
|
||||
wrong_password = 'wrongpassword'
|
||||
if not admin.check_password(wrong_password):
|
||||
print(f"✅ SUCCESS: Admin user correctly rejects wrong password")
|
||||
else:
|
||||
print(f"❌ FAILURE: Admin user accepts wrong password")
|
||||
else:
|
||||
print("Admin user not found!")
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试登录 API
|
||||
用途:直接测试后端的登录 API 是否能正常响应
|
||||
使用方法:python3 test_login_api.py <username> <password>
|
||||
"""
|
||||
import sys
|
||||
import json
|
||||
import requests
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python3 test_login_api.py <username> <password>")
|
||||
print("Example: python3 test_login_api.py admin Hxit@54321")
|
||||
sys.exit(1)
|
||||
|
||||
username = sys.argv[1]
|
||||
password = sys.argv[2]
|
||||
|
||||
# 测试登录 API
|
||||
url = "http://localhost:5002/api/user/login"
|
||||
headers = {"Content-Type": "application/json"}
|
||||
data = {"username": username, "password": password}
|
||||
|
||||
print(f"Testing login API for user '{username}'...")
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=5)
|
||||
print(f"Status code: {response.status_code}")
|
||||
print(f"Response: {response.json()}")
|
||||
|
||||
if response.status_code == 200:
|
||||
print("✅ SUCCESS: Login API returned 200 OK")
|
||||
else:
|
||||
print("❌ FAILURE: Login API returned error")
|
||||
except requests.exceptions.ConnectionError:
|
||||
print("❌ FAILURE: Cannot connect to the server. Is the backend running?")
|
||||
except Exception as e:
|
||||
print(f"❌ FAILURE: Error testing login API: {e}")
|
||||
|
||||
# 测试另一种方式:使用 Flask 应用上下文直接测试
|
||||
print("\nTesting with Flask app context...")
|
||||
try:
|
||||
from app import create_app
|
||||
from app.models import User
|
||||
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
user = User.query.filter_by(username=username).first()
|
||||
if user:
|
||||
print(f"Found user: {user.username}, Role: {user.role}")
|
||||
if user.check_password(password):
|
||||
print(f"✅ SUCCESS: Password is correct for user '{username}'")
|
||||
else:
|
||||
print(f"❌ FAILURE: Password is incorrect for user '{username}'")
|
||||
else:
|
||||
print(f"❌ FAILURE: User '{username}' not found")
|
||||
except Exception as e:
|
||||
print(f"❌ FAILURE: Error testing with app context: {e}")
|
||||
Reference in new issue
Block a user