-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Create NFC-Pass Device Connect (#279)
* Add deferredLoading * feature: Create NFC-Pass Device Connect * feat: Create Nfc Fetcher and refactor auth bloc * Удалён AuthBloc. Его функции перенесены в Profile Bloc * Теперь в события не передаются токены доступа к апи. Управление токенами делегируется на репозиторий/remote data-source или отдельные пакеты для управления сетевыми запросами * Создан `fetchNfcCode` event для получения кода пропуск * feat: Add NFC fetching and errors feedback * Update AndroidManifest.xml
Showing
61 changed files
with
5,921 additions
and
653 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,61 @@ | ||
import 'dart:core'; | ||
|
||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
import 'package:rtu_mirea_app/common/errors/exceptions.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
abstract class UserLocalData { | ||
Future<void> setTokenToCache(String token); | ||
Future<String> getTokenFromCache(); | ||
Future<void> removeTokenFromCache(); | ||
|
||
Future<int> getNfcCodeFromCache(); | ||
Future<void> setNfcCodeToCache(int code); | ||
Future<void> removeNfcCodeFromCache(); | ||
} | ||
|
||
class UserLocalDataImpl implements UserLocalData { | ||
final SharedPreferences sharedPreferences; | ||
final FlutterSecureStorage secureStorage; | ||
|
||
UserLocalDataImpl({required this.sharedPreferences}); | ||
UserLocalDataImpl({ | ||
required this.sharedPreferences, | ||
required this.secureStorage, | ||
}); | ||
|
||
@override | ||
Future<void> setTokenToCache(String token) { | ||
return sharedPreferences.setString('auth_token', token); | ||
return secureStorage.write(key: 'lks_access_token', value: token); | ||
} | ||
|
||
@override | ||
Future<String> getTokenFromCache() { | ||
String? token = sharedPreferences.getString('auth_token'); | ||
Future<String> getTokenFromCache() async { | ||
String? token = await secureStorage.read(key: 'lks_access_token'); | ||
if (token == null) throw CacheException('Auth token are not set'); | ||
return Future.value(token); | ||
} | ||
|
||
@override | ||
Future<void> removeTokenFromCache() { | ||
return sharedPreferences.remove('auth_token'); | ||
return secureStorage.delete(key: 'lks_access_token'); | ||
} | ||
|
||
@override | ||
Future<int> getNfcCodeFromCache() async { | ||
String? value = await secureStorage.read(key: 'nfc_code'); | ||
|
||
if (value == null) throw CacheException('NFC code are not set'); | ||
|
||
return Future.value(int.parse(value)); | ||
} | ||
|
||
@override | ||
Future<void> setNfcCodeToCache(int code) async { | ||
await secureStorage.write(key: 'nfc_code', value: code.toString()); | ||
} | ||
|
||
@override | ||
Future<void> removeNfcCodeFromCache() async { | ||
await secureStorage.delete(key: 'nfc_code'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.