feat: New change password page with server capabilities check

This commit is contained in:
krille-chan 2023-12-23 09:48:35 +01:00
commit 5847fe0546
No known key found for this signature in database
7 changed files with 296 additions and 94 deletions

View file

@ -23,42 +23,6 @@ class SettingsSecurity extends StatefulWidget {
}
class SettingsSecurityController extends State<SettingsSecurity> {
void changePasswordAccountAction() async {
final input = await showTextInputDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context)!.changePassword,
okLabel: L10n.of(context)!.ok,
cancelLabel: L10n.of(context)!.cancel,
textFields: [
DialogTextField(
hintText: L10n.of(context)!.chooseAStrongPassword,
obscureText: true,
minLines: 1,
maxLines: 1,
),
DialogTextField(
hintText: L10n.of(context)!.repeatPassword,
obscureText: true,
minLines: 1,
maxLines: 1,
),
],
);
if (input == null) return;
final success = await showFutureLoadingDialog(
context: context,
future: () => Matrix.of(context)
.client
.changePassword(input.last, oldPassword: input.first),
);
if (success.error == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(L10n.of(context)!.passwordHasBeenChanged)),
);
}
}
void setAppLockAction() async {
if (AppLock.of(context).isActive) {
AppLock.of(context).showLockScreen();

View file

@ -4,6 +4,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
import 'package:fluffychat/utils/beautify_string_extension.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart';
@ -20,66 +21,119 @@ class SettingsSecurityView extends StatelessWidget {
body: ListTileTheme(
iconColor: Theme.of(context).colorScheme.onBackground,
child: MaxWidthBody(
child: Column(
children: [
ListTile(
leading: const Icon(Icons.block_outlined),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(L10n.of(context)!.blockedUsers),
onTap: () => context.go('/rooms/settings/security/ignorelist'),
),
ListTile(
leading: const Icon(Icons.password_outlined),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(
L10n.of(context)!.changePassword,
),
onTap: controller.changePasswordAccountAction,
),
ListTile(
leading: const Icon(Icons.mail_outlined),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(L10n.of(context)!.passwordRecovery),
onTap: () => context.go('/rooms/settings/security/3pid'),
),
if (Matrix.of(context).client.encryption != null) ...{
const Divider(thickness: 1),
if (PlatformInfos.isMobile)
child: FutureBuilder(
future: Matrix.of(context)
.client
.getCapabilities()
.timeout(const Duration(seconds: 10)),
builder: (context, snapshot) {
final capabilities = snapshot.data;
final error = snapshot.error;
if (error == null && capabilities == null) {
return const Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
),
);
}
return Column(
children: [
if (error != null)
ListTile(
leading: const Icon(
Icons.warning_outlined,
color: Colors.orange,
),
title: Text(
error.toLocalizedString(context),
style: const TextStyle(color: Colors.orange),
),
),
if (capabilities?.mChangePassword?.enabled == true ||
error != null) ...[
ListTile(
leading: const Icon(Icons.password_outlined),
trailing: error != null
? null
: const Icon(Icons.chevron_right_outlined),
title: Text(
L10n.of(context)!.changePassword,
style: TextStyle(
decoration:
error == null ? null : TextDecoration.lineThrough,
),
),
onTap: error != null
? null
: () =>
context.go('/rooms/settings/security/password'),
),
ListTile(
leading: const Icon(Icons.mail_outlined),
trailing: error != null
? null
: const Icon(Icons.chevron_right_outlined),
title: Text(
L10n.of(context)!.passwordRecovery,
style: TextStyle(
decoration:
error == null ? null : TextDecoration.lineThrough,
),
),
onTap: error != null
? null
: () => context.go('/rooms/settings/security/3pid'),
),
const Divider(),
],
ListTile(
leading: const Icon(Icons.lock_outlined),
leading: const Icon(Icons.block_outlined),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(L10n.of(context)!.appLock),
onTap: controller.setAppLockAction,
title: Text(L10n.of(context)!.blockedUsers),
onTap: () =>
context.go('/rooms/settings/security/ignorelist'),
),
ListTile(
title: Text(L10n.of(context)!.yourPublicKey),
subtitle: Text(
Matrix.of(context).client.fingerprintKey.beautified,
style: const TextStyle(fontFamily: 'monospace'),
if (Matrix.of(context).client.encryption != null) ...{
const Divider(thickness: 1),
if (PlatformInfos.isMobile)
ListTile(
leading: const Icon(Icons.lock_outlined),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(L10n.of(context)!.appLock),
onTap: controller.setAppLockAction,
),
ListTile(
title: Text(L10n.of(context)!.yourPublicKey),
subtitle: Text(
Matrix.of(context).client.fingerprintKey.beautified,
style: const TextStyle(fontFamily: 'monospace'),
),
leading: const Icon(Icons.vpn_key_outlined),
),
},
const Divider(height: 1),
ListTile(
leading: const Icon(Icons.tap_and_play),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(
L10n.of(context)!.dehydrate,
style: const TextStyle(color: Colors.red),
),
onTap: controller.dehydrateAction,
),
leading: const Icon(Icons.vpn_key_outlined),
),
},
const Divider(height: 1),
ListTile(
leading: const Icon(Icons.tap_and_play),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(
L10n.of(context)!.dehydrate,
style: const TextStyle(color: Colors.red),
),
onTap: controller.dehydrateAction,
),
ListTile(
leading: const Icon(Icons.delete_outlined),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(
L10n.of(context)!.deleteAccount,
style: const TextStyle(color: Colors.red),
),
onTap: controller.deleteAccountAction,
),
],
ListTile(
leading: const Icon(Icons.delete_outlined),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(
L10n.of(context)!.deleteAccount,
style: const TextStyle(color: Colors.red),
),
onTap: controller.deleteAccountAction,
),
],
);
},
),
),
),