Use regular storage for pass
This commit is contained in:
parent
b3907d0c6c
commit
930fc53767
3 changed files with 16 additions and 6 deletions
|
|
@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:app_links/app_links.dart';
|
||||
import 'package:rate_my_app/rate_my_app.dart';
|
||||
import 'package:traccar_client/geolocation_service.dart';
|
||||
import 'package:traccar_client/password_service.dart';
|
||||
import 'package:traccar_client/push_service.dart';
|
||||
import 'package:traccar_client/quick_actions.dart';
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ void main() async {
|
|||
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
|
||||
await Preferences.init();
|
||||
await Preferences.migrate();
|
||||
await PasswordService.migrate();
|
||||
await GeolocationService.init();
|
||||
await PushService.init();
|
||||
runApp(const MainApp());
|
||||
|
|
|
|||
|
|
@ -1,13 +1,22 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:traccar_client/l10n/app_localizations.dart';
|
||||
import 'package:traccar_client/preferences.dart';
|
||||
|
||||
class PasswordService {
|
||||
static final FlutterSecureStorage _secureStorage = const FlutterSecureStorage();
|
||||
static const String _passwordKey = 'password';
|
||||
|
||||
static Future<void> migrate() async {
|
||||
final oldPassword = await _secureStorage.read(key: _passwordKey);
|
||||
if (oldPassword == null) return;
|
||||
await Preferences.instance.setString(_passwordKey, oldPassword);
|
||||
await _secureStorage.delete(key: _passwordKey);
|
||||
}
|
||||
|
||||
static Future<bool> authenticate(BuildContext context) async {
|
||||
if (!await _secureStorage.containsKey(key: _passwordKey)) return true;
|
||||
final storedPassword = Preferences.instance.getString(_passwordKey);
|
||||
if (storedPassword == null || storedPassword.isEmpty) return true;
|
||||
final controller = TextEditingController();
|
||||
bool? result;
|
||||
if (context.mounted) {
|
||||
|
|
@ -28,9 +37,8 @@ class PasswordService {
|
|||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final password = await _secureStorage.read(key: _passwordKey);
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context, password == controller.text);
|
||||
Navigator.pop(context, storedPassword == controller.text);
|
||||
}
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.okButton),
|
||||
|
|
@ -50,9 +58,9 @@ class PasswordService {
|
|||
|
||||
static Future<void> setPassword(String password) async {
|
||||
if (password.isNotEmpty) {
|
||||
await _secureStorage.write(key: _passwordKey, value: password);
|
||||
await Preferences.instance.setString(_passwordKey, password);
|
||||
} else {
|
||||
await _secureStorage.delete(key: _passwordKey);
|
||||
await Preferences.instance.remove(_passwordKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Preferences {
|
|||
fastestInterval, buffer, wakelock, stopDetection,
|
||||
lastTimestamp, lastLatitude, lastLongitude, lastHeading,
|
||||
'device_id_preference', 'server_url_preference', 'accuracy_preference',
|
||||
'frequency_preference', 'distance_preference', 'buffer_preference',
|
||||
'frequency_preference', 'distance_preference', 'buffer_preference', 'password',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue