feat : remember me for chicken module
This commit is contained in:
@@ -2,7 +2,8 @@ library;
|
||||
|
||||
export 'package:android_intent_plus/android_intent.dart';
|
||||
export 'package:android_intent_plus/flag.dart';
|
||||
export 'package:cached_network_image/cached_network_image.dart' ;
|
||||
export 'package:cached_network_image/cached_network_image.dart';
|
||||
export 'package:collection/collection.dart';
|
||||
export 'package:connectivity_plus/connectivity_plus.dart';
|
||||
export 'package:device_info_plus/device_info_plus.dart';
|
||||
export 'package:dio/dio.dart';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/utils/local/local_utils.dart';
|
||||
|
||||
part 'user_local_model.g.dart';
|
||||
|
||||
@@ -13,27 +12,18 @@ class UserLocalModel extends HiveObject {
|
||||
String? token;
|
||||
@HiveField(3)
|
||||
String? refreshToken;
|
||||
@HiveField(4)
|
||||
String? name;
|
||||
|
||||
@HiveField(5)
|
||||
Module? module;
|
||||
|
||||
@HiveField(6)
|
||||
String? backend;
|
||||
|
||||
@HiveField(7)
|
||||
String? apiKey;
|
||||
|
||||
UserLocalModel({
|
||||
this.username,
|
||||
this.password,
|
||||
this.token,
|
||||
this.refreshToken,
|
||||
this.name,
|
||||
this.module,
|
||||
this.backend,
|
||||
this.apiKey,
|
||||
});
|
||||
|
||||
UserLocalModel copyWith({
|
||||
@@ -41,20 +31,16 @@ class UserLocalModel extends HiveObject {
|
||||
String? password,
|
||||
String? token,
|
||||
String? refreshToken,
|
||||
String? name,
|
||||
Module? module,
|
||||
String? backend,
|
||||
String? apiKey,
|
||||
}) {
|
||||
return UserLocalModel(
|
||||
username: username ?? this.username,
|
||||
password: password ?? this.password,
|
||||
token: token ?? this.token,
|
||||
refreshToken: refreshToken ?? this.refreshToken,
|
||||
name: name ?? this.name,
|
||||
module: module ?? this.module,
|
||||
backend: backend ?? this.backend,
|
||||
apiKey: apiKey ?? this.apiKey,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,15 @@ class UserLocalModelAdapter extends TypeAdapter<UserLocalModel> {
|
||||
password: fields[1] as String?,
|
||||
token: fields[2] as String?,
|
||||
refreshToken: fields[3] as String?,
|
||||
name: fields[4] as String?,
|
||||
module: fields[5] as Module?,
|
||||
backend: fields[6] as String?,
|
||||
apiKey: fields[7] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, UserLocalModel obj) {
|
||||
writer
|
||||
..writeByte(8)
|
||||
..writeByte(6)
|
||||
..writeByte(0)
|
||||
..write(obj.username)
|
||||
..writeByte(1)
|
||||
@@ -40,14 +38,10 @@ class UserLocalModelAdapter extends TypeAdapter<UserLocalModel> {
|
||||
..write(obj.token)
|
||||
..writeByte(3)
|
||||
..write(obj.refreshToken)
|
||||
..writeByte(4)
|
||||
..write(obj.name)
|
||||
..writeByte(5)
|
||||
..write(obj.module)
|
||||
..writeByte(6)
|
||||
..write(obj.backend)
|
||||
..writeByte(7)
|
||||
..write(obj.apiKey);
|
||||
..write(obj.backend);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:rasadyar_core/hive_registrar.g.dart';
|
||||
|
||||
class TokenStorageService extends GetxService {
|
||||
static const String _tokenBoxName = 'TokenBox';
|
||||
static const String _userPassBox = 'UserPassBox';
|
||||
static const String _appBoxName = 'AppBox';
|
||||
static const String _accessTokenKey = 'accessToken';
|
||||
static const String _refreshTokenKey = 'refreshToken';
|
||||
@@ -21,7 +22,6 @@ class TokenStorageService extends GetxService {
|
||||
Rxn<Module> appModule = Rxn(null);
|
||||
|
||||
Future<void> init() async {
|
||||
|
||||
Hive.registerAdapters();
|
||||
|
||||
final String? encryptedKey = await _secureStorage.read(key: 'hive_enc_key');
|
||||
@@ -36,6 +36,7 @@ class TokenStorageService extends GetxService {
|
||||
await _localStorage.init();
|
||||
await _localStorage.openBox(_tokenBoxName, encryptionCipher: HiveAesCipher(encryptionKey));
|
||||
await _localStorage.openBox(_appBoxName);
|
||||
await _localStorage.openBox<UserLocalModel>(_userPassBox);
|
||||
|
||||
accessToken.value = _localStorage.read<String?>(boxName: _tokenBoxName, key: _accessTokenKey);
|
||||
refreshToken.value = _localStorage.read<String?>(boxName: _tokenBoxName, key: _refreshTokenKey);
|
||||
@@ -88,4 +89,18 @@ class TokenStorageService extends GetxService {
|
||||
Future<void> saveApiKey(String key) async {
|
||||
await _localStorage.save(boxName: _tokenBoxName, key: _apiKey, value: key);
|
||||
}
|
||||
|
||||
Future<void> saveUserPass(UserLocalModel model) async {
|
||||
await _localStorage.save<UserLocalModel>(
|
||||
boxName: _userPassBox,
|
||||
key: model.module!.name,
|
||||
value: model,
|
||||
);
|
||||
}
|
||||
|
||||
UserLocalModel? getUserPass(Module module) {
|
||||
return _localStorage
|
||||
.readBox<UserLocalModel>(boxName: _userPassBox)
|
||||
?.firstWhereOrNull((element) => element.module == module);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extension ListExtensions<T> on List<T> {
|
||||
extension AppListExtensions<T> on List<T> {
|
||||
void toggle(T item) {
|
||||
if (contains(item)) {
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ packages:
|
||||
source: hosted
|
||||
version: "4.10.1"
|
||||
collection:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: collection
|
||||
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
|
||||
|
||||
@@ -62,6 +62,7 @@ dependencies:
|
||||
permission_handler: ^12.0.1
|
||||
persian_datetime_picker: ^3.1.1
|
||||
encrypt: ^5.0.3
|
||||
collection: ^1.19.1
|
||||
|
||||
#L10N tools
|
||||
intl: ^0.20.2
|
||||
|
||||
Reference in New Issue
Block a user