From 82d2f323bbcd88740829dbce68c88c23a45f2669 Mon Sep 17 00:00:00 2001 From: Rainvisitor Date: Sun, 7 Jan 2024 00:37:18 +0800 Subject: [PATCH] feat: `password error five times` in login error hanlde --- lib/api/ap_helper.dart | 5 +++++ lib/api/ap_status_code.dart | 1 + lib/api/parser/ap_parser.dart | 2 ++ lib/pages/home_page.dart | 3 ++- lib/pages/login_page.dart | 4 ++++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/api/ap_helper.dart b/lib/api/ap_helper.dart index 918f5187..7b249ef9 100644 --- a/lib/api/ap_helper.dart +++ b/lib/api/ap_helper.dart @@ -163,6 +163,11 @@ class WebApHelper { statusCode: ApStatusCode.userDataError, message: 'username or password error', ); + case 5: + throw GeneralResponse( + statusCode: ApStatusCode.passwordFiveTimesError, + message: 'username or password error', + ); case 500: throw GeneralResponse( statusCode: ApStatusCode.schoolServerError, diff --git a/lib/api/ap_status_code.dart b/lib/api/ap_status_code.dart index b8e31d06..9b39d7fb 100644 --- a/lib/api/ap_status_code.dart +++ b/lib/api/ap_status_code.dart @@ -6,6 +6,7 @@ class ApStatusCode { static const int cancel = 100; static const int userDataError = 1401; static const int unknownError = 1402; + static const int passwordFiveTimesError = 1405; //Common static const int apiExpire = 401; diff --git a/lib/api/parser/ap_parser.dart b/lib/api/parser/ap_parser.dart index 15ef43a0..0af04c59 100644 --- a/lib/api/parser/ap_parser.dart +++ b/lib/api/parser/ap_parser.dart @@ -89,6 +89,8 @@ class WebApParser { return 999; } else if (match.contains('無此帳號或密碼不正確')) { return 1; + } else if (match.contains('您先前已登入')) { + return 5; } else if (match.contains('繁忙')) { return 500; } diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index fbe2bd31..240dffe7 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -608,7 +608,8 @@ class HomePageState extends State { }, onError: (GeneralResponse response) async { String message = ''; - if (response.statusCode == ApStatusCode.userDataError) { + if (response.statusCode == ApStatusCode.userDataError || + response.statusCode == ApStatusCode.passwordFiveTimesError) { Toast.show(ap.passwordError, context); await Preferences.setBool(Constants.prefAutoLogin, false); checkLogin(); diff --git a/lib/pages/login_page.dart b/lib/pages/login_page.dart index e76cc467..d80beece 100644 --- a/lib/pages/login_page.dart +++ b/lib/pages/login_page.dart @@ -207,6 +207,10 @@ class LoginPageState extends State { case ApStatusCode.userDataError: message = ap.loginFail; break; + case ApStatusCode.passwordFiveTimesError: + //TODO i18n + message = '您先前已登入失敗達5次!!請30分鐘後再嘗試登入!!'; + break; case ApStatusCode.cancel: message = null; break;