Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email phone sync #1815

Merged
merged 27 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added mobile/assets/images/email_link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion mobile/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,18 @@
"languages": "Languages",
"dataProvider":"Data Provider: {placeholder}",
"reDOLesson": "Re-do lesson",
"reDoQuiz": "Re-do quiz"
"reDoQuiz": "Re-do quiz",
"addYourEmail":"Add your Email",
"yourEmailHasBeenAdded":"Your Email has been added",
"add":"Add",
"skip":"skip",
"oopsSomethingWentWrongPleaseTryAgainLater":"Oops something went wrong! Please try again later",
"tryAgainLater":"Try again later",
"yourEmailIsAlreadyRegistered":"Your Email is already registered",
"weAreShufflingThingsAroundForYou":"We are shuffling things around for you.....",
"youWouldBeRequiredToAddYourEmailToYourProfileOnTheMobileAppToEnableYouAccessThe" :" You would be required to add your email to your profile on the mobile app to enable you access the ",
"withOneAccount":" with one account.",
"addMyEmail":"Add my email",
"remindMeLater":"Remind me later"

}
16 changes: 14 additions & 2 deletions mobile/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,17 @@
"languages": "Langues",
"dataProvider":"Fournisseur de données: {placeholder}",
"reDOLesson": "Refaire la leçon",
"reDoQuiz": "Refaire le quiz"
}
"reDoQuiz": "Refaire le quiz",
"addYourEmail":"Ajoutez votre e-mail",
"yourEmailHasBeenAdded":"Votre e-mail a été ajouté",
"add":"ajouter",
"skip":"sauter",
"oopsSomethingWentWrongPleaseTryAgainLater":"Oups quelque chose a mal tourné! Veuillez réessayer plus tard",
"tryAgainLater":"réessayez plus tard",
"yourEmailIsAlreadyRegistered":"Votre e-mail est déjà enregistré",
"weAreShufflingThingsAroundForYou":"Nous mélangeons des choses pour vous .....",
"youWouldBeRequiredToAddYourEmailToYourProfileOnTheMobileAppToEnableYouAccessThe" : " Vous devrez ajouter votre e-mail à votre profil sur l'application mobile pour vous permettre d'accéder au ",
"withOneAccount":" avec un compte.",
"addMyEmail":"ajouter mon e-mail",
"remindMeLater":"Rappelez-moi plus tard"
}
17 changes: 15 additions & 2 deletions mobile/lib/l10n/app_lg.arb
Original file line number Diff line number Diff line change
Expand Up @@ -343,5 +343,18 @@
"languages": "Ennimi",
"dataProvider":"Ensibuko yo'bubaka: {placeholder}",
"reDOLesson": "Ddiŋŋana essomo",
"reDoQuiz": "Ddiŋŋana Ekibuuzo"
}
"reDoQuiz": "Ddiŋŋana Ekibuuzo",
"addYourEmail":"Yongerako Email yo",
"yourEmailHasBeenAdded":"Email yo eyongezeddwayo",
"add":"Okwongerako",
"skip":"simbula",
"oopsSomethingWentWrongPleaseTryAgainLater":"Oops waliwo ekikyamu! Nsaba oddemu ogezeeko oluvannyuma",
"tryAgainLater":"Ddamu gezaako oluvannyuma",
"yourEmailIsAlreadyRegistered":"Email yo yawandiisibwa dda",
"weAreShufflingThingsAroundForYou":"Tutabula ebintu ku lulwo.....",
"youWouldBeRequiredToAddYourEmailToYourProfileOnTheMobileAppToEnableYouAccessThe":" Wandibadde weetaaga okwongera email yo ku profile yo ku app y'essimu okukusobozesa okuyingira mu ",
"withOneAccount":" nga erina akawunti emu.",
"addMyEmail":"Yongerako email yange",
"remindMeLater":"Nzijukiza oluvannyuma"

}
14 changes: 13 additions & 1 deletion mobile/lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,17 @@
"languageChangedSuccessfully": "Idioma alterado com sucesso {placeholder}",
"ok": "OK",
"languages": "Idiomas",
"dataProvider":"Fornecedor de dados: {placeholder}"
"dataProvider":"Fornecedor de dados: {placeholder}",
"addYourEmail":"Adicione seu e-mail",
"yourEmailHasBeenAdded":"Seu e-mail foi adicionado",
"add":"Adicionar",
"skip":"pular",
"oopsSomethingWentWrongPleaseTryAgainLater":"Opa, algo deu errado! Tente novamente mais tarde",
"tryAgainLater":"Tente novamente mais tarde",
"yourEmailIsAlreadyRegistered":"Seu e-mail já está cadastrado",
"weAreShufflingThingsAroundForYou":"Estamos embaralhando as coisas para você.....",
"youWouldBeRequiredToAddYourEmailToYourProfileOnTheMobileAppToEnableYouAccessThe":" Você deverá adicionar seu e-mail ao seu perfil no aplicativo móvel para permitir o acesso ao ",
"withOneAccount":" com uma conta.",
"addMyEmail":"Adicionar meu e-mail",
"remindMeLater":"Lembre-me mais tarde"
}
14 changes: 13 additions & 1 deletion mobile/lib/l10n/app_sw.arb
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,17 @@
"dataProvider":"Mtoa Huduma: {placeholder}",
"reDOLesson": "Fanya tena somo",
"reDoQuiz": "Fanya tena mtihani",
"continueLearning" : "Endelea kujifunza"
"continueLearning" : "Endelea kujifunza",
"addYourEmail":"Ongeza Barua pepe yako",
"yourEmailHasBeenAdded":"Barua pepe yako imeongezwa",
"add":"Ongeza",
"skip":"ruka",
"oopsSomethingWentWrongPleaseTryAgainLater":"Lo kuna hitilafu! Tafadhali jaribu tena baadaye",
"tryAgainLater":"Jaribu tena baadaye",
"yourEmailIsAlreadyRegistered":"Barua pepe yako tayari imesajiliwa",
"weAreShufflingThingsAroundForYou":"Tunachanganya mambo kwa ajili yako....",
"youWouldBeRequiredToAddYourEmailToYourProfileOnTheMobileAppToEnableYouAccessThe":" Utahitajika kuongeza barua pepe yako kwenye wasifu wako kwenye programu ya simu ili kukuwezesha kufikia ",
"withOneAccount":" na akaunti moja.",
"addMyEmail":"Ongeza barua pepe yangu",
"remindMeLater":"Nikumbushe baadaye"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: use_build_context_synchronously

import 'package:app/blocs/blocs.dart';
import 'package:app/models/enum_constants.dart';
import 'package:app/screens/email_authentication/email_auth_widgets.dart';
Expand All @@ -6,6 +8,7 @@
import 'package:app/utils/utils.dart';
import 'package:app/widgets/widgets.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -208,39 +211,80 @@
);
}

Future<void> linkAccounts() async {

Check warning on line 214 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L214

Added line #L214 was not covered by tests
final emailAuthModel =
context.read<EmailVerificationBloc>().state.emailAuthModel;

Check warning on line 216 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L216

Added line #L216 was not covered by tests

final emailCredential = EmailAuthProvider.credentialWithLink(
emailLink: emailAuthModel.signInLink,
email: emailAuthModel.emailAddress,

Check warning on line 220 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L218-L220

Added lines #L218 - L220 were not covered by tests
);

final user = FirebaseAuth.instance.currentUser;

Check warning on line 223 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L223

Added line #L223 was not covered by tests

try {
if (user != null) {
await user.linkWithCredential(emailCredential);
context.read<EmailVerificationBloc>().add(

Check warning on line 228 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L227-L228

Added lines #L227 - L228 were not covered by tests
const SetEmailVerificationStatus(
AuthenticationStatus.success,
),
);
await AirqoApiClient().syncPlatformAccount();

Check warning on line 233 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L233

Added line #L233 was not covered by tests
}
} catch (error) {
context.read<EmailVerificationBloc>().add(

Check warning on line 236 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L236

Added line #L236 was not covered by tests
const SetEmailVerificationStatus(
AuthenticationStatus.error,
),
);
if (kDebugMode) {
print('Error linking accounts: $error');

Check warning on line 242 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L242

Added line #L242 was not covered by tests
}
}
}

Future<void> _authenticate() async {
loadingScreen(context);

final emailAuthModel =
context.read<EmailVerificationBloc>().state.emailAuthModel;

final emailCredential = EmailAuthProvider.credentialWithLink(
emailLink: emailAuthModel.signInLink,
email: emailAuthModel.emailAddress,
);

try {
final bool authenticationSuccessful =
await CustomAuth.firebaseSignIn(emailCredential);
if (!mounted) return;
final currentUser = FirebaseAuth.instance.currentUser;

Check warning on line 258 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L258

Added line #L258 was not covered by tests
if (currentUser != null) {
// Link the email credential with the existing user
await currentUser.linkWithCredential(emailCredential);

Check warning on line 261 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L261

Added line #L261 was not covered by tests
} else {
// Perform email authentication if not signed in with phone number
final bool authenticationSuccessful =
await CustomAuth.firebaseSignIn(emailCredential);
if (!mounted) return;

Check warning on line 266 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L265-L266

Added lines #L265 - L266 were not covered by tests

Navigator.pop(context);
if (!authenticationSuccessful) {
await showDialog<void>(
context: context,

Check warning on line 270 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L269-L270

Added lines #L269 - L270 were not covered by tests
barrierDismissible: false,
builder: (BuildContext _) {

Check warning on line 272 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L272

Added line #L272 was not covered by tests
return const AuthFailureDialog();
},
);
}
}

if (authenticationSuccessful) {
context
.read<EmailVerificationBloc>()
.add(const SetEmailVerificationStatus(
AuthenticationStatus.success,
));
context
.read<EmailVerificationBloc>()
.add(const SetEmailVerificationStatus(

Check warning on line 281 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L279-L281

Added lines #L279 - L281 were not covered by tests
AuthenticationStatus.success,
));

// Check if account linking was done, skip postSignInActions
if (currentUser == null) {
await AppService.postSignInActions(context);
} else {
await showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext _) {
return const AuthFailureDialog();
},
);
}
} catch (exception, stackTrace) {
Navigator.pop(context);
Expand Down
Loading
Loading