feat(authentication): add full event support
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
},
|
||||
"ui": {
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"singleProjectMode": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 50;
|
||||
objectVersion = 54;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
@@ -200,6 +200,7 @@
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
@@ -236,6 +237,7 @@
|
||||
};
|
||||
9740EEB61CF901F6004384FC /* Run Script */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
+7
-36
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@@ -14,49 +14,20 @@
|
||||
// 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/firebase_options.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
|
||||
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
||||
|
||||
final getIt = GetIt.I;
|
||||
|
||||
abstract class GetItInitializer {
|
||||
static Future<void> init() async {
|
||||
getIt
|
||||
..registerLazySingleton<AuthenticationRemoteDataSource>(
|
||||
MockSettings.isEnable()
|
||||
? () => AuthenticationMockDataSourceImpl(registeredAccounts: [
|
||||
Pair(
|
||||
AccountModel(
|
||||
uid: '1',
|
||||
emailVerified: true,
|
||||
isAnonymous: false,
|
||||
providerId: 'wyatt',
|
||||
email: 'toto@test.fr',
|
||||
),
|
||||
'toto1234',
|
||||
),
|
||||
Pair(
|
||||
AccountModel(
|
||||
uid: '2',
|
||||
emailVerified: false,
|
||||
isAnonymous: false,
|
||||
providerId: 'wyatt',
|
||||
email: 'tata@test.fr',
|
||||
),
|
||||
'tata1234',
|
||||
),
|
||||
])
|
||||
: () => AuthenticationFirebaseDataSourceImpl(
|
||||
firebaseAuth: FirebaseAuth.instance,
|
||||
googleSignIn: GoogleSignIn(
|
||||
clientId: DefaultFirebaseOptions.ios.iosClientId)),
|
||||
)
|
||||
..registerLazySingleton<AuthenticationCacheDataSource<int>>(
|
||||
() => AuthenticationCacheDataSourceImpl<int>(),
|
||||
);
|
||||
getIt.registerLazySingleton<AuthenticationRemoteDataSource<int>>(
|
||||
() => AuthenticationFirebaseDataSourceImpl<int>(
|
||||
firebaseAuth: FirebaseAuth.instance,
|
||||
googleSignIn:
|
||||
GoogleSignIn(clientId: DefaultFirebaseOptions.ios.iosClientId)),
|
||||
);
|
||||
|
||||
await getIt.allReady();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@@ -14,7 +14,6 @@
|
||||
// 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';
|
||||
@@ -83,14 +82,5 @@ class AppRouter {
|
||||
const SubPage(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/home/edit',
|
||||
name: EditProfilePage.pageName,
|
||||
pageBuilder: (context, state) => defaultTransition(
|
||||
context,
|
||||
state,
|
||||
const EditProfilePage(),
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@@ -15,41 +15,39 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
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:example_router/presentation/features/authentication/authentication_cubit.dart';
|
||||
import 'package:example_router/presentation/features/sign_in/blocs/custom_sign_in_cubit.dart';
|
||||
import 'package:example_router/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:wyatt_architecture/wyatt_architecture.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';
|
||||
|
||||
FutureOrResult<int?> onAccountChanges(
|
||||
AuthenticationRepository<int> repo,
|
||||
AuthChangeEvent? authEvent,
|
||||
) async {
|
||||
final id = Random().nextInt(1000);
|
||||
final token =
|
||||
await repo.getIdentityToken().fold((value) => value, (error) => 'null');
|
||||
// FutureOrResult<int?> onAccountChanges(
|
||||
// AuthenticationRepository<int> repo,
|
||||
// AuthChangeEvent? authEvent,
|
||||
// ) async {
|
||||
// final id = Random().nextInt(1000);
|
||||
// final token =
|
||||
// await repo.getIdentityToken().fold((value) => value, (error) => 'null');
|
||||
|
||||
debugPrint(
|
||||
'onAccountChanges: ${authEvent?.account}, type: ${authEvent.runtimeType}, token: $token, generatedId: $id');
|
||||
return Ok<int, AppException>(id);
|
||||
}
|
||||
// debugPrint(
|
||||
// 'onAccountChanges: ${authEvent?.account}, type: ${authEvent.runtimeType}, token: $token, generatedId: $id');
|
||||
// return Ok<int, AppException>(id);
|
||||
// }
|
||||
|
||||
class App extends StatelessWidget {
|
||||
final AuthenticationRepository<int> authenticationRepository =
|
||||
AuthenticationRepositoryImpl(
|
||||
authenticationCacheDataSource: getIt<AuthenticationCacheDataSource<int>>(),
|
||||
authenticationRemoteDataSource: getIt<AuthenticationRemoteDataSource>(),
|
||||
onAuthChange: onAccountChanges,
|
||||
authenticationRemoteDataSource:
|
||||
getIt<AuthenticationRemoteDataSource<int>>(),
|
||||
customPasswordValidator: const CustomPassword.pure(),
|
||||
extraSignUpInputs: [
|
||||
FormInput(
|
||||
@@ -66,8 +64,7 @@ class App extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
AuthenticationState<int>? previous;
|
||||
|
||||
final AuthenticationCubit<int> authenticationCubit =
|
||||
AuthenticationCubit(authenticationRepository: authenticationRepository);
|
||||
final AuthenticationCubit<int> authenticationCubit = ExampleAuthenticationCubit(authenticationRepository: authenticationRepository);
|
||||
|
||||
final GoRouter router = GoRouter(
|
||||
initialLocation: '/',
|
||||
@@ -119,7 +116,7 @@ class App extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
BlocProvider<SignInCubit<int>>(
|
||||
create: (_) => SignInCubit(
|
||||
create: (_) => CustomSignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
),
|
||||
),
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2023 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:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
|
||||
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
||||
|
||||
class ExampleAuthenticationCubit extends AuthenticationCubit<int> {
|
||||
ExampleAuthenticationCubit({required super.authenticationRepository});
|
||||
|
||||
@override
|
||||
FutureOrResult<int?> onReauthenticate(
|
||||
Result<Account, AppException> result) async {
|
||||
print('onReauthenticate');
|
||||
|
||||
return const Ok(1);
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOrResult<int?> onRefresh(Result<Account, AppException> result) {
|
||||
print('onRefresh');
|
||||
|
||||
return const Ok(1);
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOrResult<int?> onSignInFromCache(SessionWrapper<int> wrapper) {
|
||||
print('onSignInFromCache');
|
||||
|
||||
return const Ok(1);
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOrResult<void> onSignOut() {
|
||||
print('onSignOut');
|
||||
|
||||
return const Ok(null);
|
||||
}
|
||||
}
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
// 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(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
-136
@@ -1,136 +0,0 @@
|
||||
// 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(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+8
-9
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@@ -14,7 +14,6 @@
|
||||
// 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';
|
||||
@@ -30,7 +29,7 @@ class HomePage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Home'),
|
||||
title: Text('Home | ${context.account<AuthenticationCubit<int>, int>()?.email}'),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () =>
|
||||
@@ -44,8 +43,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, sessionWrapper) => Text(
|
||||
'Logged as ${sessionWrapper.session?.account.email} | GeneratedId is ${sessionWrapper.session?.data}'),
|
||||
unauthenticated: (context) =>
|
||||
const Text('Not logged (unauthenticated)'),
|
||||
unknown: (context) => const Text('Not logged (unknown)'),
|
||||
@@ -57,10 +56,10 @@ class HomePage extends StatelessWidget {
|
||||
onPressed: () => context.pushNamed(SubPage.pageName),
|
||||
child: const Text('Go to sub page'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => context.pushNamed(EditProfilePage.pageName),
|
||||
child: const Text('Go to edit profile page'),
|
||||
),
|
||||
// ElevatedButton(
|
||||
// onPressed: () => context.pushNamed(EditProfilePage.pageName),
|
||||
// child: const Text('Go to edit profile page'),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// Copyright (C) 2023 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:wyatt_architecture/src/domain/usecases/usecase.dart';
|
||||
import 'package:wyatt_architecture/src/core/exceptions/exceptions.dart';
|
||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
|
||||
import 'package:wyatt_type_utils/src/either/either_base.dart';
|
||||
import 'package:wyatt_form_bloc/src/domain/form/wyatt_form.dart';
|
||||
|
||||
class CustomSignInCubit extends SignInCubit<int> {
|
||||
CustomSignInCubit({
|
||||
required super.authenticationRepository,
|
||||
});
|
||||
|
||||
@override
|
||||
FutureOrResult<int?> onSignInWithEmailAndPassword(Result<Account, AppException> result, WyattForm form) {
|
||||
print('onSignInWithEmailAndPassword');
|
||||
|
||||
return const Ok(1);
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOrResult<int?> onSignInAnonymously(Result<Account, AppException> result, WyattForm form) {
|
||||
print('onSignInAnonymously');
|
||||
|
||||
return const Ok(1);
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOrResult<int?> onSignInWithGoogle(Result<Account, AppException> result, WyattForm form) {
|
||||
print('onSignInWithGoogle');
|
||||
|
||||
return const Ok(1);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
+19
-18
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@@ -14,33 +14,34 @@
|
||||
// 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 'package:example_router/core/constants/form_field.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:wyatt_architecture/wyatt_architecture.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 CustomSignUpCubit extends SignUpCubit<int>{
|
||||
class CustomSignUpCubit extends SignUpCubit<int> {
|
||||
CustomSignUpCubit({
|
||||
required super.authenticationRepository,
|
||||
});
|
||||
|
||||
|
||||
@override
|
||||
FutureOrResult<void> onSignUpWithEmailAndPassword(
|
||||
Result<Account, AppException> result, WyattForm form) async {
|
||||
if (result.isOk) {
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
const id = -1;
|
||||
final confirmedPassword =
|
||||
form.valueOf<String?>(AppFormField.confirmedPassword);
|
||||
FutureOrResult<int?> onSignUpWithEmailAndPassword(Result<Account, AppException> result, WyattForm form) async {
|
||||
// if (result.isOk) {
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
// const id = -1;
|
||||
// final confirmedPassword =
|
||||
// form.valueOf<String?>(AppFormField.confirmedPassword);
|
||||
|
||||
debugPrint(
|
||||
'onSignUpSuccess: ${result.ok}, generatedId: $id, intFormData: $confirmedPassword');
|
||||
return const Ok<int, AppException>(id);
|
||||
}
|
||||
return const Ok(null);
|
||||
// debugPrint(
|
||||
// 'onSignUpSuccess: ${result.ok}, generatedId: $id, intFormData: $confirmedPassword');
|
||||
// return const Ok<int, AppException>(id);
|
||||
// }
|
||||
// return const Ok(null);
|
||||
print('onSignUpWithEmailAndPassword');
|
||||
|
||||
return const Ok(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
||||
Reference in New Issue
Block a user