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:
dahoud
2026-04-07 20:56:03 +00:00
parent 22f9c7e9a1
commit 70cbd1c873
63 changed files with 9316 additions and 6122 deletions

View File

@@ -0,0 +1,384 @@
/// Page de sélection d'organisation pour les membres multi-org.
///
/// S'affiche après la connexion si le membre appartient à plusieurs organisations,
/// ou accessible depuis le profil pour changer d'organisation active.
library org_selector_page;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../bloc/org_switcher_bloc.dart';
import '../../data/models/org_switcher_entry.dart';
class OrgSelectorPage extends StatefulWidget {
/// Si true, la page ne peut pas être ignorée (premier choix obligatoire).
final bool required;
const OrgSelectorPage({super.key, this.required = false});
@override
State<OrgSelectorPage> createState() => _OrgSelectorPageState();
}
class _OrgSelectorPageState extends State<OrgSelectorPage> {
@override
void initState() {
super.initState();
context.read<OrgSwitcherBloc>().add(const OrgSwitcherLoadRequested());
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('Choisir une organisation'),
automaticallyImplyLeading: !widget.required,
elevation: 0,
),
body: BlocConsumer<OrgSwitcherBloc, OrgSwitcherState>(
listener: (context, state) {
if (state is OrgSwitcherLoaded && widget.required && state.active != null) {
// Une org a été auto-sélectionnée, on peut continuer
}
},
builder: (context, state) {
if (state is OrgSwitcherLoading) {
return const Center(child: CircularProgressIndicator());
}
if (state is OrgSwitcherError) {
return _ErrorView(
message: state.message,
onRetry: () => context
.read<OrgSwitcherBloc>()
.add(const OrgSwitcherLoadRequested()),
);
}
if (state is OrgSwitcherLoaded) {
if (state.organisations.isEmpty) {
return const _EmptyView();
}
return _OrgList(
organisations: state.organisations,
active: state.active,
onSelect: (org) {
context
.read<OrgSwitcherBloc>()
.add(OrgSwitcherSelectRequested(org));
Navigator.of(context).pop(org);
},
);
}
return const SizedBox.shrink();
},
),
);
}
}
// ─── Widgets privés ──────────────────────────────────────────────────────────
class _OrgList extends StatelessWidget {
final List<OrgSwitcherEntry> organisations;
final OrgSwitcherEntry? active;
final ValueChanged<OrgSwitcherEntry> onSelect;
const _OrgList({
required this.organisations,
required this.active,
required this.onSelect,
});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
child: Text(
'Sélectionnez l\'organisation dans laquelle vous souhaitez travailler.',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
Expanded(
child: ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
itemCount: organisations.length,
separatorBuilder: (_, __) => const SizedBox(height: 8),
itemBuilder: (context, index) {
final org = organisations[index];
final isActive = active?.organisationId == org.organisationId;
return _OrgCard(
org: org,
isActive: isActive,
onTap: () => onSelect(org),
);
},
),
),
],
);
}
}
class _OrgCard extends StatelessWidget {
final OrgSwitcherEntry org;
final bool isActive;
final VoidCallback onTap;
const _OrgCard({
required this.org,
required this.isActive,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Card(
elevation: isActive ? 3 : 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: isActive
? BorderSide(color: colorScheme.primary, width: 2)
: BorderSide.none,
),
color: isActive
? colorScheme.primaryContainer.withValues(alpha: 0.3)
: colorScheme.surface,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
// Icône / avatar
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: isActive
? colorScheme.primary
: colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12),
),
alignment: Alignment.center,
child: Text(
org.nom.isNotEmpty ? org.nom[0].toUpperCase() : '?',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: isActive ? colorScheme.onPrimary : colorScheme.onSurfaceVariant,
),
),
),
const SizedBox(width: 12),
// Informations
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
org.libelleCourt,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: isActive ? colorScheme.primary : null,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Row(
children: [
_Chip(org.typeOrganisation),
if (org.statutMembre != null) ...[
const SizedBox(width: 6),
_Chip(
org.statutMembre!,
color: org.statutMembre == 'ACTIF'
? Colors.green.shade700
: Colors.orange.shade700,
),
],
],
),
if (org.roleOrg != null) ...[
const SizedBox(height: 2),
Text(
org.roleOrg!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: colorScheme.onSurfaceVariant,
),
),
],
],
),
),
if (isActive)
Icon(Icons.check_circle, color: colorScheme.primary, size: 24),
],
),
),
),
);
}
}
class _Chip extends StatelessWidget {
final String label;
final Color? color;
const _Chip(this.label, {this.color});
@override
Widget build(BuildContext context) {
final effectiveColor = color ?? Theme.of(context).colorScheme.onSurfaceVariant;
return Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: effectiveColor.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(4),
),
child: Text(
label,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: effectiveColor,
),
),
);
}
}
class _ErrorView extends StatelessWidget {
final String message;
final VoidCallback onRetry;
const _ErrorView({required this.message, required this.onRetry});
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.cloud_off, size: 56, color: Colors.grey),
const SizedBox(height: 16),
Text(message, textAlign: TextAlign.center),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: onRetry,
icon: const Icon(Icons.refresh),
label: const Text('Réessayer'),
),
],
),
),
);
}
}
class _EmptyView extends StatelessWidget {
const _EmptyView();
@override
Widget build(BuildContext context) {
return const Center(
child: Padding(
padding: EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.business_outlined, size: 56, color: Colors.grey),
SizedBox(height: 16),
Text(
'Vous n\'êtes membre d\'aucune organisation active.',
textAlign: TextAlign.center,
),
],
),
),
);
}
}
/// Widget compact pour afficher/changer l'org active dans une AppBar ou drawer.
///
/// Usage:
/// ```dart
/// OrgSwitcherBadge(onTap: () => _openOrgSelector(context))
/// ```
class OrgSwitcherBadge extends StatelessWidget {
final OrgSwitcherEntry? activeOrg;
final VoidCallback onTap;
const OrgSwitcherBadge({
super.key,
required this.activeOrg,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final label = activeOrg?.libelleCourt ?? 'Choisir organisation';
return GestureDetector(
onTap: onTap,
child: Container(
constraints: const BoxConstraints(maxWidth: 200),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: colorScheme.primaryContainer.withValues(alpha: 0.4),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: colorScheme.primary.withValues(alpha: 0.4),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.business, size: 16, color: colorScheme.primary),
const SizedBox(width: 6),
Flexible(
child: Text(
label,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: colorScheme.primary,
),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 4),
Icon(Icons.arrow_drop_down, size: 18, color: colorScheme.primary),
],
),
),
);
}
}
/// Ouvre [OrgSelectorPage] comme bottom sheet modal.
///
/// Retourne l'[OrgSwitcherEntry] sélectionnée ou null si annulé.
Future<OrgSwitcherEntry?> showOrgSelector(
BuildContext context, {
bool required = false,
}) {
return Navigator.of(context).push<OrgSwitcherEntry>(
MaterialPageRoute(
builder: (_) => BlocProvider.value(
value: context.read<OrgSwitcherBloc>(),
child: OrgSelectorPage(required: required),
),
),
);
}

View File

@@ -605,6 +605,12 @@ class _OrganizationsPageState extends State<OrganizationsPage> with TickerProvid
return _buildEmptyState();
}
// Vérifier le rôle une seule fois pour toute la liste (UI-02)
final authState = context.read<AuthBloc>().state;
final canManageOrgs = authState is AuthAuthenticated &&
(authState.effectiveRole == UserRole.superAdmin ||
authState.effectiveRole == UserRole.orgAdmin);
return ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
@@ -617,9 +623,9 @@ class _OrganizationsPageState extends State<OrganizationsPage> with TickerProvid
child: OrganizationCard(
organization: org,
onTap: () => _showOrganizationDetails(org),
onEdit: () => _showEditOrganizationDialog(org),
onDelete: () => _confirmDeleteOrganization(org),
showActions: true,
onEdit: canManageOrgs ? () => _showEditOrganizationDialog(org) : null,
onDelete: canManageOrgs ? () => _confirmDeleteOrganization(org) : null,
showActions: canManageOrgs,
),
);
},