flutter_dashboard/lib/services/auth_service.dart
jdysya 7720d44658 feat(leetcode): 添加 LeetCode 解题进度展示
- 在 LeetCodeCard 中添加解题进度卡片,展示用户解题情况
- 在 SettingsScreen 中添加 LeetCode User Slug 配置项
- 更新 authService 以支持保存和加载 LeetCode User Slug
- 优化 LeetCode 数据获取逻辑,同时获取提交记录和解题进度
2025-06-09 19:40:42 +08:00

52 lines
1.6 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;
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');
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;
}
_isAuthenticated = true;
notifyListeners();
}
Future<void> logout() async {
await _storage.deleteAll();
_credentials.clear();
_isAuthenticated = false;
notifyListeners();
}
}