From 49661e06e295e8a0019ffaa16aa3186871f8f2f9 Mon Sep 17 00:00:00 2001 From: ArthurBeaulieu Date: Mon, 24 Jun 2024 14:22:50 +0200 Subject: [PATCH] feat: 0.0.4 add notifications to login process #4 --- android/app/build.gradle | 4 +- lib/src/auth/login_view.dart | 101 ++++++++++++++++------ lib/src/localization/app_de.arb | 6 +- lib/src/localization/app_en.arb | 6 +- lib/src/localization/app_es.arb | 6 +- lib/src/localization/app_fr.arb | 6 +- lib/src/localization/app_it.arb | 6 +- lib/src/localization/app_pt.arb | 6 +- lib/src/settings/settings_controller.dart | 5 +- pubspec.yaml | 2 +- 10 files changed, 111 insertions(+), 37 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index d9e51ea..f668da2 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -50,8 +50,8 @@ android { applicationId "com.messebasseproduction.beercrackerz" multiDexEnabled true minSdkVersion 20 - versionCode 2 - versionName "0.0.3" + versionCode 4 + versionName "0.0.4" targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/lib/src/auth/login_view.dart b/lib/src/auth/login_view.dart index d016b1c..fa8e274 100644 --- a/lib/src/auth/login_view.dart +++ b/lib/src/auth/login_view.dart @@ -67,36 +67,85 @@ class LoginViewState extends State { final parsedJson = jsonDecode(response.body); // Check server response validity, it must contain the token and its expiration date if (parsedJson['expiry'] != null && parsedJson['token'] != null) { - await widget.settingsController.updateAuthToken( + bool authTokenUpdated = await widget.settingsController.updateAuthToken( parsedJson['expiry'], parsedJson['token'], ); - widget.settingsController.isLoggedIn = await widget.settingsController.getUserInfo(); - // Ensure context is mounted, then redirect user to MapView - if (context.mounted) { - Navigator.popAndPushNamed( - context, - MapView.routeName - ); - // Inform user that login went OK - toastification.show( - context: context, - title: Text( - AppLocalizations.of(context)!.authLoginSuccessToastTitle, - ), - description: Text( - AppLocalizations.of(context)!.authLoginSuccessToastDescription, - style: const TextStyle( - fontStyle: FontStyle.italic, + + if (authTokenUpdated == false) { + if (context.mounted) { + // Issue when saving token and expiry date + // Error LGI4 + toastification.show( + context: context, + title: Text( + AppLocalizations.of(context)!.authLoginTokenErrorToastTitle, ), - ), - type: ToastificationType.success, - style: ToastificationStyle.flatColored, - autoCloseDuration: const Duration( - seconds: 5, - ), - showProgressBar: false, - ); + description: Text( + AppLocalizations.of(context)!.authLoginTokenErrorToastDescription, + style: const TextStyle( + fontStyle: FontStyle.italic, + ), + ), + type: ToastificationType.error, + style: ToastificationStyle.flatColored, + autoCloseDuration: const Duration( + seconds: 5, + ), + showProgressBar: false, + ); + } + } else { + widget.settingsController.isLoggedIn = await widget.settingsController.getUserInfo(); + // Ensure context is mounted, then redirect user to MapView + if (context.mounted) { + if (widget.settingsController.isLoggedIn == false) { + // Unable to get user info from server + // Error LGI5 + toastification.show( + context: context, + title: Text( + AppLocalizations.of(context)!.authLoginUserInfoErrorToastTitle, + ), + description: Text( + AppLocalizations.of(context)!.authLoginUserInfoErrorToastDescription, + style: const TextStyle( + fontStyle: FontStyle.italic, + ), + ), + type: ToastificationType.error, + style: ToastificationStyle.flatColored, + autoCloseDuration: const Duration( + seconds: 5, + ), + showProgressBar: false, + ); + } else { + Navigator.popAndPushNamed( + context, + MapView.routeName + ); + // Inform user that login went OK + toastification.show( + context: context, + title: Text( + AppLocalizations.of(context)!.authLoginSuccessToastTitle, + ), + description: Text( + AppLocalizations.of(context)!.authLoginSuccessToastDescription, + style: const TextStyle( + fontStyle: FontStyle.italic, + ), + ), + type: ToastificationType.success, + style: ToastificationStyle.flatColored, + autoCloseDuration: const Duration( + seconds: 5, + ), + showProgressBar: false, + ); + } + } } } else { // No token nor expiry sent through the response, not supposed to happen diff --git a/lib/src/localization/app_de.arb b/lib/src/localization/app_de.arb index 2540faf..f1fa056 100644 --- a/lib/src/localization/app_de.arb +++ b/lib/src/localization/app_de.arb @@ -39,6 +39,10 @@ "authLoginEmptyCredentials": "Es wurden leere Anmeldeinformationen empfangen", "authLoginSuccessToastTitle": "Willkommen zurück!", "authLoginSuccessToastDescription": "Sie haben sich erfolgreich in Ihrem BeerCrackerz-Konto angemeldet. Schnappen Sie sich einen Platz, ein Bier und genießen Sie es!", + "authLoginTokenErrorToastTitle": "Ungültiges Token", + "authLoginTokenErrorToastDescription": "Das vom Server zurückgesendete Token ist entweder ungültig oder leer. Bitte wenden Sie sich an den Support, um Hilfe beim Fehlercode LGI4 zu erhalten.", + "authLoginUserInfoErrorToastTitle": "Benutzerinformationen können nicht abgerufen werden", + "authLoginUserInfoErrorToastDescription": "Der Server konnte die Benutzerinformationen nicht zurückgeben. Bitte wenden Sie sich an den Support, um Hilfe beim Fehlercode LGI5 zu erhalten.", "authRegisterTitle": "Registrieren", "authRegisterUsernameInput": "Geben Sie Ihren Benutzernamen ein", "authRegisterUsername": "benutzernamen", @@ -89,7 +93,7 @@ } }, "authProfileAboutBeerCrackerz": "BeerCrackerz ist die Community für Bierliebhaber, gefüllt mit Pint-Slayern und Müsliliebhabern. Eine clevere Idee von David Béché, umgesetzt von Messe Basse Production! BeerCrackerz ist eine Open-Source-Website und mobile Anwendung, die unter der GPL-3.0-Lizenz veröffentlicht wird.", - "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.3", + "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.4", "authProfileLogout": "Ausloggen", "authProfileLogoutSuccessToastTitle": "Erfolgreiche Abmeldung", "authProfileLogoutSuccessToastDescription": "Sie wurden erfolgreich von Ihrem Konto abgemeldet. Bis bald!", diff --git a/lib/src/localization/app_en.arb b/lib/src/localization/app_en.arb index 1a05a80..9884b3d 100644 --- a/lib/src/localization/app_en.arb +++ b/lib/src/localization/app_en.arb @@ -39,6 +39,10 @@ "authLoginEmptyCredentials": "Empty credentials received", "authLoginSuccessToastTitle": "Welcome back!", "authLoginSuccessToastDescription": "Successfully logged in your account BeerCrackerz account. Grab a spot and a beer, and enjoy!", + "authLoginTokenErrorToastTitle": "Invalid token", + "authLoginTokenErrorToastDescription": "The token sent back from server is either invalid or empty. Please contact support for assistance with error code LGI4.", + "authLoginUserInfoErrorToastTitle": "Unable to get user info", + "authLoginUserInfoErrorToastDescription": "The server couldn't give the user information back. Please contact support for assistance with error code LGI5.", "authRegisterTitle": "Register", "authRegisterUsernameInput": "Enter your username", "authRegisterUsername": "username", @@ -89,7 +93,7 @@ } }, "authProfileAboutBeerCrackerz": "BeerCrackerz is the beer lovers comunity, filled with pint slayers and cereals lovers. A brilliant idea from David Béché, brought to life by Messe Basse Production! BeerCrackerz is an open source website and mobile application released under the GPL-3.0 licence.", - "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.3", + "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.4", "authProfileLogout": "Logout", "authProfileLogoutSuccessToastTitle": "Logout success", "authProfileLogoutSuccessToastDescription": "You've been successfully logged out of your account. See you soon!", diff --git a/lib/src/localization/app_es.arb b/lib/src/localization/app_es.arb index 53fa094..b83dc6f 100644 --- a/lib/src/localization/app_es.arb +++ b/lib/src/localization/app_es.arb @@ -39,6 +39,10 @@ "authLoginEmptyCredentials": "Credenciales vacías recibidas", "authLoginSuccessToastTitle": "¡Bienvenido de nuevo!", "authLoginSuccessToastDescription": "Ingresó exitosamente a su cuenta BeerCrackerz. ¡Coge un lugar y una cerveza y disfruta!", + "authLoginTokenErrorToastTitle": "Simbolo no valido", + "authLoginTokenErrorToastDescription": "El token enviado desde el servidor no es válido o está vacío. Comuníquese con el soporte para obtener ayuda con el código de error LGI4.", + "authLoginUserInfoErrorToastTitle": "No se puede obtener información del usuario", + "authLoginUserInfoErrorToastDescription": "El servidor no pudo devolver la información del usuario. Comuníquese con el soporte para obtener ayuda con el código de error LGI5.", "authRegisterTitle": "Inscribirse", "authRegisterUsernameInput": "Ingrese su nombre de usuario", "authRegisterUsername": "nombre de usuario", @@ -89,7 +93,7 @@ } }, "authProfileAboutBeerCrackerz": "BeerCrackerz es la comunidad de amantes de la cerveza, llena de amantes de las pintas y de los cereales. ¡Una idea brillante de David Béché, materializada por Messe Basse Production! BeerCrackerz es un sitio web y una aplicación móvil de código abierto publicado bajo la licencia GPL-3.0.", - "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.3", + "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.4", "authProfileLogout": "Cerrar sesión", "authProfileLogoutSuccessToastTitle": "Cierre de sesión exitoso", "authProfileLogoutSuccessToastDescription": "Has cerrado sesión exitosamente en tu cuenta. ¡Nos vemos pronto!", diff --git a/lib/src/localization/app_fr.arb b/lib/src/localization/app_fr.arb index 7c71572..33ef996 100644 --- a/lib/src/localization/app_fr.arb +++ b/lib/src/localization/app_fr.arb @@ -39,6 +39,10 @@ "authLoginEmptyCredentials": "Informations vides envoyées", "authLoginSuccessToastTitle": "Bienvenue!", "authLoginSuccessToastDescription": "Vous ètes maintenant connecté sur votre compte BeerCrackerz. Trouvez un spot, une Bière et savourez!", + "authLoginTokenErrorToastTitle": "Jeton invalide", + "authLoginTokenErrorToastDescription": "Le jeton d'authetification reçu du serveur est soit vide, soit invalide. Veuillez contacter le support en fournissant le code d'erreur LGI4.", + "authLoginUserInfoErrorToastTitle": "Impossible de récupérer les informations", + "authLoginUserInfoErrorToastDescription": "Le serveur n'a pas pu renvoyer les informations utilisateur. Veuillez contacter le support en fournissant le code d'erreur LGI5.", "authRegisterTitle": "S'enregistrer", "authRegisterUsernameInput": "Entrez votre nom d'utilisateur", "authRegisterUsername": "nom d'utilisateur", @@ -89,7 +93,7 @@ } }, "authProfileAboutBeerCrackerz": "BeerCrackerz, c'est la communauté des amoureux de la Bière et du plein air, des pourfendeurs de pinte, des déglingos de la céréale. Une brilliante idée de David Béché, réalisée par Messe Basse Production! BeerCrackerz est un site et une application mobile en source libre, publiée sous licence GPL-3.0.", - "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.3", + "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.4", "authProfileLogout": "Se déconnecter", "authProfileLogoutSuccessToastTitle": "Déconnexion réussie", "authProfileLogoutSuccessToastDescription": "Vous vous ète déconnecté de votre compte avec succès. À tantôt!", diff --git a/lib/src/localization/app_it.arb b/lib/src/localization/app_it.arb index 9c86584..3401f6c 100644 --- a/lib/src/localization/app_it.arb +++ b/lib/src/localization/app_it.arb @@ -39,6 +39,10 @@ "authLoginEmptyCredentials": "Credenziali vuote ricevute", "authLoginSuccessToastTitle": "Bentornato!", "authLoginSuccessToastDescription": "Accedi al tuo account Account BeerCrackerz con successo. Prendi un posto e una birra e divertiti!", + "authLoginTokenErrorToastTitle": "Gettone non valido", + "authLoginTokenErrorToastDescription": "Il token restituito dal server non è valido o è vuoto. Contatta l'assistenza per ricevere assistenza con il codice di errore LGI4.", + "authLoginUserInfoErrorToastTitle": "Impossibile ottenere informazioni sull'utente", + "authLoginUserInfoErrorToastDescription": "Il server non è riuscito a restituire le informazioni all'utente. Contatta il supporto per assistenza con il codice di errore LGI5.", "authRegisterTitle": "Registrati", "authRegisterUsernameInput": "Inserisci il tuo nome utente", "authRegisterUsername": "nome utente", @@ -89,7 +93,7 @@ } }, "authProfileAboutBeerCrackerz": "BeerCrackerz è la comunità degli amanti della birra, piena di cacciatori di pinte e amanti dei cereali. Un'idea brillante di David Béché, portata in vita da Messe Basse Production! BeerCrackerz è un sito Web open source e un'applicazione mobile rilasciata con licenza GPL-3.0.", - "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.3", + "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.4", "authProfileLogout": "Disconnettersi", "authProfileLogoutSuccessToastTitle": "Disconnessione riuscita", "authProfileLogoutSuccessToastDescription": "Sei stato disconnesso con successo dal tuo account. Arrivederci!", diff --git a/lib/src/localization/app_pt.arb b/lib/src/localization/app_pt.arb index 5900a30..92a236f 100644 --- a/lib/src/localization/app_pt.arb +++ b/lib/src/localization/app_pt.arb @@ -39,6 +39,10 @@ "authLoginEmptyCredentials": "Credenciais vazias recebidas", "authLoginSuccessToastTitle": "Bem vindo de volta!", "authLoginSuccessToastDescription": "Logado com sucesso em sua conta BeerCrackerz. Pegue um lugar e uma cerveja e divirta-se!", + "authLoginTokenErrorToastTitle": "Token inválido", + "authLoginTokenErrorToastDescription": "O token enviado de volta do servidor é inválido ou está vazio. Entre em contato com o suporte para obter assistência com o código de erro LGI4.", + "authLoginUserInfoErrorToastTitle": "Não foi possível obter informações do usuário", + "authLoginUserInfoErrorToastDescription": "O servidor não pôde devolver as informações do usuário. Entre em contato com o suporte para obter assistência com o código de erro LGI5.", "authRegisterTitle": "Registro", "authRegisterUsernameInput": "Entre com seu nome de usuário", "authRegisterUsername": "nome de usuário", @@ -89,7 +93,7 @@ } }, "authProfileAboutBeerCrackerz": "BeerCrackerz é a comunidade dos amantes da cerveja, repleta de caçadores de cerveja e amantes de cereais. Uma ideia brilhante de David Béché, concretizada pela Messe Basse Production! BeerCrackerz é um site de código aberto e um aplicativo móvel lançado sob a licença GPL-3.0.", - "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.3", + "authProfileAboutVersion": "BeerCrackerz – v0.1.0 / BeerCrackerzMobile – v0.0.4", "authProfileLogout": "Sair", "authProfileLogoutSuccessToastTitle": "Sucesso no logout", "authProfileLogoutSuccessToastDescription": "Você foi desconectado da sua conta com sucesso. Vejo você em breve!", diff --git a/lib/src/settings/settings_controller.dart b/lib/src/settings/settings_controller.dart index f883a7a..a1c21e4 100644 --- a/lib/src/settings/settings_controller.dart +++ b/lib/src/settings/settings_controller.dart @@ -84,16 +84,17 @@ class SettingsController with ChangeNotifier { /* Auth related methods */ // Update the user JWT token - Future updateAuthToken( + Future updateAuthToken( String? expiry, String? token, ) async { - if (expiry == null || token == null) return; + if (expiry == null || token == null) return false; await _settingsService.updateAuthToken( expiry, token, ); notifyListeners(); + return true; } // Test that the user token is expired or not Future isAuthTokenExpired() async { diff --git a/pubspec.yaml b/pubspec.yaml index e1e185f..881dbc7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: "The app for beer lovers, to share the best spot to crack a beer, o publish_to: 'none' -version: 0.0.3+3 +version: 0.0.4+4 environment: sdk: '>=3.2.5 <4.0.0'