Skip to content

Commit

Permalink
Fix/login speedup (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes authored Sep 25, 2023
2 parents c4a2238 + 1f27e34 commit cd97a1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 45 deletions.
60 changes: 25 additions & 35 deletions uni/lib/controller/networking/network_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand All @@ -117,17 +114,13 @@ class NetworkRouter {
String pass,
List<String> 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].
Expand Down Expand Up @@ -192,6 +185,7 @@ class NetworkRouter {
NavigationService.logoutAndPopHistory(null);
return Future.error('Login failed');
}

session
..username = newSession.username
..cookies = newSession.cookies;
Expand All @@ -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<bool> 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 = <String, String>{};
headers['cookie'] = session.cookies;
final url = '${getBaseUrl(session.faculties[0])}'
'fest_geral.cursos_list?pv_num_unico=${session.username}';
final headers = <String, String>{};
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.
Expand All @@ -253,17 +245,15 @@ class NetworkRouter {
static Future<Response> killSigarraAuthentication(
List<String> 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;
}
}
10 changes: 0 additions & 10 deletions uni/lib/model/providers/state_provider_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@ abstract class StateProviderNotifier extends ChangeNotifier {

Future<void> 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<SessionProvider>(context, listen: false).session;
final profile =
Expand Down

0 comments on commit cd97a1e

Please sign in to comment.