Skip to content

Commit

Permalink
auth with all mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
aidaiym committed Jul 26, 2024
1 parent 3724dca commit cde701f
Show file tree
Hide file tree
Showing 26 changed files with 402 additions and 77 deletions.
38 changes: 38 additions & 0 deletions app/lib/app/data/repository/auth_repositoty_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,44 @@ final class AuthRepositoryImpl implements AuthRepository {
}
}

@override
Future<void> loginWithEmail(String email) async {
try {
await remoteDataSource.loginWithEmail(email);
} catch (e, s) {
MqCrashlytics.report(e, s);
log('signWithEmail: error: $e\n$s');
}
}

@override
Future<Either<UserEntity, Exception>> fetchSmsCode({
required String code,
required String languageCode,
required Gender gender,
}) async {
try {
final res = await remoteDataSource.fetchSmsCode(code: code, languageCode: languageCode, gender: gender);

return res.fold(
Left.new,
(r) {
final userEntity = UserEntity(
accessToken: r.accessToken,
username: r.username,
gender: r.gender,
localeCode: r.localeCode,
);
return Right(userEntity);
},
);
} catch (e, s) {
log('signWithemail: error: $e\n$s');
MqCrashlytics.report(e, s);
return Left(AuthenticationExc(message: e.toString()));
}
}

@override
Future<Either<UserEntity, Exception>> signWithGoogle(
String languageCode,
Expand Down
2 changes: 2 additions & 0 deletions app/lib/app/domain/domain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ export 'usecase/ser_user_data_user_case.dart';
export 'usecase/patch_gender_user_case.dart';
export 'usecase/patch_locale_code_use_case.dart';
export 'usecase/logout_use_case.dart';
export 'usecase/email_login_usecase.dart';
export 'usecase/fetch_sms_code_use_case.dart';
export 'entity/user_entity.dart';
export 'entity/user_data_entity.dart';
8 changes: 8 additions & 0 deletions app/lib/app/domain/repository/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import 'package:my_quran/core/core.dart';
abstract class AuthRepository {
UserEntity? get init;

Future<void> loginWithEmail(String email);

Future<Either<UserEntity, Exception>> fetchSmsCode({
required String code,
required String languageCode,
required Gender gender,
});

Future<Either<UserEntity, Exception>> signWithGoogle(
String languageCode,
Gender gender,
Expand Down
13 changes: 13 additions & 0 deletions app/lib/app/domain/usecase/email_login_usecase.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:meta/meta.dart';
import 'package:my_quran/app/app.dart';

@immutable
final class EmailLoginUseCase {
const EmailLoginUseCase(this.repository);

final AuthRepository repository;

Future<void> call(String email) {
return repository.loginWithEmail(email);
}
}
22 changes: 22 additions & 0 deletions app/lib/app/domain/usecase/fetch_sms_code_use_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:meta/meta.dart';
import 'package:my_quran/app/app.dart';
import 'package:my_quran/core/core.dart';

@immutable
final class FetchSmsCodeUseCase {
const FetchSmsCodeUseCase(this.repository);

final AuthRepository repository;

Future<Either<UserEntity, Exception>> call({
required String code,
required String languageCode,
required Gender gender,
}) {
return repository.fetchSmsCode(
code: code,
languageCode: languageCode,
gender: gender,
);
}
}
25 changes: 25 additions & 0 deletions app/lib/app/presentation/cubit/auth_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class AuthCubit extends Cubit<AuthState> {
this.patchGenderUseCase,
this.patchLocaleCodeUseCase,
this.logoutUseCase,
this.loginUsecase,
this.fetchSmsCodeUseCase,
) : super(AuthState(user: getInitialUserUseCase.call));

final GetInitialUserUseCase getInitialUserUseCase;
Expand All @@ -26,6 +28,29 @@ class AuthCubit extends Cubit<AuthState> {
final PatchGenderUseCase patchGenderUseCase;
final PatchLocaleCodeUseCase patchLocaleCodeUseCase;
final LogoutUseCase logoutUseCase;
final EmailLoginUseCase loginUsecase;
final FetchSmsCodeUseCase fetchSmsCodeUseCase;

Future<void> login(String email) async {
try {
await loginUsecase(email);
} catch (e) {
emit(state.copyWith(exception: Exception(e)));
}
}

Future<AuthState> fetchSmsCode(String code) async {
final user = await fetchSmsCodeUseCase(
code: code,
languageCode: state.currentLocale.languageCode,
gender: state.gender,
);
user.fold(
(l) => emit(state.copyWith(exception: l)),
(r) => emit(state.copyWith(user: r)),
);
return state;
}

Future<AuthState> signInWithGoogle() async {
final user = await googleSignIn(
Expand Down
2 changes: 2 additions & 0 deletions app/lib/app/presentation/view/app_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class MyApp extends StatelessWidget {
PatchGenderUseCase(context.read<AuthRepository>()),
PatchLocaleCodeUseCase(context.read<AuthRepository>()),
LogoutUseCase(context.read<AuthRepository>()),
EmailLoginUseCase(context.read<AuthRepository>()),
FetchSmsCodeUseCase(context.read<AuthRepository>()),
),
),
BlocProvider(
Expand Down
1 change: 1 addition & 0 deletions app/lib/components/components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export 'indicators/dot_indicator.dart';
export 'audio/seek_bar.dart';
export 'audio/audio_center_button.dart';
export 'alert/confirmation_dialog.dart';
export 'forms/custom_text_field.dart';
33 changes: 33 additions & 0 deletions app/lib/components/forms/custom_text_field.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';

class CustomTextFormField extends StatelessWidget {
const CustomTextFormField({
this.controller,
this.labelText,
this.obscureText = false,
this.suffixIcon,
this.validator,
super.key,
});

final bool obscureText;
final TextEditingController? controller;
final String? labelText;
final Widget? suffixIcon;
final String? Function(String?)? validator;

@override
Widget build(BuildContext context) {
return TextFormField(
controller: controller,
decoration: InputDecoration(
labelText: labelText,
border: const OutlineInputBorder(),
suffixIcon: suffixIcon,
errorMaxLines: 3,
),
obscureText: obscureText,
validator: validator,
);
}
}
10 changes: 8 additions & 2 deletions app/lib/config/router/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class AppRouter {
static const hatimRead = 'hatim-read';
static const login = 'login';
static const loginWihtSoccial = 'login-with-soccial';
static const verificationCode = 'verification-code';

static const settingsPage = 'settings';
static const langSettings = 'lang-settings';
Expand Down Expand Up @@ -55,7 +56,12 @@ final class AppRouter {
GoRoute(
path: '/$loginWihtSoccial',
name: loginWihtSoccial,
builder: (context, state) => const SignInView(),
builder: (context, state) => SignInView(),
),
GoRoute(
path: '/$verificationCode',
name: verificationCode,
builder: (context, state) => VerificationCodeView(),
),
GoRoute(
path: '/$devModeView',
Expand Down Expand Up @@ -114,7 +120,7 @@ final class AppRouter {
redirect: (context, state) {
final path = state.matchedLocation;
if (!context.read<AuthCubit>().isAuthedticated) {
if (!path.contains(devModeView) && !path.contains(loginWihtSoccial)) {
if (!path.contains(devModeView) && !path.contains(loginWihtSoccial) && !path.contains(verificationCode)) {
return '/$login';
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/core/analytics/mq_analytic_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class AnalyticKey {

// action
static const tapLogout = 'tap_logout';
static const tapLoginWithSoccial = 'tap_login_with_soccial';
static const tapLogin = 'tap_login';
static const tapPrivacyPolicy = 'tap_privacy_policy';
static const tapQuranReadSettings = 'tap_quran_read_settings';
static const showAmin = 'show_amin';
Expand Down
8 changes: 7 additions & 1 deletion app/lib/l10n/arb/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"recommendedVersionDescription": "نسخة جديدة من التطبيق متاحة.",
"remindMeLater": "ذكرني لاحقاً",
"updateNow": "تحديث الآن",
"hatimNotAvailable": "خاتم غير متاح"
"hatimNotAvailable": "خاتم غير متاح",
"enterEmailToLogin": "الرجاء إدخال بريدك الإلكتروني لتسجيل الدخول إلى التطبيق الخاص بنا.",
"email": "البريد الإلكتروني",
"emailRequired": "البريد الإلكتروني مطلوب.",
"invalidEmail": "يرجى إدخال عنوان بريد إلكتروني صالح.",
"signIn": "تسجيل الدخول",
"orContinueWith": "أو تابع مع"
}
8 changes: 7 additions & 1 deletion app/lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"recommendedVersionDescription": "A new version of the app is available.",
"remindMeLater": "Remind me later",
"updateNow": "Update now",
"hatimNotAvailable": "Hatim is not available."
"hatimNotAvailable": "Hatim is not available.",
"enterEmailToLogin": "Please enter your email to log in to our application.",
"email": "Email",
"emailRequired": "Email is required.",
"invalidEmail": "Please enter a valid email address.",
"signIn": "Sign in",
"orContinueWith": "Or continue with"
}
8 changes: 7 additions & 1 deletion app/lib/l10n/arb/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"recommendedVersionDescription": "Versi baru dari aplikasi tersedia.",
"remindMeLater": "Ingatkan saya nanti",
"updateNow": "Perbarui sekarang",
"hatimNotAvailable": "Hatim tidak tersedia."
"hatimNotAvailable": "Hatim tidak tersedia.",
"enterEmailToLogin": "Silakan masukkan email Anda untuk masuk ke aplikasi kami.",
"email": "Email",
"emailRequired": "Email diperlukan.",
"invalidEmail": "Silakan masukkan alamat email yang valid.",
"signIn": "Masuk",
"orContinueWith": "Atau lanjutkan dengan"
}
8 changes: 7 additions & 1 deletion app/lib/l10n/arb/app_kk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"recommendedVersionDescription": "Қолданбаның жаңа нұсқасы қолайлы.",
"remindMeLater": "Кейін еске салу",
"updateNow": "Қазір жаңарту",
"hatimNotAvailable": "Хатым жетімді емес."
"hatimNotAvailable": "Хатым жетімді емес.",
"enterEmailToLogin": "Біздің қолданбамызға кіру үшін emailңізді енгізіңіз.",
"email": "Электрондық пошта",
"emailRequired": "Электрондық пошта қажет.",
"invalidEmail": "Жарамды электрондық пошта мекенжайын енгізіңіз.",
"signIn": "Кіру",
"orContinueWith": "Немесе жалғастыру"
}
10 changes: 8 additions & 2 deletions app/lib/l10n/arb/app_ky.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"recommendedVersionDescription": "Колдонмонун жаңы версиясы жеткиликтүү",
"remindMeLater": "Кийинчерээк эстетип коюу",
"updateNow": "Азыр жаңыртуу",
"hatimNotAvailable": "Хатымга катышуу азырынча жеткиликтүү эмес."
}
"hatimNotAvailable": "Хатымга катышуу азырынча жеткиликтүү эмес.",
"enterEmailToLogin": "Тиркемеге кирүү үчүн электрондук почтаңызды жазыңыз.",
"email": "Электрондук почта",
"emailRequired": "Электрондук почтаңызды жазыңыз.",
"invalidEmail": "Туура электрондук почта дарегин киргизиңиз.",
"signIn": "Кирүү",
"orContinueWith": "Же"
}
8 changes: 7 additions & 1 deletion app/lib/l10n/arb/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"recommendedVersionDescription": "Доступна новая версия приложения.",
"remindMeLater": "Напомнить позже",
"updateNow": "Обновить сейчас",
"hatimNotAvailable": "Хатим недоступен."
"hatimNotAvailable": "Хатим недоступен.",
"enterEmailToLogin": "Введите ваш email для входа в приложение.",
"email": "Эл. почта",
"emailRequired": "Требуется электронная почта.",
"invalidEmail": "Пожалуйста, введите действующий адрес электронной почты.",
"signIn": "Войти",
"orContinueWith": "Или продолжить с"
}
8 changes: 7 additions & 1 deletion app/lib/l10n/arb/app_tr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"recommendedVersionDescription": "Uygulamanın yeni bir sürümü mevcut.",
"remindMeLater": "Daha sonra hatırlat",
"updateNow": "Şimdi güncelle",
"hatimNotAvailable": "Hatim mevcut değil."
"hatimNotAvailable": "Hatim mevcut değil.",
"enterEmailToLogin": "Uygulamamıza giriş yapmak için lütfen e-posta adresinizi girin.",
"email": "E-posta",
"emailRequired": "E-posta gereklidir.",
"invalidEmail": "Lütfen geçerli bir e-posta adresi girin.",
"signIn": "Giriş Yap",
"orContinueWith": "Veya ile devam et"
}
1 change: 1 addition & 0 deletions app/lib/modules/login/presentation/presentation.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export 'cubit/login_cubit.dart';
export 'view/login_view.dart';
export 'view/sign_in_view.dart';
export 'view/verification_code_view.dart';
export 'widgets/select_gender.dart';
export 'widgets/select_lang.dart';
Loading

0 comments on commit cde701f

Please sign in to comment.