From 78d2ed077c45c98c59404320d16640cc6f28aa0e Mon Sep 17 00:00:00 2001 From: Bruno Mendes Date: Sat, 23 Sep 2023 15:00:59 +0100 Subject: [PATCH] Remove useless login locks and checks --- .../controller/networking/network_router.dart | 60 ++++++++----------- .../providers/state_provider_notifier.dart | 10 ---- 2 files changed, 25 insertions(+), 45 deletions(-) diff --git a/uni/lib/controller/networking/network_router.dart b/uni/lib/controller/networking/network_router.dart index a72f59b98..f05d88d54 100644 --- a/uni/lib/controller/networking/network_router.dart +++ b/uni/lib/controller/networking/network_router.dart @@ -55,7 +55,6 @@ class NetworkRouter { final url = '${NetworkRouter.getBaseUrls(faculties)[0]}mob_val_geral.autentica'; - final response = await http.post( url.toUri(), body: {'pv_login': username, 'pv_password': password}, @@ -100,8 +99,6 @@ class NetworkRouter { final faculties = session.faculties; final persistentSession = session.persistentSession; - Logger().d('Re-login from session: $username, $faculties'); - return login( username, password, @@ -117,17 +114,13 @@ class NetworkRouter { String pass, List faculties, ) async { - return _loginLock.synchronized(() async { - final url = - '${NetworkRouter.getBaseUrls(faculties)[0]}vld_validacao.validacao'; - - final response = await http.post( - url.toUri(), - body: {'p_user': user, 'p_pass': pass}, - ).timeout(_requestTimeout); - - return response.body; - }); + final url = + '${NetworkRouter.getBaseUrls(faculties)[0]}vld_validacao.validacao'; + final response = await http.post( + url.toUri(), + body: {'p_user': user, 'p_pass': pass}, + ).timeout(_requestTimeout); + return response.body; } /// Extracts the cookies present in [headers]. @@ -192,6 +185,7 @@ class NetworkRouter { NavigationService.logoutAndPopHistory(null); return Future.error('Login failed'); } + session ..username = newSession.username ..cookies = newSession.cookies; @@ -218,20 +212,18 @@ class NetworkRouter { /// Check if the user is still logged in, /// performing a health check on the user's personal page. static Future userLoggedIn(Session session) async { - return _loginLock.synchronized(() async { - Logger().d('Checking if user is still logged in'); + Logger().d('Checking if user is still logged in'); - final url = '${getBaseUrl(session.faculties[0])}' - 'fest_geral.cursos_list?pv_num_unico=${session.username}'; - final headers = {}; - headers['cookie'] = session.cookies; + final url = '${getBaseUrl(session.faculties[0])}' + 'fest_geral.cursos_list?pv_num_unico=${session.username}'; + final headers = {}; + headers['cookie'] = session.cookies; - final response = await (httpClient != null - ? httpClient!.get(url.toUri(), headers: headers) - : http.get(url.toUri(), headers: headers)); + final response = await (httpClient != null + ? httpClient!.get(url.toUri(), headers: headers) + : http.get(url.toUri(), headers: headers)); - return response.statusCode == 200; - }); + return response.statusCode == 200; } /// Returns the base url of the user's faculties. @@ -253,17 +245,15 @@ class NetworkRouter { static Future killSigarraAuthentication( List faculties, ) async { - return _loginLock.synchronized(() async { - final url = '${NetworkRouter.getBaseUrl(faculties[0])}vld_validacao.sair'; - final response = await http.get(url.toUri()).timeout(_requestTimeout); + final url = '${NetworkRouter.getBaseUrl(faculties[0])}vld_validacao.sair'; + final response = await http.get(url.toUri()).timeout(_requestTimeout); - if (response.statusCode == 200) { - Logger().i('Logout Successful'); - } else { - Logger().i('Logout Failed'); - } + if (response.statusCode == 200) { + Logger().i('Logout Successful'); + } else { + Logger().i('Logout Failed'); + } - return response; - }); + return response; } } diff --git a/uni/lib/model/providers/state_provider_notifier.dart b/uni/lib/model/providers/state_provider_notifier.dart index beb4b7616..41e80ed28 100644 --- a/uni/lib/model/providers/state_provider_notifier.dart +++ b/uni/lib/model/providers/state_provider_notifier.dart @@ -108,16 +108,6 @@ abstract class StateProviderNotifier extends ChangeNotifier { Future forceRefresh(BuildContext context) async { await _lock.synchronized(() async { - if (_lastUpdateTime != null && - DateTime.now().difference(_lastUpdateTime!) < - const Duration(minutes: 1)) { - Logger().w( - 'Last update for $runtimeType was less than a minute ago; ' - 'skipping refresh', - ); - return; - } - final session = Provider.of(context, listen: false).session; final profile =