Files
Eventify-frontend/lib/features/auth/providers/auth_provider.dart
Sicherhaven 8955febd00 feat: Phase 1 critical gaps — gamification API, Razorpay checkout, Google OAuth, notifications
- Fix gamification endpoints to use Node.js server (app.eventifyplus.com)
- Replace 6 mock gamification methods with real API calls (dashboard, leaderboard, shop, redeem, submit)
- Add booking models, service, payment service (Razorpay), checkout provider
- Add 3-step CheckoutScreen with Razorpay native modal integration
- Add Google OAuth login (Flutter + Django backend)
- Add full notifications system (Django model + 3 endpoints + Flutter UI)
- Register CheckoutProvider, NotificationProvider in main.dart MultiProvider
- Wire notification bell in HomeScreen app bar
- Add razorpay_flutter ^1.3.7 and google_sign_in ^6.2.2 packages
2026-04-04 15:46:53 +05:30

81 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import '../models/user_model.dart';
import '../services/auth_service.dart';
class AuthProvider extends ChangeNotifier {
final AuthService _authService = AuthService();
UserModel? _user;
bool _loading = false;
UserModel? get user => _user;
bool get loading => _loading;
/// Login with username/email and password.
Future<void> login(String username, String password) async {
_loading = true;
notifyListeners();
try {
final user = await _authService.login(username, password);
_user = user;
} finally {
_loading = false;
notifyListeners();
}
}
/// Register wrapper that is compatible with both old and new callers.
///
/// Preferred: provide [email], [phoneNumber], [password].
/// Older callers that pass [username] will still work — username is ignored
/// for the backend call (we use email/phone/password as per API spec).
Future<void> register({
String? username, // kept for backward compatibility; not sent to backend
String? email,
required String password,
String? phoneNumber,
}) async {
_loading = true;
notifyListeners();
try {
// Prefer explicit email param; if not provided try to use username (some screens passed email as username)
final resolvedEmail = (email != null && email.isNotEmpty) ? email : (username ?? '');
// Ensure we always pass a string phoneNumber to the AuthService (it expects a non-null value)
final resolvedPhone = phoneNumber ?? '';
final user = await _authService.register(
email: resolvedEmail,
phoneNumber: resolvedPhone,
password: password,
);
_user = user;
} finally {
_loading = false;
notifyListeners();
}
}
/// Google OAuth login.
Future<void> googleLogin() async {
_loading = true;
notifyListeners();
try {
final user = await _authService.googleLogin();
_user = user;
} finally {
_loading = false;
notifyListeners();
}
}
Future<void> logout() async {
await _authService.logout();
_user = null;
notifyListeners();
}
}