mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: logout
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:convert';
|
||||
import 'package:PiliPlus/build_config.dart';
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/services/loggeer.dart';
|
||||
import 'package:PiliPlus/utils/login.dart';
|
||||
import 'package:cookie_jar/cookie_jar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -313,7 +314,7 @@ Commit Hash: ${BuildConfig.commitHash}''',
|
||||
Get.back();
|
||||
try {
|
||||
dynamic res = jsonDecode(data.text!);
|
||||
Utils.afterLoginByApp(
|
||||
LoginUtils.onLogin(
|
||||
res['accessKey'],
|
||||
{'cookies': res['cookies']},
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
library dynamics.tab;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
||||
export './view.dart';
|
||||
|
||||
@@ -5,8 +5,8 @@ import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/login.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@@ -84,7 +84,7 @@ class LoginPageController extends GetxController
|
||||
if (value['status']) {
|
||||
t.cancel();
|
||||
statusQRCode.value = '扫码成功';
|
||||
await Utils.afterLoginByApp(
|
||||
await LoginUtils.onLogin(
|
||||
value['data'], value['data']['cookie_info']);
|
||||
Get.back();
|
||||
} else if (value['code'] == 86038) {
|
||||
@@ -221,7 +221,7 @@ class LoginPageController extends GetxController
|
||||
);
|
||||
if (result.data['code'] == 0) {
|
||||
try {
|
||||
await Utils.afterLoginByApp(
|
||||
await LoginUtils.onLogin(
|
||||
{'mid': '${result.data['data']['mid']}'},
|
||||
{
|
||||
'cookies':
|
||||
@@ -435,7 +435,7 @@ class LoginPageController extends GetxController
|
||||
return;
|
||||
}
|
||||
SmartDialog.showToast('正在保存身份信息');
|
||||
await Utils.afterLoginByApp(
|
||||
await LoginUtils.onLogin(
|
||||
data['token_info'], data['cookie_info']);
|
||||
Get.back();
|
||||
Get.back();
|
||||
@@ -454,7 +454,7 @@ class LoginPageController extends GetxController
|
||||
return;
|
||||
}
|
||||
SmartDialog.showToast('正在保存身份信息');
|
||||
await Utils.afterLoginByApp(data['token_info'], data['cookie_info']);
|
||||
await LoginUtils.onLogin(data['token_info'], data['cookie_info']);
|
||||
Get.back();
|
||||
} else {
|
||||
// handle login result
|
||||
@@ -517,7 +517,7 @@ class LoginPageController extends GetxController
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast('登录成功');
|
||||
var data = res['data'];
|
||||
await Utils.afterLoginByApp(data['token_info'], data['cookie_info']);
|
||||
await LoginUtils.onLogin(data['token_info'], data['cookie_info']);
|
||||
Get.back();
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:PiliPlus/pages/about/index.dart';
|
||||
import 'package:PiliPlus/pages/main/controller.dart';
|
||||
import 'package:PiliPlus/pages/setting/extra_setting.dart';
|
||||
import 'package:PiliPlus/pages/setting/play_setting.dart';
|
||||
import 'package:PiliPlus/pages/setting/privacy_setting.dart';
|
||||
@@ -9,8 +8,9 @@ import 'package:PiliPlus/pages/setting/video_setting.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/login.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../http/init.dart';
|
||||
@@ -205,22 +205,26 @@ class _SettingPageState extends State<SettingPage> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// 清空cookie
|
||||
await Request.cookieManager.cookieJar.deleteAll();
|
||||
await CookieManager().deleteAllCookies();
|
||||
Request.dio.options.headers['cookie'] = '';
|
||||
// 清空本地存储的用户标识
|
||||
GStorage.userInfo.put('userInfoCache', null);
|
||||
GStorage.localCache.put(LocalCacheKey.accessKey,
|
||||
{'mid': -1, 'value': '', 'refresh': ''});
|
||||
_isLogin.value = false;
|
||||
if (Get.isRegistered<MainController>()) {
|
||||
MainController mainController =
|
||||
Get.find<MainController>();
|
||||
mainController.isLogin.value = false;
|
||||
SmartDialog.showLoading();
|
||||
dynamic res = await Request().post(
|
||||
'https://passport.bilibili.com/login/exit/v2',
|
||||
data: {
|
||||
'biliCSRF': await Request.getCsrf(),
|
||||
},
|
||||
options: Options(
|
||||
contentType:
|
||||
Headers.formUrlEncodedContentType,
|
||||
),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
await LoginUtils.onLogout();
|
||||
_isLogin.value = false;
|
||||
SmartDialog.dismiss();
|
||||
Get.back();
|
||||
} else {
|
||||
SmartDialog.dismiss();
|
||||
SmartDialog.showToast('${res.data['message']}');
|
||||
}
|
||||
await LoginUtils.onLogout();
|
||||
Get.back();
|
||||
},
|
||||
child: const Text('确认'),
|
||||
)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
library video_reply_new;
|
||||
|
||||
export './view.dart';
|
||||
export './view.dart';
|
||||
|
||||
@@ -1,24 +1,137 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/http/loading_state.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/pages/live/controller.dart';
|
||||
import 'package:PiliPlus/pages/main/controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/index.dart';
|
||||
import 'package:PiliPlus/pages/home/index.dart';
|
||||
import 'package:PiliPlus/pages/media/index.dart';
|
||||
import 'package:PiliPlus/pages/mine/index.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:webview_cookie_manager/webview_cookie_manager.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart' as web;
|
||||
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/http/user.dart';
|
||||
|
||||
class LoginUtils {
|
||||
static Future onLogin(Map<String, dynamic> token_info, cookie_info) async {
|
||||
try {
|
||||
GStorage.localCache.put(LocalCacheKey.accessKey, {
|
||||
'mid': token_info['mid'],
|
||||
'value': token_info['access_token'] ?? token_info['value'],
|
||||
'refresh': token_info['refresh_token'] ?? token_info['refresh']
|
||||
});
|
||||
List<dynamic> cookieInfo = cookie_info['cookies'];
|
||||
List<Cookie> cookies = [];
|
||||
String cookieStrings = cookieInfo.map((cookie) {
|
||||
String cstr =
|
||||
'${cookie['name']}=${cookie['value']};Domain=.bilibili.com;Path=/;';
|
||||
cookies.add(Cookie.fromSetCookieValue(cstr));
|
||||
return cstr;
|
||||
}).join('');
|
||||
List<String> urls = [
|
||||
HttpString.baseUrl,
|
||||
HttpString.apiBaseUrl,
|
||||
HttpString.tUrl
|
||||
];
|
||||
for (var url in urls) {
|
||||
await Request.cookieManager.cookieJar
|
||||
.saveFromResponse(Uri.parse(url), cookies);
|
||||
}
|
||||
Request.dio.options.headers['cookie'] = cookieStrings;
|
||||
await WebviewCookieManager().setCookies(cookies);
|
||||
for (Cookie item in cookies) {
|
||||
await web.CookieManager().setCookie(
|
||||
url: web.WebUri(item.domain ?? ''),
|
||||
name: item.name,
|
||||
value: item.value,
|
||||
path: item.path ?? '',
|
||||
domain: item.domain,
|
||||
isSecure: item.secure,
|
||||
isHttpOnly: item.httpOnly,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('设置登录态失败,$e');
|
||||
}
|
||||
final result = await UserHttp.userInfo();
|
||||
if (result['status'] && result['data'].isLogin) {
|
||||
SmartDialog.showToast('登录成功,当前采用「'
|
||||
'${GStorage.setting.get(SettingBoxKey.defaultRcmdType, defaultValue: 'app')}'
|
||||
'端」推荐');
|
||||
await GStorage.userInfo.put('userInfoCache', result['data']);
|
||||
try {
|
||||
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 (_) {}
|
||||
|
||||
for (int i = 0; i < tabsConfig.length; i++) {
|
||||
try {
|
||||
Get.find<DynamicsTabController>(tag: tabsConfig[i]['tag'])
|
||||
.onRefresh();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
try {
|
||||
Get.find<MediaController>()
|
||||
..mid = result['data'].mid
|
||||
..onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<LiveController>()
|
||||
..isLogin.value = true
|
||||
..fetchLiveFollowing();
|
||||
} catch (_) {}
|
||||
} else {
|
||||
// 获取用户信息失败
|
||||
SmartDialog.showNotify(
|
||||
msg: '登录失败,请检查cookie是否正确,${result['message']}',
|
||||
notifyType: NotifyType.warning);
|
||||
}
|
||||
}
|
||||
|
||||
static Future onLogout() async {
|
||||
await Request.cookieManager.cookieJar.deleteAll();
|
||||
await web.CookieManager().deleteAllCookies();
|
||||
Request.dio.options.headers['cookie'] = '';
|
||||
|
||||
await GStorage.userInfo.delete('userInfoCache');
|
||||
await GStorage.localCache.delete(LocalCacheKey.accessKey);
|
||||
|
||||
try {
|
||||
Get.find<MainController>().isLogin.value = false;
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<MineController>()
|
||||
|
||||
@@ -10,19 +10,11 @@ import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/http/member.dart';
|
||||
import 'package:PiliPlus/http/search.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/bangumi/info.dart';
|
||||
import 'package:PiliPlus/models/common/dynamics_type.dart';
|
||||
import 'package:PiliPlus/models/common/search_type.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/models/live/item.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/tab/controller.dart';
|
||||
import 'package:PiliPlus/pages/home/controller.dart';
|
||||
import 'package:PiliPlus/pages/live/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';
|
||||
@@ -37,8 +29,6 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:webview_cookie_manager/webview_cookie_manager.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart' as web;
|
||||
import 'package:html/dom.dart' as dom;
|
||||
import 'package:html/parser.dart' as html_parser;
|
||||
import 'package:path/path.dart' as path;
|
||||
@@ -296,99 +286,6 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
static Future afterLoginByApp(
|
||||
Map<String, dynamic> token_info, cookie_info) async {
|
||||
try {
|
||||
GStorage.localCache.put(LocalCacheKey.accessKey, {
|
||||
'mid': token_info['mid'],
|
||||
'value': token_info['access_token'] ?? token_info['value'],
|
||||
'refresh': token_info['refresh_token'] ?? token_info['refresh']
|
||||
});
|
||||
List<dynamic> cookieInfo = cookie_info['cookies'];
|
||||
List<Cookie> cookies = [];
|
||||
String cookieStrings = cookieInfo.map((cookie) {
|
||||
String cstr =
|
||||
'${cookie['name']}=${cookie['value']};Domain=.bilibili.com;Path=/;';
|
||||
cookies.add(Cookie.fromSetCookieValue(cstr));
|
||||
return cstr;
|
||||
}).join('');
|
||||
List<String> urls = [
|
||||
HttpString.baseUrl,
|
||||
HttpString.apiBaseUrl,
|
||||
HttpString.tUrl
|
||||
];
|
||||
for (var url in urls) {
|
||||
await Request.cookieManager.cookieJar
|
||||
.saveFromResponse(Uri.parse(url), cookies);
|
||||
}
|
||||
Request.dio.options.headers['cookie'] = cookieStrings;
|
||||
await WebviewCookieManager().setCookies(cookies);
|
||||
for (Cookie item in cookies) {
|
||||
await web.CookieManager().setCookie(
|
||||
url: web.WebUri(item.domain ?? ''),
|
||||
name: item.name,
|
||||
value: item.value,
|
||||
path: item.path ?? '',
|
||||
domain: item.domain,
|
||||
isSecure: item.secure,
|
||||
isHttpOnly: item.httpOnly,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('设置登录态失败,$e');
|
||||
}
|
||||
final result = await UserHttp.userInfo();
|
||||
if (result['status'] && result['data'].isLogin) {
|
||||
SmartDialog.showToast('登录成功,当前采用「'
|
||||
'${GStorage.setting.get(SettingBoxKey.defaultRcmdType, defaultValue: 'app')}'
|
||||
'端」推荐');
|
||||
await GStorage.userInfo.put('userInfoCache', result['data']);
|
||||
try {
|
||||
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 (_) {}
|
||||
|
||||
for (int i = 0; i < tabsConfig.length; i++) {
|
||||
try {
|
||||
Get.find<DynamicsTabController>(tag: tabsConfig[i]['tag'])
|
||||
.onRefresh();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
try {
|
||||
Get.find<MediaController>()
|
||||
..mid = result['data'].mid
|
||||
..onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<LiveController>()
|
||||
..isLogin.value = true
|
||||
..fetchLiveFollowing();
|
||||
} catch (_) {}
|
||||
} else {
|
||||
// 获取用户信息失败
|
||||
SmartDialog.showNotify(
|
||||
msg: '登录失败,请检查cookie是否正确,${result['message']}',
|
||||
notifyType: NotifyType.warning);
|
||||
}
|
||||
}
|
||||
|
||||
static bool isStringNumeric(str) {
|
||||
RegExp numericRegex = RegExp(r'^[\d\.]+$');
|
||||
return numericRegex.hasMatch(str.toString());
|
||||
|
||||
Reference in New Issue
Block a user