mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: login/logout
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -2,9 +2,12 @@ import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/models/common/dynamics_type.dart';
|
||||
import 'package:PiliPlus/models/user/info.dart';
|
||||
import 'package:PiliPlus/models/user/stat.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/tab/controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/index.dart';
|
||||
import 'package:PiliPlus/pages/home/index.dart';
|
||||
@@ -13,25 +16,40 @@ import 'package:PiliPlus/pages/mine/index.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class LoginUtils {
|
||||
static Future refreshLoginStatus(bool status) async {
|
||||
static Future onLogout() async {
|
||||
await GStorage.userInfo.delete('userInfoCache');
|
||||
|
||||
try {
|
||||
// logout
|
||||
if (status.not) {
|
||||
// 更改我的页面登录状态
|
||||
await Get.find<MineController>().resetUserInfo();
|
||||
Get.find<MediaController>().loadingState.value = LoadingState.loading();
|
||||
Get.find<MineController>()
|
||||
..userInfo.value = UserInfoData()
|
||||
..userStat.value = UserStat()
|
||||
..isLogin.value = false;
|
||||
MineController.anonymity.value = false;
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<HomeController>()
|
||||
..isLogin.value = false
|
||||
..userFace.value = '';
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<DynamicsController>()
|
||||
..isLogin.value = false
|
||||
..onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<MediaController>()
|
||||
..mid = null
|
||||
..loadingState.value = LoadingState.loading();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
for (int i = 0; i < tabsConfig.length; i++) {
|
||||
Get.find<DynamicsTabController>(tag: tabsConfig[i]['tag']).onRefresh();
|
||||
}
|
||||
|
||||
// 更改主页登录状态
|
||||
Get.find<HomeController>().updateLoginStatus(status);
|
||||
|
||||
Get.find<MineController>().userLogin.value = status;
|
||||
|
||||
Get.find<DynamicsController>().userLogin.value = status;
|
||||
} catch (err) {
|
||||
// SmartDialog.showToast('refreshLoginStatus error: ${err.toString()}');
|
||||
debugPrint('refreshLoginStatus error: $err');
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
static String buvid() {
|
||||
|
||||
@@ -13,12 +13,13 @@ import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/bangumi/info.dart';
|
||||
import 'package:PiliPlus/models/common/search_type.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/controller.dart';
|
||||
import 'package:PiliPlus/pages/home/controller.dart';
|
||||
import 'package:PiliPlus/pages/media/controller.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
import 'package:PiliPlus/pages/video/detail/introduction/widgets/group_panel.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/login.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
@@ -109,15 +110,30 @@ class Utils {
|
||||
'端」推荐');
|
||||
await GStorage.userInfo.put('userInfoCache', result['data']);
|
||||
try {
|
||||
Get.find<HomeController>()
|
||||
..updateLoginStatus(true)
|
||||
..userFace.value = result['data'].face;
|
||||
Get.find<MineController>()
|
||||
..isLogin.value = true
|
||||
..queryUserInfo();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<HomeController>()
|
||||
..isLogin.value = true
|
||||
..userFace.value = result['data'].face;
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<DynamicsController>()
|
||||
..isLogin.value = true
|
||||
..ownerMid = result['data'].mid
|
||||
..face = result['data'].face
|
||||
..onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<MediaController>()
|
||||
..mid = result['data'].mid
|
||||
..onRefresh();
|
||||
} catch (_) {}
|
||||
await LoginUtils.refreshLoginStatus(true);
|
||||
} else {
|
||||
// 获取用户信息失败
|
||||
SmartDialog.showNotify(
|
||||
|
||||
Reference in New Issue
Block a user