docs(auth): add correct header
This commit is contained in:
		
							parent
							
								
									672aba7084
								
							
						
					
					
						commit
						5e83c9e74e
					
				@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: bootstrap.dart
 | 
			
		||||
// Created Date: 19/08/2022 15:05:17
 | 
			
		||||
// Last Modified: Fri Nov 11 2022
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'dart:async';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,20 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: form_field.dart
 | 
			
		||||
// Created Date: 19/08/2022 11:52:33
 | 
			
		||||
// Last Modified: 19/08/2022 16:35:39
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
abstract class AppFormField {
 | 
			
		||||
  static const oldPassword = 'oldPassword';
 | 
			
		||||
  static const confirmedPassword = 'confirmedPassword';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,19 @@
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
abstract class AppFormName {
 | 
			
		||||
  static const editProfile = 'editProfile';
 | 
			
		||||
}
 | 
			
		||||
@ -1,12 +1,20 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: router.dart
 | 
			
		||||
// Created Date: 19/08/2022 11:52:22
 | 
			
		||||
// Last Modified: 19/08/2022 16:39:07
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
//
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
//
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
//
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/presentation/features/edit_profile/edit_profile_page.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/home/home_page.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/sign_in/sign_in_page.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/sign_up/sign_up_page.dart';
 | 
			
		||||
@ -75,5 +83,14 @@ class AppRouter {
 | 
			
		||||
        const SubPage(),
 | 
			
		||||
      ),
 | 
			
		||||
    ),
 | 
			
		||||
    GoRoute(
 | 
			
		||||
      path: '/home/edit',
 | 
			
		||||
      name: EditProfilePage.pageName,
 | 
			
		||||
      pageBuilder: (context, state) => defaultTransition(
 | 
			
		||||
        context,
 | 
			
		||||
        state,
 | 
			
		||||
        const EditProfilePage(),
 | 
			
		||||
      ),
 | 
			
		||||
    ),
 | 
			
		||||
  ];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: app_bloc_observer.dart
 | 
			
		||||
// Created Date: 19/08/2022 12:02:23
 | 
			
		||||
// Last Modified: 19/08/2022 12:02:45
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:flutter/foundation.dart';
 | 
			
		||||
import 'package:flutter_bloc/flutter_bloc.dart';
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,32 @@
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
//
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
//
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
//
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/core/constants/form_field.dart';
 | 
			
		||||
import 'package:example_router/core/constants/form_name.dart';
 | 
			
		||||
import 'package:example_router/core/utils/custom_password.dart';
 | 
			
		||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
 | 
			
		||||
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
 | 
			
		||||
 | 
			
		||||
abstract class AppForms {
 | 
			
		||||
  static WyattForm getEditProfileForm() => WyattFormImpl(
 | 
			
		||||
        [
 | 
			
		||||
          FormInput(AuthFormField.email, const Email.pure()),
 | 
			
		||||
          FormInput(AuthFormField.password, const CustomPassword.pure()),
 | 
			
		||||
          FormInput(AppFormField.oldPassword, const CustomPassword.pure()),
 | 
			
		||||
        ],
 | 
			
		||||
        name: AppFormName.editProfile,
 | 
			
		||||
      );
 | 
			
		||||
}
 | 
			
		||||
@ -1,3 +1,19 @@
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/bootstrap.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/app/app.dart';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: app.dart
 | 
			
		||||
// Created Date: 19/08/2022 12:05:38
 | 
			
		||||
// Last Modified: Sat Dec 03 2022
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
//
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
//
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
//
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'dart:async';
 | 
			
		||||
import 'dart:math';
 | 
			
		||||
@ -14,6 +21,7 @@ import 'package:example_router/core/constants/form_field.dart';
 | 
			
		||||
import 'package:example_router/core/dependency_injection/get_it.dart';
 | 
			
		||||
import 'package:example_router/core/routes/router.dart';
 | 
			
		||||
import 'package:example_router/core/utils/custom_password.dart';
 | 
			
		||||
import 'package:example_router/core/utils/forms.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_bloc/flutter_bloc.dart';
 | 
			
		||||
import 'package:go_router/go_router.dart';
 | 
			
		||||
@ -69,7 +77,7 @@ class App extends StatelessWidget {
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    AuthenticationState? previous;
 | 
			
		||||
    AuthenticationState<int>? previous;
 | 
			
		||||
 | 
			
		||||
    final AuthenticationCubit<int> authenticationCubit =
 | 
			
		||||
        AuthenticationCubit(authenticationRepository: authenticationRepository);
 | 
			
		||||
@ -85,29 +93,18 @@ class App extends StatelessWidget {
 | 
			
		||||
      redirect: (context, state) {
 | 
			
		||||
        final authState = authenticationCubit.state;
 | 
			
		||||
 | 
			
		||||
        if (authState != previous) {
 | 
			
		||||
        if (authState.status != previous?.status) {
 | 
			
		||||
          previous = authState;
 | 
			
		||||
          // Check if current user is logged in
 | 
			
		||||
          final loggedIn =
 | 
			
		||||
              authState.status == AuthenticationStatus.authenticated;
 | 
			
		||||
 | 
			
		||||
          // Checking if current path is onboarding or not
 | 
			
		||||
          final isOnboarding = AppRouter.publicRoutes.contains(state.subloc);
 | 
			
		||||
 | 
			
		||||
          if (!loggedIn) {
 | 
			
		||||
          if (authState.status == AuthenticationStatus.unauthenticated) {
 | 
			
		||||
            debugPrint('Not logged');
 | 
			
		||||
            if (isOnboarding) {
 | 
			
		||||
              return null;
 | 
			
		||||
            } else {
 | 
			
		||||
            if (!isOnboarding) {
 | 
			
		||||
              return '/';
 | 
			
		||||
            }
 | 
			
		||||
          } else {
 | 
			
		||||
          } else if (authState.status == AuthenticationStatus.authenticated) {
 | 
			
		||||
            debugPrint('Logged');
 | 
			
		||||
            if (isOnboarding) {
 | 
			
		||||
            return '/home';
 | 
			
		||||
            } else {
 | 
			
		||||
              return null;
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
@ -116,9 +113,13 @@ class App extends StatelessWidget {
 | 
			
		||||
 | 
			
		||||
    return MultiRepositoryProvider(
 | 
			
		||||
      providers: [
 | 
			
		||||
        RepositoryProvider<AuthenticationRepository>.value(
 | 
			
		||||
        RepositoryProvider<AuthenticationRepository<int>>.value(
 | 
			
		||||
          value: authenticationRepository,
 | 
			
		||||
        ),
 | 
			
		||||
        RepositoryProvider<FormRepository>(
 | 
			
		||||
          create: (context) =>
 | 
			
		||||
              FormRepositoryImpl()..registerForm(AppForms.getEditProfileForm()),
 | 
			
		||||
        ),
 | 
			
		||||
      ],
 | 
			
		||||
      child: MultiBlocProvider(
 | 
			
		||||
        providers: [
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,74 @@
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/core/constants/form_field.dart';
 | 
			
		||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
 | 
			
		||||
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
 | 
			
		||||
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
 | 
			
		||||
 | 
			
		||||
class EditProfileCubit extends FormDataCubitImpl {
 | 
			
		||||
  final AuthenticationRepository<int> authenticationRepository;
 | 
			
		||||
 | 
			
		||||
  EditProfileCubit(
 | 
			
		||||
    super._formRepository,
 | 
			
		||||
    super._formName, {
 | 
			
		||||
    required this.authenticationRepository,
 | 
			
		||||
  }) : super();
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Future<void> submit() async {
 | 
			
		||||
    emit(
 | 
			
		||||
      state.copyWith(
 | 
			
		||||
        status: FormStatus.submissionInProgress,
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
    final user = (await authenticationRepository.getAccount()).ok;
 | 
			
		||||
 | 
			
		||||
    final form = state.form;
 | 
			
		||||
    final email = form.valueOf<String?>(AuthFormField.email);
 | 
			
		||||
    final oldPassword = form.valueOf<String?>(AppFormField.oldPassword);
 | 
			
		||||
    final newPassword = form.valueOf<String?>(AuthFormField.password);
 | 
			
		||||
 | 
			
		||||
    if (email.isNullOrEmpty ||
 | 
			
		||||
        oldPassword.isNullOrEmpty ||
 | 
			
		||||
        newPassword.isNullOrEmpty) {
 | 
			
		||||
      emit(
 | 
			
		||||
        state.copyWith(
 | 
			
		||||
          errorMessage: 'An error occured while retrieving data from the form.',
 | 
			
		||||
          status: FormStatus.submissionFailure,
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      // await authenticationRepository.signInWithEmailAndPassword(
 | 
			
		||||
      //   email: user?.email ?? '',
 | 
			
		||||
      //   password: oldPassword ?? '',
 | 
			
		||||
      // );
 | 
			
		||||
      // await authenticationRepository.reauthenticateWithCredential();
 | 
			
		||||
      await authenticationRepository.updateEmail(email: email!);
 | 
			
		||||
      await authenticationRepository.updatePassword(password: newPassword!);
 | 
			
		||||
    } on Exception catch (e) {
 | 
			
		||||
      emit(
 | 
			
		||||
        state.copyWith(
 | 
			
		||||
          status: FormStatus.submissionFailure,
 | 
			
		||||
          errorMessage: e.toString(),
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
    emit(state.copyWith(status: FormStatus.submissionSuccess));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,61 @@
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
//
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
//
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
//
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/core/constants/form_name.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/edit_profile/blocs/edit_profile_cubit.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/edit_profile/widgets/edit_profile_form.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_bloc/flutter_bloc.dart';
 | 
			
		||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
 | 
			
		||||
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
 | 
			
		||||
 | 
			
		||||
class EditProfilePage extends StatelessWidget {
 | 
			
		||||
  const EditProfilePage({Key? key}) : super(key: key);
 | 
			
		||||
 | 
			
		||||
  static String pageName = 'EditProfile';
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      appBar: AppBar(title: const Text('Edit Profile')),
 | 
			
		||||
      body: Padding(
 | 
			
		||||
        padding: const EdgeInsets.all(8),
 | 
			
		||||
        child: SingleChildScrollView(
 | 
			
		||||
          child: BlocProvider<EditProfileCubit>(
 | 
			
		||||
            create: (context) => EditProfileCubit(
 | 
			
		||||
              context.read<FormRepository>(),
 | 
			
		||||
              AppFormName.editProfile,
 | 
			
		||||
              authenticationRepository:
 | 
			
		||||
                  context.read<AuthenticationRepository<int>>(),
 | 
			
		||||
            )..dataChanged<String?>(
 | 
			
		||||
                AuthFormField.email,
 | 
			
		||||
                Email.dirty(
 | 
			
		||||
                  context
 | 
			
		||||
                          .read<AuthenticationCubit<int>>()
 | 
			
		||||
                          .state
 | 
			
		||||
                          .accountWrapper
 | 
			
		||||
                          ?.account
 | 
			
		||||
                          ?.email ??
 | 
			
		||||
                      '',
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
            child: const EditProfileForm(),
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,136 @@
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
//
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
//
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
//
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/core/constants/form_field.dart';
 | 
			
		||||
import 'package:example_router/core/utils/custom_password.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/edit_profile/blocs/edit_profile_cubit.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_bloc/flutter_bloc.dart';
 | 
			
		||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
 | 
			
		||||
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
 | 
			
		||||
 | 
			
		||||
class _EmailInput extends StatelessWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return InputBuilderTextController<EditProfileCubit, String?, void>(
 | 
			
		||||
      field: AuthFormField.email,
 | 
			
		||||
      builder: ((context, cubit, state, field, input, controller, extra) {
 | 
			
		||||
        return TextField(
 | 
			
		||||
          onChanged: (email) => cubit.dataChanged<String?>(
 | 
			
		||||
              AuthFormField.email, Email.dirty(email)),
 | 
			
		||||
          keyboardType: TextInputType.emailAddress,
 | 
			
		||||
          controller: controller,
 | 
			
		||||
          decoration: InputDecoration(
 | 
			
		||||
            labelText: 'Email',
 | 
			
		||||
            helperText: '',
 | 
			
		||||
            errorText: input.validator.invalid ? 'Invalid email' : null,
 | 
			
		||||
          ),
 | 
			
		||||
        );
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _OldPasswordInput extends StatelessWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return InputBuilder<EditProfileCubit>(
 | 
			
		||||
      field: AppFormField.oldPassword,
 | 
			
		||||
      builder: ((context, cubit, state, field, input) {
 | 
			
		||||
        return TextField(
 | 
			
		||||
          onChanged: (pwd) => cubit.dataChanged<String?>(
 | 
			
		||||
              AppFormField.oldPassword, CustomPassword.dirty(pwd)),
 | 
			
		||||
          obscureText: true,
 | 
			
		||||
          decoration: InputDecoration(
 | 
			
		||||
            labelText: 'Old Password',
 | 
			
		||||
            helperText: '',
 | 
			
		||||
            errorText: input.validator.invalid ? 'Invalid password' : null,
 | 
			
		||||
          ),
 | 
			
		||||
        );
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _NewPasswordInput extends StatelessWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return InputBuilder<EditProfileCubit>(
 | 
			
		||||
      field: AuthFormField.password,
 | 
			
		||||
      builder: ((context, cubit, state, field, input) {
 | 
			
		||||
        return TextField(
 | 
			
		||||
          onChanged: (pwd) => cubit.dataChanged<String?>(
 | 
			
		||||
              AuthFormField.password, CustomPassword.dirty(pwd)),
 | 
			
		||||
          obscureText: true,
 | 
			
		||||
          decoration: InputDecoration(
 | 
			
		||||
            labelText: 'New Password',
 | 
			
		||||
            helperText: '',
 | 
			
		||||
            errorText: input.validator.invalid ? 'Invalid password' : null,
 | 
			
		||||
          ),
 | 
			
		||||
        );
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _EditButton extends StatelessWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return SubmitBuilder<EditProfileCubit>(
 | 
			
		||||
      builder: ((context, cubit, status) {
 | 
			
		||||
        return status.isSubmissionInProgress
 | 
			
		||||
            ? const CircularProgressIndicator()
 | 
			
		||||
            : ElevatedButton(
 | 
			
		||||
                onPressed: status.isValidated ? () => cubit.submit() : null,
 | 
			
		||||
                child: const Text('Edit profile'),
 | 
			
		||||
              );
 | 
			
		||||
      }),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class EditProfileForm extends StatelessWidget {
 | 
			
		||||
  const EditProfileForm({Key? key}) : super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return BlocListener<EditProfileCubit, FormDataState>(
 | 
			
		||||
      listener: (context, state) {
 | 
			
		||||
        if (state.status == FormStatus.submissionFailure) {
 | 
			
		||||
          ScaffoldMessenger.of(context)
 | 
			
		||||
            ..hideCurrentSnackBar()
 | 
			
		||||
            ..showSnackBar(
 | 
			
		||||
              SnackBar(content: Text(state.errorMessage ?? 'Edit Failure')),
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
      },
 | 
			
		||||
      child: SingleChildScrollView(
 | 
			
		||||
        child: Column(
 | 
			
		||||
          crossAxisAlignment: CrossAxisAlignment.center,
 | 
			
		||||
          children: [
 | 
			
		||||
            _EmailInput(),
 | 
			
		||||
            const SizedBox(height: 8),
 | 
			
		||||
            _OldPasswordInput(),
 | 
			
		||||
            const SizedBox(height: 8),
 | 
			
		||||
            _NewPasswordInput(),
 | 
			
		||||
            const SizedBox(height: 16),
 | 
			
		||||
            _EditButton(),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -1,12 +1,20 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: home_page.dart
 | 
			
		||||
// Created Date: 19/08/2022 14:38:24
 | 
			
		||||
// Last Modified: Wed Nov 09 2022
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
//
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
//
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
//
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/presentation/features/edit_profile/edit_profile_page.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/sub/sub_page.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_bloc/flutter_bloc.dart';
 | 
			
		||||
@ -25,7 +33,8 @@ class HomePage extends StatelessWidget {
 | 
			
		||||
        title: const Text('Home'),
 | 
			
		||||
        actions: [
 | 
			
		||||
          IconButton(
 | 
			
		||||
              onPressed: () => context.read<AuthenticationCubit<int>>().signOut(),
 | 
			
		||||
              onPressed: () =>
 | 
			
		||||
                  context.read<AuthenticationCubit<int>>().signOut(),
 | 
			
		||||
              icon: const Icon(Icons.logout_rounded))
 | 
			
		||||
        ],
 | 
			
		||||
      ),
 | 
			
		||||
@ -35,8 +44,8 @@ class HomePage extends StatelessWidget {
 | 
			
		||||
          child: Column(
 | 
			
		||||
            children: [
 | 
			
		||||
              AuthenticationBuilder<int>(
 | 
			
		||||
                authenticated: (context, accountWrapper) =>
 | 
			
		||||
                    Text('Logged as ${accountWrapper.account?.email} | GeneratedId is ${accountWrapper.data}'),
 | 
			
		||||
                authenticated: (context, accountWrapper) => Text(
 | 
			
		||||
                    'Logged as ${accountWrapper.account?.email} | GeneratedId is ${accountWrapper.data}'),
 | 
			
		||||
                unauthenticated: (context) =>
 | 
			
		||||
                    const Text('Not logged (unauthenticated)'),
 | 
			
		||||
                unknown: (context) => const Text('Not logged (unknown)'),
 | 
			
		||||
@ -46,7 +55,12 @@ class HomePage extends StatelessWidget {
 | 
			
		||||
              ),
 | 
			
		||||
              ElevatedButton(
 | 
			
		||||
                onPressed: () => context.pushNamed(SubPage.pageName),
 | 
			
		||||
                  child: const Text('Go to sub page')),
 | 
			
		||||
                child: const Text('Go to sub page'),
 | 
			
		||||
              ),
 | 
			
		||||
              ElevatedButton(
 | 
			
		||||
                onPressed: () => context.pushNamed(EditProfilePage.pageName),
 | 
			
		||||
                child: const Text('Go to edit profile page'),
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: sign_in_page.dart
 | 
			
		||||
// Created Date: 19/08/2022 12:41:42
 | 
			
		||||
// Last Modified: 19/08/2022 15:26:36
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/presentation/features/sign_in/widgets/sign_in_form.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: sign_in_form.dart
 | 
			
		||||
// Created Date: 19/08/2022 15:24:37
 | 
			
		||||
// Last Modified: Sat Dec 03 2022
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/core/utils/custom_password.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: sign_up_page.dart
 | 
			
		||||
// Created Date: 19/08/2022 12:41:27
 | 
			
		||||
// Last Modified: 19/08/2022 14:58:51
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/presentation/features/sign_up/widgets/sign_up_form.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: sign_up_form.dart
 | 
			
		||||
// Created Date: 19/08/2022 14:41:08
 | 
			
		||||
// Last Modified: Sat Dec 03 2022
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/core/constants/form_field.dart';
 | 
			
		||||
import 'package:example_router/core/utils/custom_password.dart';
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: sub_page.dart
 | 
			
		||||
// Created Date: 19/08/2022 16:10:05
 | 
			
		||||
// Last Modified: Wed Nov 09 2022
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_bloc/flutter_bloc.dart';
 | 
			
		||||
@ -24,7 +31,10 @@ class SubPage extends StatelessWidget {
 | 
			
		||||
        actions: [
 | 
			
		||||
          IconButton(
 | 
			
		||||
              onPressed: () => context.read<AuthenticationCubit<int>>().signOut(),
 | 
			
		||||
              icon: const Icon(Icons.logout_rounded))
 | 
			
		||||
              icon: const Icon(Icons.logout_rounded)),
 | 
			
		||||
          IconButton(
 | 
			
		||||
              onPressed: () => context.read<AuthenticationRepository<int>>().refresh(),
 | 
			
		||||
              icon: const Icon(Icons.refresh))
 | 
			
		||||
        ],
 | 
			
		||||
      ),
 | 
			
		||||
      body: const Padding(
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,18 @@
 | 
			
		||||
// Author: Hugo Pointcheval
 | 
			
		||||
// Email: git@pcl.ovh
 | 
			
		||||
// -----
 | 
			
		||||
// File: welcome_page.dart
 | 
			
		||||
// Created Date: 19/08/2022 12:33:21
 | 
			
		||||
// Last Modified: Wed Nov 09 2022
 | 
			
		||||
// -----
 | 
			
		||||
// Copyright (c) 2022
 | 
			
		||||
// Copyright (C) 2022 WYATT GROUP
 | 
			
		||||
// Please see the AUTHORS file for details.
 | 
			
		||||
// 
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// any later version.
 | 
			
		||||
// 
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
// 
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:example_router/presentation/features/sign_in/sign_in_page.dart';
 | 
			
		||||
import 'package:example_router/presentation/features/sign_up/sign_up_page.dart';
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user