Skip to content

Commit

Permalink
Delete onstartup file
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes committed Jul 10, 2023
1 parent ebaa067 commit a3de86f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 38 deletions.
16 changes: 7 additions & 9 deletions uni/lib/controller/networking/network_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:logger/logger.dart';
import 'package:synchronized/synchronized.dart';
import 'package:uni/controller/local_storage/app_shared_preferences.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/view/navigation_service.dart';

extension UriString on String {
/// Converts a [String] to an [Uri].
Expand All @@ -16,13 +17,9 @@ extension UriString on String {
/// Manages the networking of the app.
class NetworkRouter {
static http.Client? httpClient;

static const int loginRequestTimeout = 20;

static Lock loginLock = Lock();

static Function onReloginFail = () {};

/// Creates an authenticated [Session] on the given [faculty] with the
/// given username [user] and password [pass].
static Future<Session> login(String user, String pass, List<String> faculties,
Expand Down Expand Up @@ -52,7 +49,7 @@ class NetworkRouter {
}

/// Determines if a re-login with the [session] is possible.
static Future<bool> relogin(Session session) {
static Future<bool> reLogin(Session session) {
return loginLock.synchronized(() async {
if (!session.persistentSession) {
return false;
Expand Down Expand Up @@ -94,10 +91,11 @@ class NetworkRouter {

/// Returns the response body of the login in Sigarra
/// given username [user] and password [pass].
static Future<String> loginInSigarra(String user, String pass, List<String> faculties) async {
static Future<String> loginInSigarra(
String user, String pass, List<String> faculties) async {
final String url =
'${NetworkRouter.getBaseUrls(faculties)[0]}vld_validacao.validacao';

final response = await http.post(url.toUri(), body: {
'p_user': user,
'p_pass': pass
Expand Down Expand Up @@ -149,12 +147,12 @@ class NetworkRouter {
return response;
} else if (response.statusCode == 403 && !(await userLoggedIn(session))) {
// HTTP403 - Forbidden
final bool reLoginSuccessful = await relogin(session);
final bool reLoginSuccessful = await reLogin(session);
if (reLoginSuccessful) {
headers['cookie'] = session.cookies;
return http.get(url.toUri(), headers: headers);
} else {
onReloginFail();
NavigationService.logout();
Logger().e('Login failed');
return Future.error('Login failed');
}
Expand Down
18 changes: 0 additions & 18 deletions uni/lib/controller/on_start_up.dart

This file was deleted.

2 changes: 0 additions & 2 deletions uni/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:provider/provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:uni/controller/background_workers/background_callback.dart';
import 'package:uni/controller/local_storage/app_shared_preferences.dart';
import 'package:uni/controller/on_start_up.dart';
import 'package:uni/model/providers/lazy/bus_stop_provider.dart';
import 'package:uni/model/providers/lazy/calendar_provider.dart';
import 'package:uni/model/providers/lazy/exam_provider.dart';
Expand Down Expand Up @@ -57,7 +56,6 @@ Future<void> main() async {
FacultyLocationsProvider(),
HomePageProvider());

OnStartUp.onStart(stateProviders.sessionProvider);
WidgetsFlutterBinding.ensureInitialized();

await Workmanager().initialize(workerStartCallback,
Expand Down
3 changes: 1 addition & 2 deletions uni/lib/model/providers/startup/profile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:uni/controller/local_storage/app_courses_database.dart';
import 'package:uni/controller/local_storage/app_refresh_times_database.dart';
import 'package:uni/controller/local_storage/app_shared_preferences.dart';
import 'package:uni/controller/local_storage/app_user_database.dart';
import 'package:uni/controller/local_storage/file_offline_storage.dart';
import 'package:uni/controller/parsers/parser_fees.dart';
import 'package:uni/controller/parsers/parser_print_balance.dart';
import 'package:uni/model/entities/course.dart';
Expand All @@ -22,8 +23,6 @@ import 'package:uni/model/entities/session.dart';
import 'package:uni/model/providers/state_provider_notifier.dart';
import 'package:uni/model/request_status.dart';

import '../../../controller/local_storage/file_offline_storage.dart';

class ProfileProvider extends StateProviderNotifier {
Profile _profile = Profile();
DateTime? _feesRefreshTime;
Expand Down
14 changes: 7 additions & 7 deletions uni/lib/model/providers/startup/session_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:uni/model/entities/profile.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/model/providers/state_provider_notifier.dart';
import 'package:uni/model/request_status.dart';
import 'package:uni/view/navigation_service.dart';

class SessionProvider extends StateProviderNotifier {
Session _session = Session();
Expand Down Expand Up @@ -47,7 +48,6 @@ class SessionProvider extends StateProviderNotifier {
() => {NotificationManager().initializeNotifications()});

await acceptTermsAndConditions();

updateStatus(RequestStatus.successful);
} else {
final String responseHtml =
Expand Down Expand Up @@ -81,7 +81,7 @@ class SessionProvider extends StateProviderNotifier {
updateStatus(RequestStatus.successful);
action?.complete();
} else {
failReLogin(action);
handleFailedReLogin(action);
}
} catch (e) {
_session = Session(
Expand All @@ -92,14 +92,14 @@ class SessionProvider extends StateProviderNotifier {
cookies: '',
persistentSession: true);

failReLogin(action);
handleFailedReLogin(action);
}
}

void failReLogin(Completer? action) {
notifyListeners();
updateStatus(RequestStatus.failed);
handleFailedReLogin(Completer? action) {
action?.completeError(RequestStatus.failed);
NetworkRouter.onReloginFail();
if (!session.persistentSession) {
return NavigationService.logout();
}
}
}

0 comments on commit a3de86f

Please sign in to comment.