flutter_dashboard/lib/services/auth_service.dart
jdysya f8aaf86cf8 feat(kodbox): 使用用户名和密码替代 API Token(#4)
- 移除 KodBox API Token 相关代码
- 添加 KodBox 用户名和密码输入字段
- 实现 KodBox 有效 token 获取逻辑
- 更新 KodBox 日志获取和展示逻辑
- 添加文件路径点击打开功能
- 更新相关测试和依赖
2025-06-10 15:23:39 +08:00

72 lines
2.4 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class AuthService extends ChangeNotifier {
final _storage = const FlutterSecureStorage();
bool _isAuthenticated = false;
final Map<String, String> _credentials = {};
bool get isAuthenticated => _isAuthenticated;
Map<String, String> get credentials => _credentials;
Future<void> saveConfigs(String key, String value) async {
await _storage.write(key: key, value: value);
_credentials[key] = value;
_isAuthenticated = true;
notifyListeners();
}
Future<void> loadConfigs() async {
final leetcodeCookie = await _storage.read(key: 'leetcode_cookie');
final leetcodeUserSlug = await _storage.read(key: 'leetcode_user_slug');
final giteaToken = await _storage.read(key: 'gitea_token');
final giteaUserName = await _storage.read(key: 'gitea_username');
final kodboxToken = await _storage.read(key: 'kodbox_token');
final githubUserName = await _storage.read(key: 'github_username');
final githubToken = await _storage.read(key: 'github_token');
final wakatimeToken = await _storage.read(key: 'wakatime_token');
final kodboxUname = await _storage.read(key: 'kodbox_username');
final kodboxPwd = await _storage.read(key: 'kodbox_password');
if (leetcodeCookie != null) {
_credentials['leetcode_cookie'] = leetcodeCookie;
}
if (leetcodeUserSlug != null) {
_credentials['leetcode_user_slug'] = leetcodeUserSlug;
}
if (giteaToken != null) {
_credentials['gitea_token'] = giteaToken;
}
if (giteaUserName != null) {
_credentials['gitea_username'] = giteaUserName;
}
if (kodboxToken != null) {
_credentials['kodbox_token'] = kodboxToken;
}
if (githubUserName != null) {
_credentials['github_username'] = githubUserName;
}
if (githubToken != null) {
_credentials['github_token'] = githubToken;
}
if (wakatimeToken != null) {
_credentials['wakatime_token'] = wakatimeToken;
}
if (kodboxUname != null) {
_credentials['kodbox_username'] = kodboxUname;
}
if (kodboxPwd != null) {
_credentials['kodbox_password'] = kodboxPwd;
}
_isAuthenticated = true;
notifyListeners();
}
Future<void> logout() async {
await _storage.deleteAll();
_credentials.clear();
_isAuthenticated = false;
notifyListeners();
}
}