Delete demo.py
Browse files
demo.py
DELETED
|
@@ -1,81 +0,0 @@
|
|
| 1 |
-
# Add test account creation function
|
| 2 |
-
def create_test_accounts():
|
| 3 |
-
try:
|
| 4 |
-
# Create/admin2@test.com (Admin)
|
| 5 |
-
try:
|
| 6 |
-
admin_user = auth.create_user(
|
| 7 |
-
email='admin2@test.com',
|
| 8 |
-
password='password1'
|
| 9 |
-
)
|
| 10 |
-
except auth.EmailAlreadyExistsError:
|
| 11 |
-
admin_user = auth.get_user_by_email('admin2@test.com')
|
| 12 |
-
|
| 13 |
-
db.reference(f'users/{admin_user.uid}').set({
|
| 14 |
-
'daily_cash': 300,
|
| 15 |
-
'remaining_cash': 300,
|
| 16 |
-
'last_reset': '2000-01-01T00:00:00+00:00',
|
| 17 |
-
'is_admin': True
|
| 18 |
-
})
|
| 19 |
-
|
| 20 |
-
# Create user1@test.com (Regular user)
|
| 21 |
-
try:
|
| 22 |
-
regular_user = auth.create_user(
|
| 23 |
-
email='user1@test.com',
|
| 24 |
-
password='123456'
|
| 25 |
-
)
|
| 26 |
-
except auth.EmailAlreadyExistsError:
|
| 27 |
-
regular_user = auth.get_user_by_email('user1@test.com')
|
| 28 |
-
|
| 29 |
-
db.reference(f'users/{regular_user.uid}').set({
|
| 30 |
-
'daily_cash': 300,
|
| 31 |
-
'remaining_cash': 300,
|
| 32 |
-
'last_reset': '2000-01-01T00:00:00+00:00',
|
| 33 |
-
'is_admin': False
|
| 34 |
-
})
|
| 35 |
-
|
| 36 |
-
print("Test accounts created/updated successfully")
|
| 37 |
-
except Exception as e:
|
| 38 |
-
print(f"Error creating test accounts: {str(e)}")
|
| 39 |
-
|
| 40 |
-
# Create test accounts when server starts
|
| 41 |
-
create_test_accounts()
|
| 42 |
-
|
| 43 |
-
@app.route('/api/admin/users/<string:uid>/cash-limit-period', methods=['PUT'])
|
| 44 |
-
def update_cash_limit_period(uid):
|
| 45 |
-
try:
|
| 46 |
-
verify_admin(request.headers.get('Authorization', ''))
|
| 47 |
-
data = request.get_json()
|
| 48 |
-
start_date = data.get('start_date')
|
| 49 |
-
end_date = data.get('end_date')
|
| 50 |
-
cash_limit = data.get('cash_limit')
|
| 51 |
-
if not (start_date and end_date and cash_limit is not None):
|
| 52 |
-
return jsonify({'error': 'start_date, end_date, and cash_limit are required'}), 400
|
| 53 |
-
try:
|
| 54 |
-
datetime.strptime(start_date, '%Y-%m-%d')
|
| 55 |
-
datetime.strptime(end_date, '%Y-%m-%d')
|
| 56 |
-
except Exception as e:
|
| 57 |
-
return jsonify({'error': 'Invalid date format. Use YYYY-MM-DD for start_date and end_date'}), 400
|
| 58 |
-
|
| 59 |
-
user_ref = db.reference(f'users/{uid}')
|
| 60 |
-
user_data = user_ref.get()
|
| 61 |
-
if not user_data:
|
| 62 |
-
return jsonify({'error': 'User not found'}), 404
|
| 63 |
-
|
| 64 |
-
user_ref.update({
|
| 65 |
-
'cash_limit_period': {
|
| 66 |
-
'start_date': start_date,
|
| 67 |
-
'end_date': end_date,
|
| 68 |
-
'limit': float(cash_limit)
|
| 69 |
-
}
|
| 70 |
-
})
|
| 71 |
-
|
| 72 |
-
return jsonify({
|
| 73 |
-
'success': True,
|
| 74 |
-
'cash_limit_period': {
|
| 75 |
-
'start_date': start_date,
|
| 76 |
-
'end_date': end_date,
|
| 77 |
-
'limit': float(cash_limit)
|
| 78 |
-
}
|
| 79 |
-
})
|
| 80 |
-
except Exception as e:
|
| 81 |
-
return jsonify({'error': str(e)}), 400
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|