Refactored DI, serialization, added feedback to document download

This commit is contained in:
Anton Stubenbord
2022-12-06 00:39:18 +01:00
parent d79682a011
commit 75fa2f7713
51 changed files with 711 additions and 366 deletions

View File

@@ -2,30 +2,22 @@ import 'package:paperless_mobile/core/type/types.dart';
import 'package:paperless_mobile/features/login/model/client_certificate.dart';
class AuthenticationInformation {
static const usernameKey = 'username';
static const passwordKey = 'password';
static const tokenKey = 'token';
static const serverUrlKey = 'serverUrl';
static const clientCertificateKey = 'clientCertificate';
final String username;
final String password;
final String token;
final String? token;
final String serverUrl;
final ClientCertificate? clientCertificate;
AuthenticationInformation({
required this.username,
required this.password,
required this.token,
this.token,
required this.serverUrl,
this.clientCertificate,
});
AuthenticationInformation.fromJson(JSON json)
: username = json[usernameKey],
password = json[passwordKey],
token = json[tokenKey],
: token = json[tokenKey],
serverUrl = json[serverUrlKey],
clientCertificate = json[clientCertificateKey] != null
? ClientCertificate.fromJson(json[clientCertificateKey])
@@ -33,8 +25,6 @@ class AuthenticationInformation {
JSON toJson() {
return {
usernameKey: username,
passwordKey: password,
tokenKey: token,
serverUrlKey: serverUrl,
clientCertificateKey: clientCertificate?.toJson(),
@@ -42,21 +32,16 @@ class AuthenticationInformation {
}
bool get isValid {
return serverUrl.isNotEmpty && token.isNotEmpty;
return serverUrl.isNotEmpty && (token?.isNotEmpty ?? false);
}
AuthenticationInformation copyWith({
String? username,
String? password,
String? token,
String? serverUrl,
ClientCertificate? clientCertificate,
bool removeClientCertificate = false,
bool? isLocalAuthenticationEnabled,
}) {
return AuthenticationInformation(
username: username ?? this.username,
password: password ?? this.password,
token: token ?? this.token,
serverUrl: serverUrl ?? this.serverUrl,
clientCertificate: clientCertificate ??