mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 08:07:59 -06:00
Initial commit
This commit is contained in:
66
lib/features/login/model/authentication_information.dart
Normal file
66
lib/features/login/model/authentication_information.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter_paperless_mobile/core/type/json.dart';
|
||||
import 'package:flutter_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 serverUrl;
|
||||
final ClientCertificate? clientCertificate;
|
||||
|
||||
AuthenticationInformation({
|
||||
required this.username,
|
||||
required this.password,
|
||||
required this.token,
|
||||
required this.serverUrl,
|
||||
this.clientCertificate,
|
||||
});
|
||||
|
||||
AuthenticationInformation.fromJson(JSON json)
|
||||
: username = json[usernameKey],
|
||||
password = json[passwordKey],
|
||||
token = json[tokenKey],
|
||||
serverUrl = json[serverUrlKey],
|
||||
clientCertificate = json[clientCertificateKey] != null
|
||||
? ClientCertificate.fromJson(json[clientCertificateKey])
|
||||
: null;
|
||||
|
||||
JSON toJson() {
|
||||
return {
|
||||
usernameKey: username,
|
||||
passwordKey: password,
|
||||
tokenKey: token,
|
||||
serverUrlKey: serverUrl,
|
||||
clientCertificateKey: clientCertificate?.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
bool get isValid {
|
||||
return serverUrl.isNotEmpty && token.isNotEmpty;
|
||||
}
|
||||
|
||||
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 ??
|
||||
(removeClientCertificate ? null : this.clientCertificate),
|
||||
);
|
||||
}
|
||||
}
|
||||
39
lib/features/login/model/client_certificate.dart
Normal file
39
lib/features/login/model/client_certificate.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_paperless_mobile/core/type/json.dart';
|
||||
|
||||
class ClientCertificate {
|
||||
static const bytesKey = 'bytes';
|
||||
static const passphraseKey = 'passphrase';
|
||||
|
||||
final Uint8List bytes;
|
||||
final String? passphrase;
|
||||
|
||||
ClientCertificate({required this.bytes, this.passphrase});
|
||||
|
||||
static ClientCertificate? nullable(Uint8List? bytes, {String? passphrase}) {
|
||||
if (bytes != null) {
|
||||
return ClientCertificate(bytes: bytes, passphrase: passphrase);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
JSON toJson() {
|
||||
return {
|
||||
bytesKey: base64Encode(bytes),
|
||||
passphraseKey: passphrase,
|
||||
};
|
||||
}
|
||||
|
||||
ClientCertificate.fromJson(JSON json)
|
||||
: bytes = base64Decode(json[bytesKey]),
|
||||
passphrase = json[passphraseKey];
|
||||
|
||||
ClientCertificate copyWith({Uint8List? bytes, String? passphrase}) {
|
||||
return ClientCertificate(
|
||||
bytes: bytes ?? this.bytes,
|
||||
passphrase: passphrase ?? this.passphrase,
|
||||
);
|
||||
}
|
||||
}
|
||||
13
lib/features/login/model/user_credentials.model.dart
Normal file
13
lib/features/login/model/user_credentials.model.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
class UserCredentials {
|
||||
final String? username;
|
||||
final String? password;
|
||||
|
||||
UserCredentials({this.username, this.password});
|
||||
|
||||
UserCredentials copyWith({String? username, String? password}) {
|
||||
return UserCredentials(
|
||||
username: username ?? this.username,
|
||||
password: password ?? this.password,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user