File tree Expand file tree Collapse file tree
ClassSchedule/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,6 +40,15 @@ Y/akVmYNtghKZzz6jwIDAQAB
4040 await loginWithEncrypted (account: account, encryptedPassword: encryptedPwd);
4141 }
4242
43+ Future <void > resetLoginContext ({String ? account}) async {
44+ if (account == null || account.trim ().isEmpty) {
45+ _timetableLoginStates.clear ();
46+ } else {
47+ _timetableLoginStates.remove (account.trim ());
48+ }
49+ await _client.cookieJar.deleteAll ();
50+ }
51+
4352 Future <void > ensureTimetableLogin ({
4453 required String account,
4554 String ? password,
Original file line number Diff line number Diff line change @@ -77,6 +77,9 @@ class CourseApi {
7777 allowReloginRetry: false ,
7878 );
7979 }
80+ if (_looksLikeAuthError (parsed)) {
81+ throw Exception (_authErrorMessage (parsed));
82+ }
8083 return parsed;
8184 } catch (e) {
8285 if (! allowReloginRetry) rethrow ;
@@ -116,4 +119,10 @@ class CourseApi {
116119 if (data.containsKey ('code' ) || data.containsKey ('msg' )) return true ;
117120 return false ;
118121 }
122+
123+ String _authErrorMessage (Map <String , dynamic > data) {
124+ final msg = (data['msg' ] ?? '' ).toString ().trim ();
125+ if (msg.isNotEmpty) return msg;
126+ return '课表鉴权失败,请重新登录' ;
127+ }
119128}
Original file line number Diff line number Diff line change @@ -274,6 +274,11 @@ class ScheduleController {
274274 persistLastViewed: persistLastViewed,
275275 updateWidgetPins: shouldPinWidget,
276276 );
277+ final loadedWeek = (data.weekNum ?? '' ).trim ();
278+ final loadedWeeks = data.weekList;
279+ if (loadedWeek.isEmpty || loadedWeeks == null || loadedWeeks.isEmpty) {
280+ throw Exception ("课表鉴权失败,请重新登录" );
281+ }
277282
278283 if (weekNum == null && yearTerm == null ) {
279284 final now = DateTime .now ();
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ class _LoginPageState extends State<LoginPage> {
195195 setState (() => _isLoading = true );
196196
197197 try {
198+ await _authApi.resetLoginContext ();
198199 if (useSavedPassword) {
199200 await _authApi.loginWithEncrypted (
200201 account: account,
Original file line number Diff line number Diff line change 1+ import 'package:cqut/api/auth/auth_api.dart' ;
12import 'package:flutter/material.dart' ;
23import 'package:shared_preferences/shared_preferences.dart' ;
34
@@ -17,6 +18,7 @@ Future<void> showMineLogoutDialog(BuildContext context) async {
1718 final prefs = await SharedPreferences .getInstance ();
1819 await prefs.remove ('account' );
1920 await prefs.remove ('encrypted_password' );
21+ await AuthApi ().resetLoginContext ();
2022 if (context.mounted) {
2123 Navigator .pop (context);
2224 ScaffoldMessenger .of (
You can’t perform that action at this time.
0 commit comments