mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-15 00:12:22 -06:00
feat: Implement switching between accounts (multi user support), still WIP
This commit is contained in:
@@ -3,44 +3,15 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:hive_flutter/adapters.dart';
|
||||
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
|
||||
import 'package:paperless_mobile/core/type/types.dart';
|
||||
|
||||
part 'client_certificate.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.clientCertificate)
|
||||
class ClientCertificate {
|
||||
static const bytesKey = 'bytes';
|
||||
static const passphraseKey = 'passphrase';
|
||||
|
||||
@HiveField(0)
|
||||
final Uint8List bytes;
|
||||
Uint8List bytes;
|
||||
@HiveField(1)
|
||||
final String? passphrase;
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
19
lib/features/login/model/client_certificate_form_model.dart
Normal file
19
lib/features/login/model/client_certificate_form_model.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
class ClientCertificateFormModel {
|
||||
static const bytesKey = 'bytes';
|
||||
static const passphraseKey = 'passphrase';
|
||||
|
||||
final Uint8List bytes;
|
||||
final String? passphrase;
|
||||
|
||||
ClientCertificateFormModel({required this.bytes, this.passphrase});
|
||||
|
||||
ClientCertificateFormModel copyWith({Uint8List? bytes, String? passphrase}) {
|
||||
return ClientCertificateFormModel(
|
||||
bytes: bytes ?? this.bytes,
|
||||
passphrase: passphrase ?? this.passphrase,
|
||||
);
|
||||
}
|
||||
}
|
||||
13
lib/features/login/model/login_form_credentials.dart
Normal file
13
lib/features/login/model/login_form_credentials.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
class LoginFormCredentials {
|
||||
final String? username;
|
||||
final String? password;
|
||||
|
||||
LoginFormCredentials({this.username, this.password});
|
||||
|
||||
LoginFormCredentials copyWith({String? username, String? password}) {
|
||||
return LoginFormCredentials(
|
||||
username: username ?? this.username,
|
||||
password: password ?? this.password,
|
||||
);
|
||||
}
|
||||
}
|
||||
20
lib/features/login/model/user_account.dart
Normal file
20
lib/features/login/model/user_account.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:hive_flutter/adapters.dart';
|
||||
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
|
||||
|
||||
part 'user_account.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.userAccount)
|
||||
class UserAccount {
|
||||
@HiveField(0)
|
||||
final String serverUrl;
|
||||
@HiveField(1)
|
||||
final String username;
|
||||
@HiveField(2)
|
||||
final String? fullName;
|
||||
|
||||
UserAccount({
|
||||
required this.serverUrl,
|
||||
required this.username,
|
||||
this.fullName,
|
||||
});
|
||||
}
|
||||
18
lib/features/login/model/user_credentials.dart
Normal file
18
lib/features/login/model/user_credentials.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
|
||||
import 'package:paperless_mobile/features/login/model/client_certificate.dart';
|
||||
|
||||
part 'user_credentials.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.userCredentials)
|
||||
class UserCredentials extends HiveObject {
|
||||
@HiveField(0)
|
||||
final String token;
|
||||
@HiveField(1)
|
||||
final ClientCertificate? clientCertificate;
|
||||
|
||||
UserCredentials({
|
||||
required this.token,
|
||||
this.clientCertificate,
|
||||
});
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
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