From 55cb39c568557959578f7496c7feed596d6594a8 Mon Sep 17 00:00:00 2001 From: Ioana Alexandru Date: Thu, 19 Mar 2020 13:37:52 +0200 Subject: [PATCH] send email verification on signup --- lib/authentication/service/auth_provider.dart | 15 +++++++++++---- lib/generated/intl/messages_en.dart | 1 + lib/generated/intl/messages_ro.dart | 1 + lib/generated/l10n.dart | 13 +++++++++++-- lib/l10n/intl_en.arb | 1 + lib/l10n/intl_ro.arb | 1 + pubspec.yaml | 2 +- 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/authentication/service/auth_provider.dart b/lib/authentication/service/auth_provider.dart index b647245f3..b7976ad11 100644 --- a/lib/authentication/service/auth_provider.dart +++ b/lib/authentication/service/auth_provider.dart @@ -27,7 +27,7 @@ extension DatabaseUser on User { } class AuthProvider with ChangeNotifier { - FirebaseUser firebaseUser; // TODO: Make this private + FirebaseUser firebaseUser; // TODO: Make this private StreamSubscription userAuthSub; AuthProvider() { @@ -109,8 +109,10 @@ class AuthProvider with ChangeNotifier { if (isAnonymous) { return null; } - DocumentSnapshot snapshot = - await Firestore.instance.collection('users').document(firebaseUser.uid).get(); + DocumentSnapshot snapshot = await Firestore.instance + .collection('users') + .document(firebaseUser.uid) + .get(); return DatabaseUser.fromSnap(snapshot); } @@ -290,7 +292,12 @@ class AuthProvider with ChangeNotifier { Firestore.instance.collection('users').document(user.uid); ref.setData(user.toData()); - AppToast.show(S.of(context).messageAccountCreated); + // Send verification e-mail + await firebaseUser.sendEmailVerification(); + + AppToast.show(S.of(context).messageAccountCreated + + ' ' + + S.of(context).messageCheckEmailVerification); return true; } catch (e) { _errorHandler(e, context); diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 920a1918a..69b30ce12 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -68,6 +68,7 @@ class MessageLookup extends MessageLookupByLibrary { "labelLastName" : MessageLookupByLibrary.simpleMessage("Last name"), "labelPassword" : MessageLookupByLibrary.simpleMessage("Password"), "messageAccountCreated" : MessageLookupByLibrary.simpleMessage("Account created successfully."), + "messageCheckEmailVerification" : MessageLookupByLibrary.simpleMessage("Please check your email for account verification."), "messageNewUser" : MessageLookupByLibrary.simpleMessage("New user?"), "messageResetPassword" : MessageLookupByLibrary.simpleMessage("Enter your e-mai in order to receive instructions on how to reset your password."), "messageUnderConstruction" : MessageLookupByLibrary.simpleMessage("Under construction"), diff --git a/lib/generated/intl/messages_ro.dart b/lib/generated/intl/messages_ro.dart index 6280d6ce0..e092da8b7 100644 --- a/lib/generated/intl/messages_ro.dart +++ b/lib/generated/intl/messages_ro.dart @@ -68,6 +68,7 @@ class MessageLookup extends MessageLookupByLibrary { "labelLastName" : MessageLookupByLibrary.simpleMessage("Nume"), "labelPassword" : MessageLookupByLibrary.simpleMessage("Parolă"), "messageAccountCreated" : MessageLookupByLibrary.simpleMessage("Contul a fost creat cu succes."), + "messageCheckEmailVerification" : MessageLookupByLibrary.simpleMessage("Verificați-vă mail-ul pentru confirmarea contului."), "messageNewUser" : MessageLookupByLibrary.simpleMessage("Utilizator nou?"), "messageResetPassword" : MessageLookupByLibrary.simpleMessage("Introduceți mail-ul pentru a primi instrucțiuni de resetare a parolei."), "messageUnderConstruction" : MessageLookupByLibrary.simpleMessage("În construcție"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index d3cc90aa9..15d6ac57b 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -16,7 +16,7 @@ class S { AppLocalizationDelegate(); static Future load(Locale locale) { - final String name = locale.countryCode.isEmpty ? locale.languageCode : locale.toString(); + final String name = (locale.countryCode?.isEmpty ?? false) ? locale.languageCode : locale.toString(); final String localeName = Intl.canonicalizedLocale(name); return initializeMessages(localeName).then((_) { Intl.defaultLocale = localeName; @@ -597,6 +597,15 @@ class S { ); } + String get messageCheckEmailVerification { + return Intl.message( + 'Please check your email for account verification.', + name: 'messageCheckEmailVerification', + desc: '', + args: [], + ); + } + String get messageResetPassword { return Intl.message( 'Enter your e-mai in order to receive instructions on how to reset your password.', @@ -648,7 +657,7 @@ class AppLocalizationDelegate extends LocalizationsDelegate { List get supportedLocales { return const [ - Locale('en', ''), Locale('ro', ''), + Locale.fromSubtags(languageCode: 'en'), Locale.fromSubtags(languageCode: 'ro'), ]; } diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 2eac2ff60..ba125fb99 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -71,6 +71,7 @@ "messageWelcomeName": "Welcome, {name}!", "messageNewUser": "New user?", "messageAccountCreated": "Account created successfully.", + "messageCheckEmailVerification": "Please check your email for account verification.", "messageResetPassword": "Enter your e-mai in order to receive instructions on how to reset your password.", "messageUnderConstruction": "Under construction", diff --git a/lib/l10n/intl_ro.arb b/lib/l10n/intl_ro.arb index ab6e7ae8f..9de16c2b6 100644 --- a/lib/l10n/intl_ro.arb +++ b/lib/l10n/intl_ro.arb @@ -71,6 +71,7 @@ "messageWelcomeName": "Bine ai venit, {name}!", "messageNewUser":"Utilizator nou?", "messageAccountCreated": "Contul a fost creat cu succes.", + "messageCheckEmailVerification": "Verificați-vă mail-ul pentru confirmarea contului.", "messageResetPassword": "Introduceți mail-ul pentru a primi instrucțiuni de resetare a parolei.", "messageUnderConstruction": "În construcție", diff --git a/pubspec.yaml b/pubspec.yaml index b3e6fc528..963a32b3f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A mobile application for students at ACS UPB. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.3.10+2 +version: 0.3.11+1 environment: sdk: ">=2.6.0 <3.0.0"