migrated timetable integration from WebUntis to the MarianumConnect API, implementing a Dio-based client with bearer token authentication, background session validation, and auto-refresh logic.
This commit is contained in:
@@ -4,8 +4,9 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../api/errors/auth_exception.dart';
|
||||
import '../../api/errors/error_mapper.dart';
|
||||
import '../../api/marianumcloud/talk/room/get_room.dart';
|
||||
import '../../api/marianumcloud/talk/room/get_room_params.dart';
|
||||
import '../../api/marianumconnect/auth/device_token_name.dart';
|
||||
import '../../api/marianumconnect/auth/token_storage.dart';
|
||||
import '../../api/marianumconnect/queries/auth_login/auth_login.dart';
|
||||
import '../../model/account_data.dart';
|
||||
import '../../widget_data/widget_sync.dart';
|
||||
|
||||
@@ -32,22 +33,28 @@ class LoginController extends ChangeNotifier {
|
||||
final user = username.trim().toLowerCase();
|
||||
try {
|
||||
await AccountData().removeData();
|
||||
// Drop any cached widget snapshot from a previous account before the
|
||||
// new credentials populate it — otherwise a re-login with a different
|
||||
// user briefly shows the previous owner's timetable on the home screen.
|
||||
// Vorherigen Token revoken bevor wir einen neuen anfordern — ein altes
|
||||
// Account hätte sonst noch einen aktiven Token in api_tokens.
|
||||
await const MarianumConnectTokenStorage().clear();
|
||||
// Widget-Snapshot löschen, sonst blitzt nach Account-Wechsel kurz der
|
||||
// Stundenplan des vorigen Users auf dem Home-Bildschirm.
|
||||
await WidgetSync.clear();
|
||||
await WidgetSync.triggerUpdate();
|
||||
// AuthLogin = Credential-Probe + Token-Create in einem Call.
|
||||
// 401 hier heißt: falsches Passwort.
|
||||
await AuthLogin().run(
|
||||
username: user,
|
||||
password: password,
|
||||
tokenName: await DeviceTokenName.resolve(),
|
||||
);
|
||||
await AccountData().setData(user, password);
|
||||
await GetRoom(GetRoomParams(includeStatus: false)).run();
|
||||
_loading = false;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
await AccountData().removeData();
|
||||
// 401 from the probe means the credentials were wrong; everything else
|
||||
// (no network, server down, TLS errors, …) gets the generic mapped
|
||||
// message so the user knows it isn't their typo.
|
||||
await const MarianumConnectTokenStorage().clear();
|
||||
final isWrongCredentials = e is AuthException && e.statusCode == 401;
|
||||
_errorMessage = isWrongCredentials
|
||||
? 'Benutzername oder Passwort falsch.'
|
||||
|
||||
Reference in New Issue
Block a user