From 407018c38a9e9e7f1ea7c46261076e7f7380b03b Mon Sep 17 00:00:00 2001 From: vyPal <66716025+vyPal@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:41:00 +0100 Subject: [PATCH] Fix icanteen support --- lib/icanteen.dart | 23 +++++++++-------------- lib/icanteen_setup.dart | 17 +++-------------- lib/load.dart | 3 +++ 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/lib/icanteen.dart b/lib/icanteen.dart index 546a2be..5671f43 100644 --- a/lib/icanteen.dart +++ b/lib/icanteen.dart @@ -54,24 +54,19 @@ class ICanteenPageState extends State { loading = true; //make loading true to show progressindicator }); - String token = sharedPreferences.getString("token")!; - Response response = await dio - .get( - "$baseUrl/lunches", - options: buildCacheOptions( - const Duration(days: 0), - forceRefresh: true, - options: Options( - headers: { - "Authorization": "Bearer $token", - }, - ), - ), + .post( + "$baseUrl/icanteen", + data: { + "username": sharedPreferences.getString("ic_email"), + "password": sharedPreferences.getString("ic_password"), + "server": sharedPreferences.getString("ic_server"), + }, + options: Options(contentType: Headers.formUrlEncodedContentType), ) .catchError((obj) { return Response( - requestOptions: RequestOptions(path: "$baseUrl/lunches"), + requestOptions: RequestOptions(path: "$baseUrl/icanteen"), statusCode: 500, ); }); diff --git a/lib/icanteen_setup.dart b/lib/icanteen_setup.dart index bc3dc35..6c94bf7 100644 --- a/lib/icanteen_setup.dart +++ b/lib/icanteen_setup.dart @@ -36,20 +36,9 @@ class ICanteenSetupScreenState extends State { setState(() { hasLogin = true; }); - String? token = sharedPreferences.getString("token"); - await dio.post( - "$baseUrl/set_icanteen", - data: { - 'email': email, - 'password': password, - 'server': server, - }, - options: Options( - headers: { - "Authorization": "Bearer $token", - }, - ), - ); + sharedPreferences.setString("ic_server", server); + sharedPreferences.setString("ic_email", email); + sharedPreferences.setString("ic_password", password); sharedPreferences.setBool("ice", true); } diff --git a/lib/load.dart b/lib/load.dart index 09126f8..144d7c4 100644 --- a/lib/load.dart +++ b/lib/load.dart @@ -59,6 +59,9 @@ class LoadingScreenState extends State { baseUrl = endpoint; } quickstart = sharedPreferences.getBool('quickstart') ?? false; + if (sharedPreferences.getBool("ice") == true) { + sessionManager.set("iCanteenEnabled", true); + } progress = 0.1; loaderText = local!.loadCredentials; dio.interceptors