mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-07 01:18:27 +08:00
完善 log
This commit is contained in:
parent
ac9532b3fb
commit
5a3fc8753e
@ -37,14 +37,15 @@ class MaxKey with ChangeNotifier {
|
|||||||
handler.next(response);
|
handler.next(response);
|
||||||
},
|
},
|
||||||
onError: (error, handler) {
|
onError: (error, handler) {
|
||||||
|
LOGGER.e("InterceptorsWrapper.onError(): ");
|
||||||
LOGGER.e(error.type);
|
LOGGER.e(error.type);
|
||||||
LOGGER.e(error.response);
|
LOGGER.e(error.response);
|
||||||
if (error.type == DioExceptionType.badResponse) {
|
if (error.type == DioExceptionType.badResponse) {
|
||||||
SCAFFOLD_MESSENGER_KEY.currentState?.showSnackBar(
|
SCAFFOLD_MESSENGER_KEY.currentState?.showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: const Text("Please login again."),
|
content: const Text("登陆状态过期。请重新登陆"),
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
label: "Login",
|
label: "重新登陆",
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
_dio.options.headers.remove(HttpHeaders.authorizationHeader);
|
_dio.options.headers.remove(HttpHeaders.authorizationHeader);
|
||||||
await MaxKeyPersistent.instance.clearToken();
|
await MaxKeyPersistent.instance.clearToken();
|
||||||
@ -62,6 +63,7 @@ class MaxKey with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateBaseUrl() {
|
void updateBaseUrl() {
|
||||||
|
LOGGER.i("MaxKey.updateBaseUrl(): ");
|
||||||
LOGGER.i("old baseUrl: ${_dio.options.baseUrl}");
|
LOGGER.i("old baseUrl: ${_dio.options.baseUrl}");
|
||||||
_dio.options.baseUrl = MaxKeyPersistent.instance.baseUrl;
|
_dio.options.baseUrl = MaxKeyPersistent.instance.baseUrl;
|
||||||
LOGGER.i("new baseUrl: ${_dio.options.baseUrl}");
|
LOGGER.i("new baseUrl: ${_dio.options.baseUrl}");
|
||||||
@ -72,16 +74,20 @@ class MaxKey with ChangeNotifier {
|
|||||||
|
|
||||||
Future<bool> maxKeyNetworkTest({String? host}) async {
|
Future<bool> maxKeyNetworkTest({String? host}) async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("MaxKey.maxKeyNetworkTest(): ");
|
||||||
LOGGER.i(
|
LOGGER.i(
|
||||||
"[MaxKeyNetworkTest] GET: ${host == null ? MaxKeyPersistent.instance.baseUrl : "http://$host/sign"}",
|
"[MaxKeyNetworkTest] GET: ${host == null ? MaxKeyPersistent.instance.baseUrl : "http://$host/sign"}",
|
||||||
);
|
);
|
||||||
|
|
||||||
await _dio.get(
|
await _dio
|
||||||
host == null ? MaxKeyPersistent.instance.baseUrl : "http://$host/sign",
|
.get(host == null
|
||||||
);
|
? MaxKeyPersistent.instance.baseUrl
|
||||||
|
: "http://$host/sign")
|
||||||
|
.timeout(const Duration(seconds: 5));
|
||||||
LOGGER.i("MaxKeyNetworkTest: true");
|
LOGGER.i("MaxKeyNetworkTest: true");
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("MaxKey.maxKeyNetworkTest(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
LOGGER.i("MaxKeyNetworkTest: false");
|
LOGGER.i("MaxKeyNetworkTest: false");
|
||||||
|
|||||||
@ -14,6 +14,7 @@ class AuthnService {
|
|||||||
/// 获取 state 类型
|
/// 获取 state 类型
|
||||||
Future<String?> get() async {
|
Future<String?> get() async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("AuthnService.get(): ");
|
||||||
LOGGER.i("GET: /login/get?_allow_anonymous=true");
|
LOGGER.i("GET: /login/get?_allow_anonymous=true");
|
||||||
|
|
||||||
final res = await _dio.get(
|
final res = await _dio.get(
|
||||||
@ -22,6 +23,7 @@ class AuthnService {
|
|||||||
);
|
);
|
||||||
return res.data["data"]["state"];
|
return res.data["data"]["state"];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("AuthnService.get(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -33,6 +35,7 @@ class AuthnService {
|
|||||||
required String mobile,
|
required String mobile,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("AuthnService.produceOtp(): ");
|
||||||
LOGGER.i("GET: /login/sendotp/$mobile?_allow_anonymous=true");
|
LOGGER.i("GET: /login/sendotp/$mobile?_allow_anonymous=true");
|
||||||
|
|
||||||
final res = await _dio.get(
|
final res = await _dio.get(
|
||||||
@ -49,6 +52,7 @@ class AuthnService {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("AuthnService.produceOtp(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -63,6 +67,7 @@ class AuthnService {
|
|||||||
required String captcha,
|
required String captcha,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("AuthnService.loginNormal(): ");
|
||||||
LOGGER.i("POST: /login/signin?_allow_anonymous=true");
|
LOGGER.i("POST: /login/signin?_allow_anonymous=true");
|
||||||
|
|
||||||
final res = await _dio.post(
|
final res = await _dio.post(
|
||||||
@ -91,6 +96,7 @@ class AuthnService {
|
|||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("AuthnService.loginNormal(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -100,8 +106,10 @@ class AuthnService {
|
|||||||
required ExpectedErrorHandler expectedErrorHandler,
|
required ExpectedErrorHandler expectedErrorHandler,
|
||||||
required String code,
|
required String code,
|
||||||
}) async {
|
}) async {
|
||||||
|
LOGGER.i("AuthnService.scanCode(): ");
|
||||||
final token = MaxKeyPersistent.instance.token;
|
final token = MaxKeyPersistent.instance.token;
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
|
LOGGER.i("未登录");
|
||||||
expectedErrorHandler("未登录");
|
expectedErrorHandler("未登录");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -122,6 +130,7 @@ class AuthnService {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("AuthnService.scanCode(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -148,9 +157,11 @@ class AuthnService {
|
|||||||
/// 登出并清除本地缓存的 token
|
/// 登出并清除本地缓存的 token
|
||||||
Future<void> logout() async {
|
Future<void> logout() async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("AuthnService.logout(): ");
|
||||||
LOGGER.i("GET: /logout");
|
LOGGER.i("GET: /logout");
|
||||||
await _dio.get("/logout");
|
await _dio.get("/logout").timeout(const Duration(seconds: 5));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("AuthnService.logout(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ class ImageCaptchaService {
|
|||||||
|
|
||||||
Future<Uint8List?> captcha({required String state}) async {
|
Future<Uint8List?> captcha({required String state}) async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("ImageCaptchaService.captcha(): ");
|
||||||
LOGGER.i("GET: /captcha?_allow_anonymous=true");
|
LOGGER.i("GET: /captcha?_allow_anonymous=true");
|
||||||
|
|
||||||
final res = await _dio.get(
|
final res = await _dio.get(
|
||||||
@ -20,6 +21,7 @@ class ImageCaptchaService {
|
|||||||
final String base64Image = res.data["data"]["image"];
|
final String base64Image = res.data["data"]["image"];
|
||||||
return base64.decode(base64Image.split(",")[1]);
|
return base64.decode(base64Image.split(",")[1]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("ImageCaptchaService.captcha(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -7,6 +7,7 @@ class TimeBasedService {
|
|||||||
|
|
||||||
Future<bool> verify({required String totpCode}) async {
|
Future<bool> verify({required String totpCode}) async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("TimeBasedService.verify(): ");
|
||||||
LOGGER.i("GET: /config/verify?otp=$totpCode");
|
LOGGER.i("GET: /config/verify?otp=$totpCode");
|
||||||
|
|
||||||
final res = await _dio.get(
|
final res = await _dio.get(
|
||||||
@ -22,6 +23,7 @@ class TimeBasedService {
|
|||||||
LOGGER.i("验证成功");
|
LOGGER.i("验证成功");
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("TimeBasedService.verify(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -212,6 +212,7 @@ class UsersService {
|
|||||||
|
|
||||||
Future<MaxKeyUser?> getBasicUserInfo() async {
|
Future<MaxKeyUser?> getBasicUserInfo() async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("UsersService.getBasicUserInfo(): ");
|
||||||
LOGGER.i("GET: /users/profile/get");
|
LOGGER.i("GET: /users/profile/get");
|
||||||
|
|
||||||
final res = await _dio.get("/users/profile/get");
|
final res = await _dio.get("/users/profile/get");
|
||||||
@ -221,6 +222,7 @@ class UsersService {
|
|||||||
}
|
}
|
||||||
return MaxKeyUser.fromMap(res.data);
|
return MaxKeyUser.fromMap(res.data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.i("UsersService.getBasicUserInfo(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -228,6 +230,7 @@ class UsersService {
|
|||||||
|
|
||||||
Future<MaxKeyUserInfo?> getFullUserInfo() async {
|
Future<MaxKeyUserInfo?> getFullUserInfo() async {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.i("UsersService.getFullUserInfo(): ");
|
||||||
LOGGER.i("GET: /users/profile/get");
|
LOGGER.i("GET: /users/profile/get");
|
||||||
|
|
||||||
final res = await _dio.get("/users/profile/get");
|
final res = await _dio.get("/users/profile/get");
|
||||||
@ -238,6 +241,7 @@ class UsersService {
|
|||||||
|
|
||||||
return MaxKeyUserInfo.fromMap(res.data["data"]);
|
return MaxKeyUserInfo.fromMap(res.data["data"]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
LOGGER.e("UsersService.getFullUserInfo(): ");
|
||||||
LOGGER.e(err);
|
LOGGER.e(err);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -17,15 +17,20 @@ class _NewTotpBtn extends StatelessWidget {
|
|||||||
child: InkWell(
|
child: InkWell(
|
||||||
borderRadius: BorderRadius.circular(8.0),
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
LOGGER.i("_NewTotpBtn: ");
|
||||||
final qrCodeValue = await context.push<String?>(
|
final qrCodeValue = await context.push<String?>(
|
||||||
RoutePath.scanPage,
|
RoutePath.scanPage,
|
||||||
extra: AppLocalizations.of(context)!.homePageNewTotpBtnScanPage,
|
extra: AppLocalizations.of(context)!.homePageNewTotpBtnScanPage,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (qrCodeValue == null) return;
|
if (qrCodeValue == null) {
|
||||||
|
LOGGER.w("No QR code.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final newTotp = Totp.fromUri(qrCodeValue);
|
final newTotp = Totp.fromUri(qrCodeValue);
|
||||||
if (newTotp == null) {
|
if (newTotp == null) {
|
||||||
|
LOGGER.w("Unsupported QR code.");
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text(AppLocalizations.of(context)!.homePagenewTotpBtnErr)),
|
SnackBar(content: Text(AppLocalizations.of(context)!.homePagenewTotpBtnErr)),
|
||||||
@ -39,6 +44,7 @@ class _NewTotpBtn extends StatelessWidget {
|
|||||||
await MaxKeyPersistent.instance.saveTotps(totps);
|
await MaxKeyPersistent.instance.saveTotps(totps);
|
||||||
|
|
||||||
controller.update();
|
controller.update();
|
||||||
|
LOGGER.i("TOTP added.");
|
||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||||
|
|||||||
@ -73,7 +73,9 @@ class _TotpListView extends StatelessWidget {
|
|||||||
listenable: controller,
|
listenable: controller,
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
if (controller.totps.isEmpty) {
|
if (controller.totps.isEmpty) {
|
||||||
return Center(child: Text(AppLocalizations.of(context)!.homePageTotpListViewNoTOTP));
|
return Center(
|
||||||
|
child: Text(AppLocalizations.of(context)!
|
||||||
|
.homePageTotpListViewNoTOTP));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
@ -120,19 +122,22 @@ class _TotpListView extends StatelessWidget {
|
|||||||
final confirm = await showDialog<bool>(
|
final confirm = await showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: Text(AppLocalizations.of(context)!.homePageTotpListViewConfirmDialog),
|
title: Text(AppLocalizations.of(context)!
|
||||||
|
.homePageTotpListViewConfirmDialog),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop(false);
|
Navigator.of(context).pop(false);
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.homePageTotpListViewConfirmDialogCancelBtn),
|
child: Text(AppLocalizations.of(context)!
|
||||||
|
.homePageTotpListViewConfirmDialogCancelBtn),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop(true);
|
Navigator.of(context).pop(true);
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.homePageTotpListViewConfirmDialogConfirmBtn),
|
child: Text(AppLocalizations.of(context)!
|
||||||
|
.homePageTotpListViewConfirmDialogConfirmBtn),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -179,7 +184,8 @@ class _TotpCodeCardState extends State<_TotpCodeCard> {
|
|||||||
|
|
||||||
int getValidity() {
|
int getValidity() {
|
||||||
final utc = DateTime.timestamp();
|
final utc = DateTime.timestamp();
|
||||||
return widget.totp.interval - (utc.millisecondsSinceEpoch ~/ 1000 % 30);
|
return widget.totp.interval -
|
||||||
|
(utc.millisecondsSinceEpoch ~/ 1000 % widget.totp.interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -189,12 +195,10 @@ class _TotpCodeCardState extends State<_TotpCodeCard> {
|
|||||||
validity = getValidity();
|
validity = getValidity();
|
||||||
|
|
||||||
updater = Timer.periodic(const Duration(seconds: 1), (timer) {
|
updater = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||||
validity = getValidity();
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
validity = getValidity();
|
validity = getValidity();
|
||||||
if (validity == widget.totp.interval) {
|
if (validity == widget.totp.interval) {
|
||||||
LOGGER.i(DateTime.now());
|
LOGGER.i("totp: ${DateTime.now()}");
|
||||||
password = widget.totp.now;
|
password = widget.totp.now;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user