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