fix(mobile): URL changement mdp corrigée + v3.0 — multi-org, AppAuth, sécurité prod
Auth: - profile_repository.dart: /api/auth/change-password → /api/membres/auth/change-password Multi-org (Phase 3): - OrgSelectorPage, OrgSwitcherBloc, OrgSwitcherEntry - org_context_service.dart: headers X-Active-Organisation-Id + X-Active-Role Navigation: - MorePage: navigation conditionnelle par typeOrganisation - Suppression adaptive_navigation (remplacé par main_navigation_layout) Auth AppAuth: - keycloak_webview_auth_service: fixes AppAuth Android - AuthBloc: gestion REAUTH_REQUIS + premierLoginComplet Onboarding: - Nouveaux états: payment_method_page, onboarding_shared_widgets - SouscriptionStatusModel mis à jour StatutValidationSouscription Android: - build.gradle: ProGuard/R8, network_security_config - Gradle wrapper mis à jour
This commit is contained in:
@@ -6,6 +6,7 @@ import '../../data/models/user_role.dart';
|
||||
import '../../data/datasources/keycloak_auth_service.dart';
|
||||
import '../../data/datasources/permission_engine.dart';
|
||||
import '../../../../core/config/environment.dart';
|
||||
import '../../../../core/network/org_context_service.dart';
|
||||
import '../../../../core/storage/dashboard_cache_manager.dart';
|
||||
import '../../../../core/utils/logger.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
@@ -87,16 +88,32 @@ class AuthPendingOnboarding extends AuthState {
|
||||
List<Object?> get props => [onboardingState, souscriptionId, organisationId, typeOrganisation];
|
||||
}
|
||||
|
||||
// Nouvel événement : auto-select l'org active après login (pour membres mono-org)
|
||||
class AuthOrgContextInitRequested extends AuthEvent {
|
||||
final String organisationId;
|
||||
final String organisationNom;
|
||||
final String? type;
|
||||
const AuthOrgContextInitRequested({
|
||||
required this.organisationId,
|
||||
required this.organisationNom,
|
||||
this.type,
|
||||
});
|
||||
@override
|
||||
List<Object?> get props => [organisationId, organisationNom, type];
|
||||
}
|
||||
|
||||
// === BLOC ===
|
||||
@lazySingleton
|
||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
final KeycloakAuthService _authService;
|
||||
final OrgContextService _orgContextService;
|
||||
|
||||
AuthBloc(this._authService) : super(AuthInitial()) {
|
||||
AuthBloc(this._authService, this._orgContextService) : super(AuthInitial()) {
|
||||
on<AuthLoginRequested>(_onLoginRequested);
|
||||
on<AuthLogoutRequested>(_onLogoutRequested);
|
||||
on<AuthStatusChecked>(_onStatusChecked);
|
||||
on<AuthTokenRefreshRequested>(_onTokenRefreshRequested);
|
||||
on<AuthOrgContextInitRequested>(_onOrgContextInit);
|
||||
}
|
||||
|
||||
Future<void> _onLoginRequested(AuthLoginRequested event, Emitter<AuthState> emit) async {
|
||||
@@ -185,9 +202,22 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
emit(AuthLoading());
|
||||
await _authService.logout();
|
||||
await DashboardCacheManager.clear();
|
||||
_orgContextService.clear();
|
||||
emit(AuthUnauthenticated());
|
||||
}
|
||||
|
||||
Future<void> _onOrgContextInit(
|
||||
AuthOrgContextInitRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
_orgContextService.setActiveOrganisation(
|
||||
organisationId: event.organisationId,
|
||||
nom: event.organisationNom,
|
||||
type: event.type,
|
||||
);
|
||||
AppLogger.info('AuthBloc: contexte org initialisé → ${event.organisationNom}');
|
||||
}
|
||||
|
||||
Future<void> _onStatusChecked(AuthStatusChecked event, Emitter<AuthState> emit) async {
|
||||
final tokenValid = await _authService.getValidToken();
|
||||
final isAuth = tokenValid != null;
|
||||
@@ -276,9 +306,18 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
///
|
||||
/// Si le rôle est [UserRole.orgAdmin] et que [organizationContexts] est vide,
|
||||
/// appelle GET /api/organisations/mes pour récupérer les organisations de l'admin.
|
||||
/// Auto-initialise [OrgContextService] si une seule organisation.
|
||||
Future<User> _enrichUserWithOrgContext(User user) async {
|
||||
if (user.primaryRole != UserRole.orgAdmin ||
|
||||
user.organizationContexts.isNotEmpty) {
|
||||
// Auto-select le premier contexte existant si pas encore de contexte actif
|
||||
if (!_orgContextService.hasContext && user.organizationContexts.isNotEmpty) {
|
||||
final first = user.organizationContexts.first;
|
||||
_orgContextService.setActiveOrganisation(
|
||||
organisationId: first.organizationId,
|
||||
nom: first.organizationName,
|
||||
);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
try {
|
||||
@@ -296,7 +335,15 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
return contexts.isEmpty ? user : user.copyWith(organizationContexts: contexts);
|
||||
if (contexts.isEmpty) return user;
|
||||
// Auto-select si une seule organisation
|
||||
if (contexts.length == 1 && !_orgContextService.hasContext) {
|
||||
_orgContextService.setActiveOrganisation(
|
||||
organisationId: contexts.first.organizationId,
|
||||
nom: contexts.first.organizationName,
|
||||
);
|
||||
}
|
||||
return user.copyWith(organizationContexts: contexts);
|
||||
} catch (e) {
|
||||
AppLogger.warning('AuthBloc: impossible de charger le contexte org: $e');
|
||||
return user;
|
||||
|
||||
Reference in New Issue
Block a user