opt: login status processing
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:pilipala/utils/login.dart';
|
||||
|
||||
class ApiInterceptor extends Interceptor {
|
||||
@override
|
||||
@ -18,6 +19,9 @@ class ApiInterceptor extends Interceptor {
|
||||
void onResponse(Response response, ResponseInterceptorHandler handler) {
|
||||
try {
|
||||
// 在响应之后处理数据
|
||||
if (response.data['code'] == -101) {
|
||||
LoginUtils.loginOut();
|
||||
}
|
||||
} catch (err) {
|
||||
print('ApiInterceptor: $err');
|
||||
}
|
||||
|
@ -61,16 +61,7 @@ class SettingController extends GetxController {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// 清空cookie
|
||||
await Request.cookieManager.cookieJar.deleteAll();
|
||||
Request.dio.options.headers['cookie'] = '';
|
||||
|
||||
// 清空本地存储的用户标识
|
||||
userInfoCache.put('userInfoCache', null);
|
||||
localCache
|
||||
.put(LocalCacheKey.accessKey, {'mid': -1, 'value': ''});
|
||||
|
||||
await LoginUtils.refreshLoginStatus(false);
|
||||
await LoginUtils.loginOut();
|
||||
SmartDialog.dismiss().then((value) => Get.back());
|
||||
},
|
||||
child: const Text('确认'),
|
||||
|
@ -7,15 +7,20 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/http/index.dart';
|
||||
import 'package:pilipala/http/user.dart';
|
||||
import 'package:pilipala/pages/dynamics/index.dart';
|
||||
import 'package:pilipala/pages/home/index.dart';
|
||||
import 'package:pilipala/pages/mine/index.dart';
|
||||
import 'package:pilipala/utils/cookie.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class LoginUtils {
|
||||
static Box userInfoCache = GStrorage.userInfo;
|
||||
static Box localCache = GStrorage.localCache;
|
||||
|
||||
static Future refreshLoginStatus(bool status) async {
|
||||
try {
|
||||
// 更改我的页面登录状态
|
||||
@ -109,4 +114,14 @@ class LoginUtils {
|
||||
Clipboard.setData(ClipboardData(text: content));
|
||||
}
|
||||
}
|
||||
|
||||
// 退出登录
|
||||
static loginOut() async {
|
||||
await Request.cookieManager.cookieJar.deleteAll();
|
||||
Request.dio.options.headers['cookie'] = '';
|
||||
userInfoCache.put('userInfoCache', null);
|
||||
localCache.put(LocalCacheKey.accessKey, {'mid': -1, 'value': ''});
|
||||
GlobalDataCache().userInfo = null;
|
||||
await refreshLoginStatus(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user