181186 - Criar PDV Android para rodar em maquinas P.O.S.
This commit is contained in:
commit
c9983cbad5
204 files changed
+11453
No files matched your search
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
abstract interface class SecureSessionStorage {
|
||||
Future<String?> readCookie();
|
||||
|
||||
Future<String?> readServerUrl();
|
||||
|
||||
Future<String?> readSessionId();
|
||||
|
||||
Future<void> writeSession(
|
||||
{required String cookie,
|
||||
required String serverUrl,
|
||||
required String sessionId});
|
||||
|
||||
Future<void> clearCookie();
|
||||
}
|
||||
|
||||
class FlutterSecureSessionStorage implements SecureSessionStorage {
|
||||
FlutterSecureSessionStorage({FlutterSecureStorage? storage})
|
||||
: _storage = storage ?? const FlutterSecureStorage();
|
||||
|
||||
static const _cookieKey = 'pdv.odoo_session_cookie';
|
||||
static const _serverUrlKey = 'pdv.odoo_session_server_url';
|
||||
static const _sessionIdKey = 'pdv.odoo_session_id';
|
||||
final FlutterSecureStorage _storage;
|
||||
|
||||
@override
|
||||
Future<String?> readCookie() => _storage.read(key: _cookieKey);
|
||||
|
||||
@override
|
||||
Future<String?> readServerUrl() => _storage.read(key: _serverUrlKey);
|
||||
|
||||
@override
|
||||
Future<String?> readSessionId() => _storage.read(key: _sessionIdKey);
|
||||
|
||||
@override
|
||||
Future<void> writeSession(
|
||||
{required String cookie,
|
||||
required String serverUrl,
|
||||
required String sessionId}) async {
|
||||
await _storage.write(key: _cookieKey, value: cookie);
|
||||
await _storage.write(key: _serverUrlKey, value: serverUrl);
|
||||
await _storage.write(key: _sessionIdKey, value: sessionId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearCookie() async {
|
||||
await _storage.delete(key: _cookieKey);
|
||||
await _storage.delete(key: _serverUrlKey);
|
||||
await _storage.delete(key: _sessionIdKey);
|
||||
}
|
||||
}
|
||||
|
||||
class InMemorySessionStorage implements SecureSessionStorage {
|
||||
String? _cookie;
|
||||
String? _serverUrl;
|
||||
String? _sessionId;
|
||||
|
||||
@override
|
||||
Future<String?> readCookie() async => _cookie;
|
||||
|
||||
@override
|
||||
Future<String?> readServerUrl() async => _serverUrl;
|
||||
|
||||
@override
|
||||
Future<String?> readSessionId() async => _sessionId;
|
||||
|
||||
@override
|
||||
Future<void> writeSession({
|
||||
required String cookie,
|
||||
required String serverUrl,
|
||||
required String sessionId,
|
||||
}) async {
|
||||
_cookie = cookie;
|
||||
_serverUrl = serverUrl;
|
||||
_sessionId = sessionId;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearCookie() async {
|
||||
_cookie = null;
|
||||
_serverUrl = null;
|
||||
_sessionId = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'secure_session_storage.dart';
|
||||
|
||||
SecureSessionStorage createSessionStorage() {
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
return FlutterSecureSessionStorage();
|
||||
}
|
||||
if (kDebugMode) {
|
||||
return InMemorySessionStorage();
|
||||
}
|
||||
throw UnsupportedError(
|
||||
'O armazenamento seguro de sessão só está disponível em Android/iOS.',
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user