feat: Implement switching between accounts (multi user support), still WIP

This commit is contained in:
Anton Stubenbord
2023-04-21 01:32:43 +02:00
parent 1334f546ee
commit 95dd0a2405
50 changed files with 1055 additions and 721 deletions

View File

@@ -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,
);
}
}

View 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,
);
}
}

View 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,
);
}
}

View 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,
});
}

View 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,
});
}

View File

@@ -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,
);
}
}