Skip to content

Commit

Permalink
oprava přihlašování - už nevyhodí chybu, že nejste připojen k internetu
Browse files Browse the repository at this point in the history
  • Loading branch information
tpkowastaken committed Oct 15, 2023
1 parent 19c1483 commit 5a4520f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions lib/methods_vars/icanteen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Ordering ordering = Ordering();
///
/// 'no internet' - when there is no internet connection
///
/// 'Uživatel není přihlášen' - when user is not logged in and doesn't have credentials in storage
/// 'nejdříve se musíte přihlásit' - when user is not logged in and doesn't have credentials in storage
Future<Canteen> initCanteen({bool hasToBeNew = false, String? url, String? username, String? password, bool? doIndexing}) async {
LoginDataAutojidelna loginData = await getLoginDataFromSecureStorage();
url ??= loginData.users[loginData.currentlyLoggedInId!].url;
Expand All @@ -59,7 +59,7 @@ Future<Canteen> initCanteen({bool hasToBeNew = false, String? url, String? usern
if (username == null || password == null) {
savedCredetnials = true;
if (loginData.currentlyLoggedInId == null) {
return Future.error('Uživatel není přihlášen');
return Future.error('nejdříve se musíte přihlásit');
}
}

Expand Down Expand Up @@ -145,7 +145,7 @@ void pridatStatistiku(TypStatistiky statistika) async {
///získá Jídelníček pro den [den]
///tuto funkci nevolat globálně, nebere informace s canteenData a zároveň je neukládá
///uživatel musí být přihlášen
///Jinak vyhodí chybu 'Uživatel není přihlášen'
///Jinak vyhodí chybu 'nejdříve se musíte přihlásit'
///může vyhodit chybu 'no internet'
Future<Jidelnicek> ziskatJidelnicekDen(DateTime den) async {
try {
Expand All @@ -156,14 +156,14 @@ Future<Jidelnicek> ziskatJidelnicekDen(DateTime den) async {
/// this variable is used as a maximum number of Lunches that it should check for this error. If you change it it only lowers/highers the effectiveness of this fix with a tradeoff in performance
return jidelnicek;
} catch (e) {
if (e == 'Uživatel není přihlášen') {
if (e == 'nejdříve se musíte přihlásit') {
try {
await initCanteen(hasToBeNew: true);
await Future.delayed(const Duration(seconds: 1));
return await ziskatJidelnicekDen(den);
} catch (e) {
if (e == 'Uživatel není přihlášen') {
return Future.error('Uživatel není přihlášen');
if (e == 'nejdříve se musíte přihlásit') {
return Future.error('nejdříve se musíte přihlásit');
}
return Future.error('no internet');
}
Expand Down Expand Up @@ -344,6 +344,9 @@ Future<void> logout({int? id}) async {

//ensuring correct loginData.currentlyloggedInId
if (id == loginData.currentlyLoggedInId) {
canteenData = null;
canteenInstance = null;
changeDate(newDate: DateTime.now());
loginData.currentlyLoggedInId = loginData.users.length - 2;
} else if (loginData.currentlyLoggedInId != null && loginData.currentlyLoggedInId! > id) {
loginData.currentlyLoggedInId = loginData.currentlyLoggedInId! - 1;
Expand All @@ -355,9 +358,6 @@ Future<void> logout({int? id}) async {
loginData.currentlyLoggedIn = false;
loginData.currentlyLoggedInId = null;
}
canteenData = null;
canteenInstance = null;
changeDate(newDate: DateTime.now());
saveLoginToSecureStorage(loginData);
return;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ class LoginScreen extends StatelessWidget {
loginData.currentlyLoggedInId = loginData.users.length;
loginData.users.add(LoggedInUser(username: _usernameController.text, password: _passwordController.text, url: url));
try {
canteenData!.pocetJidel = {};
canteenData = null;
canteenInstance = null;
changeDate(newDate: DateTime.now());
} catch (e) {
//this needs to be done only if we are loggin in the second time
Expand All @@ -264,7 +265,7 @@ class LoginScreen extends StatelessWidget {
Navigator.pop(context);
setHomeWidget(LoggingInWidget(setHomeWidget: setHomeWidget));
} else {
setHomeWidget(MainAppScreen(setHomeWidget: setHomeWidget));
setHomeWidget(LoggingInWidget(setHomeWidget: setHomeWidget));
}
} else {
_setErrorText('Špatné heslo nebo uživatelské jméno', LoginFormErrorField.password);
Expand Down

0 comments on commit 5a4520f

Please sign in to comment.