Skip to content

Commit

Permalink
feat: 0.0.4 add notifications to login process #4
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurBeaulieu committed Jun 24, 2024
1 parent 8c51b7e commit 49661e0
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 37 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
101 changes: 75 additions & 26 deletions lib/src/auth/login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,85 @@ class LoginViewState extends State<LoginView> {
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
Expand Down
6 changes: 5 additions & 1 deletion lib/src/localization/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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!",
Expand Down
6 changes: 5 additions & 1 deletion lib/src/localization/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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!",
Expand Down
6 changes: 5 additions & 1 deletion lib/src/localization/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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!",
Expand Down
6 changes: 5 additions & 1 deletion lib/src/localization/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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!",
Expand Down
6 changes: 5 additions & 1 deletion lib/src/localization/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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!",
Expand Down
6 changes: 5 additions & 1 deletion lib/src/localization/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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!",
Expand Down
5 changes: 3 additions & 2 deletions lib/src/settings/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ class SettingsController with ChangeNotifier {
/* Auth related methods */

// Update the user JWT token
Future<void> updateAuthToken(
Future<bool> 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<bool> isAuthTokenExpired() async {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 49661e0

Please sign in to comment.