petitspas/frontend/lib/config/app_router.dart
Julien Martin 18f3a7f276 feat(#127): mot de passe oublié — flux complet (API + web + e-mail)
- API publique POST /auth/forgot-password et /auth/reset-password (jeton
  password_reset_*, anti-énumération, e-mail P'titsPas)
- BDD: colonnes password_reset_token / password_reset_expires + index
- Front: écrans /forgot-password, /reset-password, lien login, mutualisation
  formulaires par token
- Template e-mail + alignement couleur; tests unitaires (auth, mail)

Merge depuis develop: branche feature/127.

Made-with: Cursor
2026-04-24 12:53:42 +02:00

160 lines
6.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
// Models
import '../models/user_registration_data.dart';
import '../models/am_registration_data.dart';
// Screens
import '../screens/auth/login_screen.dart';
import '../screens/auth/register_choice_screen.dart';
import '../screens/auth/parent_register_step1_screen.dart';
import '../screens/auth/parent_register_step2_screen.dart';
import '../screens/auth/parent_register_step3_screen.dart';
import '../screens/auth/parent_register_step4_screen.dart';
import '../screens/auth/parent_register_step5_screen.dart';
import '../screens/auth/am_register_step1_screen.dart';
import '../screens/auth/am_register_step2_screen.dart';
import '../screens/auth/am_register_step3_screen.dart';
import '../screens/auth/am_register_step4_screen.dart';
import '../screens/auth/create_password_screen.dart';
import '../screens/auth/forgot_password_screen.dart';
import '../screens/auth/reset_password_screen.dart';
import '../screens/home/home_screen.dart';
import '../screens/administrateurs/admin_dashboardScreen.dart';
import '../screens/gestionnaire/gestionnaire_dashboard_screen.dart';
import '../screens/home/parent_screen/ParentDashboardScreen.dart';
import '../screens/am/am_dashboard_screen.dart';
import '../screens/legal/privacy_page.dart';
import '../screens/legal/legal_page.dart';
import '../screens/unknown_screen.dart';
// --- Provider Instances ---
// It's generally better to provide these higher up the widget tree if possible,
// or ensure they are created only once.
// For ShellRoute, creating them here and passing via .value is common.
final userRegistrationDataNotifier = UserRegistrationData();
final amRegistrationDataNotifier = AmRegistrationData();
class AppRouter {
static final GoRouter router = GoRouter(
initialLocation: '/login',
errorBuilder: (context, state) => const UnknownScreen(),
debugLogDiagnostics: true,
routes: <RouteBase>[
GoRoute(
path: '/login',
builder: (BuildContext context, GoRouterState state) => const LoginScreen(),
),
GoRoute(
path: '/register-choice',
builder: (BuildContext context, GoRouterState state) => const RegisterChoiceScreen(),
),
GoRoute(
path: '/create-password',
builder: (BuildContext context, GoRouterState state) =>
CreatePasswordScreen(token: state.uri.queryParameters['token']),
),
GoRoute(
path: '/forgot-password',
builder: (BuildContext context, GoRouterState state) => const ForgotPasswordScreen(),
),
GoRoute(
path: '/reset-password',
builder: (BuildContext context, GoRouterState state) =>
ResetPasswordScreen(token: state.uri.queryParameters['token']),
),
GoRoute(
path: '/home',
builder: (BuildContext context, GoRouterState state) => const HomeScreen(),
),
GoRoute(
path: '/admin-dashboard',
builder: (BuildContext context, GoRouterState state) => const AdminDashboardScreen(),
),
GoRoute(
path: '/gestionnaire-dashboard',
builder: (BuildContext context, GoRouterState state) => const GestionnaireDashboardScreen(),
),
GoRoute(
path: '/parent-dashboard',
builder: (BuildContext context, GoRouterState state) => const ParentDashboardScreen(),
),
GoRoute(
path: '/am-dashboard',
builder: (BuildContext context, GoRouterState state) =>
const AmDashboardScreen(),
),
GoRoute(
path: '/privacy',
builder: (BuildContext context, GoRouterState state) => const PrivacyPage(),
),
GoRoute(
path: '/legal',
builder: (BuildContext context, GoRouterState state) => const LegalPage(),
),
// --- Parent Registration Flow ---
ShellRoute(
builder: (context, state, child) {
return ChangeNotifierProvider<UserRegistrationData>.value(
value: userRegistrationDataNotifier,
child: child,
);
},
routes: <RouteBase>[
GoRoute(
path: '/parent-register-step1',
builder: (BuildContext context, GoRouterState state) => const ParentRegisterStep1Screen(),
),
GoRoute(
path: '/parent-register-step2',
builder: (BuildContext context, GoRouterState state) => const ParentRegisterStep2Screen(),
),
GoRoute(
path: '/parent-register-step3',
builder: (BuildContext context, GoRouterState state) => const ParentRegisterStep3Screen(),
),
GoRoute(
path: '/parent-register-step4',
builder: (BuildContext context, GoRouterState state) => const ParentRegisterStep4Screen(),
),
GoRoute(
path: '/parent-register-step5',
builder: (BuildContext context, GoRouterState state) => const ParentRegisterStep5Screen(),
),
],
),
// --- AM (Assistante Maternelle) Registration Flow ---
ShellRoute(
builder: (context, state, child) {
return ChangeNotifierProvider<AmRegistrationData>.value(
value: amRegistrationDataNotifier,
child: child,
);
},
routes: <RouteBase>[
GoRoute(
path: '/am-register-step1',
builder: (BuildContext context, GoRouterState state) => const AmRegisterStep1Screen(),
),
GoRoute(
path: '/am-register-step2',
builder: (BuildContext context, GoRouterState state) => const AmRegisterStep2Screen(),
),
GoRoute(
path: '/am-register-step3',
builder: (BuildContext context, GoRouterState state) => const AmRegisterStep3Screen(),
),
GoRoute(
path: '/am-register-step4',
builder: (BuildContext context, GoRouterState state) => const AmRegisterStep4Screen(),
),
],
),
],
);
}