feat: Add new translations, add list of existing accounts to login page

This commit is contained in:
Anton Stubenbord
2023-05-30 01:19:27 +02:00
parent cd56f5fdb8
commit 1dc7d22d3a
19 changed files with 694 additions and 381 deletions

View File

@@ -140,20 +140,14 @@ class AuthenticationCubit extends Cubit<AuthenticationState> {
}
Future<void> removeAccount(String userId) async {
final globalSettings = Hive.box<GlobalSettings>(HiveBoxes.globalSettings).getValue()!;
final userAccountBox = Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount);
final userAppStateBox = Hive.box<LocalUserAppState>(HiveBoxes.localUserAppState);
final currentUser = globalSettings.currentLoggedInUser;
await userAccountBox.delete(userId);
await userAppStateBox.delete(userId);
await withEncryptedBox(HiveBoxes.localUserCredentials, (box) {
await withEncryptedBox<UserCredentials, void>(HiveBoxes.localUserCredentials, (box) {
box.delete(userId);
});
if (currentUser == userId) {
return logout();
}
}
///
@@ -209,10 +203,10 @@ class AuthenticationCubit extends Cubit<AuthenticationState> {
Future<void> logout() async {
await _resetExternalState();
final globalSettings = Hive.box<GlobalSettings>(HiveBoxes.globalSettings).getValue()!;
emit(const AuthenticationState.unauthenticated());
globalSettings
..currentLoggedInUser = null
..save();
emit(const AuthenticationState.unauthenticated());
}
Future<void> _resetExternalState() async {

View File

@@ -1,5 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
import 'package:paperless_mobile/core/database/tables/local_user_account.dart';
import 'package:paperless_mobile/features/login/cubit/authentication_cubit.dart';
import 'package:paperless_mobile/features/login/model/client_certificate.dart';
import 'package:paperless_mobile/features/login/model/client_certificate_form_model.dart';
import 'package:paperless_mobile/features/login/model/login_form_credentials.dart';
@@ -7,6 +12,8 @@ import 'package:paperless_mobile/features/login/view/widgets/form_fields/client_
import 'package:paperless_mobile/features/login/view/widgets/form_fields/server_address_form_field.dart';
import 'package:paperless_mobile/features/login/view/widgets/form_fields/user_credentials_form_field.dart';
import 'package:paperless_mobile/features/login/view/widgets/login_pages/server_connection_page.dart';
import 'package:paperless_mobile/features/users/view/widgets/user_account_list_tile.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'widgets/login_pages/server_login_page.dart';
import 'widgets/never_scrollable_scroll_behavior.dart';
@@ -23,11 +30,14 @@ class LoginPage extends StatefulWidget {
final String submitText;
final String titleString;
final bool showLocalAccounts;
const LoginPage({
Key? key,
required this.onSubmit,
required this.submitText,
required this.titleString,
this.showLocalAccounts = false,
}) : super(key: key);
@override
@@ -41,6 +51,7 @@ class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context) {
final localAccounts = Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount);
return Scaffold(
resizeToAvoidBottomInset: false,
body: FormBuilder(
@@ -49,6 +60,42 @@ class _LoginPageState extends State<LoginPage> {
controller: _pageController,
scrollBehavior: NeverScrollableScrollBehavior(),
children: [
if (widget.showLocalAccounts && localAccounts.isNotEmpty)
Scaffold(
appBar: AppBar(
title: Text(S.of(context)!.logInToExistingAccount),
),
bottomNavigationBar: BottomAppBar(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FilledButton(
child: Text(S.of(context)!.goToLogin),
onPressed: () {
_pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
},
),
],
),
),
body: ListView.builder(
itemBuilder: (context, index) {
final account = localAccounts.values.elementAt(index);
return Card(
child: UserAccountListTile(
account: account,
onTap: () {
context.read<AuthenticationCubit>().switchAccount(account.id);
},
),
);
},
itemCount: localAccounts.length,
),
),
ServerConnectionPage(
titleString: widget.titleString,
formBuilderKey: _formKey,