Spaces:
Sleeping
Sleeping
| # 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() | |
| 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 | |