Initial commit
This commit is contained in:
129
lib/pages/bootstrap/widgets/new_passphrase_view.dart
Normal file
129
lib/pages/bootstrap/widgets/new_passphrase_view.dart
Normal file
@@ -0,0 +1,129 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:tatchat/l10n/l10n.dart';
|
||||
import 'package:tatchat/pages/bootstrap/view_model/bootstrap_view_model.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
class NewPassphraseView extends StatelessWidget {
|
||||
final BootstrapViewModel viewModel;
|
||||
|
||||
const NewPassphraseView(this.viewModel, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final canCreatePassphrase =
|
||||
viewModel.value.newPassphraseEqualsRepeatPassphrase &&
|
||||
viewModel.value.newPassphraseNumbers &&
|
||||
viewModel.value.newPassphraseSpecialCharacters &&
|
||||
viewModel.value.newPassphraseUpperAndLowerCase &&
|
||||
viewModel.value.newPassphraseLongEnough;
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
children: [
|
||||
Text(L10n.of(context).newPassphraseDescription, textAlign: .center),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
obscureText: viewModel.value.obscureText,
|
||||
readOnly: viewModel.value.isLoading,
|
||||
controller: viewModel.newPassphraseController,
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
viewModel.value.obscureText
|
||||
? Icons.visibility_off_outlined
|
||||
: Icons.visibility_outlined,
|
||||
),
|
||||
onPressed: viewModel.toggleObscureText,
|
||||
),
|
||||
hintText: L10n.of(context).newPassphrase,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
obscureText: viewModel.value.obscureText,
|
||||
readOnly: viewModel.value.isLoading,
|
||||
controller: viewModel.repeatPassphraseController,
|
||||
decoration: InputDecoration(
|
||||
hintText: L10n.of(context).repeatPassphrase,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: canCreatePassphrase && !viewModel.value.isLoading
|
||||
? () => viewModel.setOrSkipPassphrase(
|
||||
viewModel.newPassphraseController.text,
|
||||
context,
|
||||
)
|
||||
: null,
|
||||
child: viewModel.value.isLoading
|
||||
? CircularProgressIndicator.adaptive()
|
||||
: Text(L10n.of(context).continueText),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextButton(
|
||||
onPressed: viewModel.value.isLoading
|
||||
? null
|
||||
: () => viewModel.setOrSkipPassphrase(null, context),
|
||||
style: TextButton.styleFrom(foregroundColor: theme.colorScheme.error),
|
||||
child: Text(L10n.of(context).skip),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_PassphraseCheckListTile(
|
||||
checked: viewModel.value.newPassphraseEqualsRepeatPassphrase,
|
||||
label: L10n.of(context).passphrasesMatch,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_PassphraseCheckListTile(
|
||||
checked: viewModel.value.newPassphraseLongEnough,
|
||||
label: L10n.of(context).passphraseLengthRequirement,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_PassphraseCheckListTile(
|
||||
checked: viewModel.value.newPassphraseUpperAndLowerCase,
|
||||
label: L10n.of(context).passphraseUpperAndLowerCaseRequirement,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_PassphraseCheckListTile(
|
||||
checked: viewModel.value.newPassphraseSpecialCharacters,
|
||||
label: L10n.of(context).passphraseSpecialCharactersRequirement,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_PassphraseCheckListTile(
|
||||
checked: viewModel.value.newPassphraseNumbers,
|
||||
label: L10n.of(context).passphraseNumberRequirement,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PassphraseCheckListTile extends StatelessWidget {
|
||||
final String label;
|
||||
final bool checked;
|
||||
const _PassphraseCheckListTile({required this.label, required this.checked});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Row(
|
||||
spacing: 8.0,
|
||||
children: [
|
||||
Icon(
|
||||
checked ? Icons.check_circle_outlined : Icons.circle_outlined,
|
||||
color: checked
|
||||
? theme.brightness == Brightness.light
|
||||
? Colors.green.shade800
|
||||
: Colors.green.shade300
|
||||
: theme.colorScheme.error,
|
||||
size: 20,
|
||||
),
|
||||
Text(label, style: TextStyle(fontSize: 12)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
198
lib/pages/bootstrap/widgets/restore_bootstrap_view.dart
Normal file
198
lib/pages/bootstrap/widgets/restore_bootstrap_view.dart
Normal file
@@ -0,0 +1,198 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:tatchat/config/app_config.dart';
|
||||
import 'package:tatchat/l10n/l10n.dart';
|
||||
import 'package:tatchat/pages/bootstrap/view_model/bootstrap_view_model.dart';
|
||||
import 'package:tatchat/pages/key_verification/key_verification_dialog.dart';
|
||||
import 'package:tatchat/utils/date_time_extension.dart';
|
||||
import 'package:tatchat/utils/localized_exception_extension.dart';
|
||||
import 'package:tatchat/utils/matrix_sdk_extensions/device_extension.dart';
|
||||
import 'package:tatchat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:matrix/encryption/utils/key_verification.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class RestoreBootstrapView extends StatelessWidget {
|
||||
final BootstrapViewModel viewModel;
|
||||
|
||||
const RestoreBootstrapView(this.viewModel, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final keyVerification = viewModel.value.keyVerification;
|
||||
if (keyVerification != null) {
|
||||
Logs().v('Key verification state:', keyVerification.state);
|
||||
if (keyVerification.state == KeyVerificationState.askSas) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
KeyVerificationDialog(request: keyVerification).show(context);
|
||||
});
|
||||
}
|
||||
}
|
||||
final devices =
|
||||
viewModel.value.connectedDevices
|
||||
?.map(
|
||||
(device) => (
|
||||
title: device.displayname,
|
||||
lastActive: device.lastActive,
|
||||
icon: device.icon,
|
||||
),
|
||||
)
|
||||
.toList() ??
|
||||
[];
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
children: [
|
||||
if (keyVerification != null) ...[
|
||||
ListTile(
|
||||
leading:
|
||||
(keyVerification.state == KeyVerificationState.error ||
|
||||
viewModel.value.noSecretsreceived)
|
||||
? IconButton(
|
||||
onPressed: viewModel.value.isLoading
|
||||
? null
|
||||
: viewModel.retryKeyVerification,
|
||||
tooltip: L10n.of(context).tryAgain,
|
||||
icon: Icon(Icons.refresh_outlined),
|
||||
)
|
||||
: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: CircularProgressIndicator.adaptive(),
|
||||
),
|
||||
minLeadingWidth: 40,
|
||||
title: Text(
|
||||
viewModel.value.waitingForSecrets
|
||||
? L10n.of(context).waitingForKeys
|
||||
: viewModel.value.noSecretsreceived
|
||||
? L10n.of(context).noKeysTransmitted
|
||||
: L10n.of(context).restoreBootstrapDevicesDescription,
|
||||
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Material(
|
||||
color: theme.colorScheme.surfaceContainer,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: 128),
|
||||
child: Scrollbar(
|
||||
thumbVisibility: true,
|
||||
trackVisibility: true,
|
||||
controller: viewModel.devicesScrollController,
|
||||
child: ListView.builder(
|
||||
controller: viewModel.devicesScrollController,
|
||||
shrinkWrap: true,
|
||||
itemCount: devices.length,
|
||||
itemBuilder: (context, i) => ListTile(
|
||||
leading: CircleAvatar(
|
||||
foregroundColor: theme.colorScheme.onPrimary,
|
||||
backgroundColor: theme.colorScheme.primary,
|
||||
child: Icon(devices[i].icon),
|
||||
),
|
||||
title: Text(
|
||||
devices[i].title,
|
||||
maxLines: 1,
|
||||
overflow: .ellipsis,
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
subtitle: Text(
|
||||
L10n.of(context).lastActiveAgo(
|
||||
devices[i].lastActive.localizedTime(context),
|
||||
),
|
||||
style: TextStyle(fontSize: 11),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: Divider(height: 64)),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(L10n.of(context).or),
|
||||
),
|
||||
Expanded(child: Divider(height: 64)),
|
||||
],
|
||||
),
|
||||
] else ...[
|
||||
Text(
|
||||
L10n.of(context).restoreBootstrapEmptyDevicesDescription,
|
||||
textAlign: .center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
TextField(
|
||||
readOnly: viewModel.value.isLoading,
|
||||
obscureText: viewModel.value.obscureText,
|
||||
controller: viewModel.enterPassphraseOrRecovController,
|
||||
minLines: 1,
|
||||
maxLines: viewModel.value.obscureText ? 1 : 4,
|
||||
onSubmitted: (_) => viewModel.unlock(context),
|
||||
decoration: InputDecoration(
|
||||
hintText: L10n.of(context).passphraseOrKey,
|
||||
prefixIcon: IconButton(
|
||||
icon: Icon(
|
||||
viewModel.value.obscureText
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
),
|
||||
onPressed: viewModel.toggleObscureText,
|
||||
),
|
||||
errorText: viewModel.value.unlockWithError?.toLocalizedString(
|
||||
context,
|
||||
),
|
||||
errorMaxLines: 4,
|
||||
suffixIcon: viewModel.value.isLoading
|
||||
? SizedBox.square(
|
||||
dimension: 32,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||
),
|
||||
)
|
||||
: TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppConfig.borderRadius / 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
onPressed: viewModel.value.passphraseOrRecoveryKeyEntered
|
||||
? () => viewModel.unlock(context)
|
||||
: () => viewModel.openRecoveryKeyFile(context),
|
||||
child: Text(
|
||||
viewModel.value.passphraseOrRecoveryKeyEntered
|
||||
? L10n.of(context).unlock
|
||||
: L10n.of(context).openFile,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final consent = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).warning,
|
||||
message: L10n.of(context).resetAccountWarning,
|
||||
isDestructive: true,
|
||||
okLabel: L10n.of(context).resetAccount,
|
||||
);
|
||||
if (consent != OkCancelResult.ok) return;
|
||||
if (!context.mounted) return;
|
||||
viewModel.startResetAccount();
|
||||
},
|
||||
style: TextButton.styleFrom(foregroundColor: theme.colorScheme.error),
|
||||
child: Text(L10n.of(context).resetAccount),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
63
lib/pages/bootstrap/widgets/store_recovery_key_view.dart
Normal file
63
lib/pages/bootstrap/widgets/store_recovery_key_view.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:tatchat/l10n/l10n.dart';
|
||||
import 'package:tatchat/pages/bootstrap/view_model/bootstrap_view_model.dart';
|
||||
import 'package:tatchat/utils/tatu_share.dart';
|
||||
import 'package:tatchat/utils/platform_infos.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
class StoreRecoveryKeyView extends StatelessWidget {
|
||||
final BootstrapViewModel viewModel;
|
||||
const StoreRecoveryKeyView(this.viewModel, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
children: [
|
||||
Text(L10n.of(context).storeRecoveryKeyDescription),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
// TODO: Dispose this
|
||||
controller: TextEditingController(text: viewModel.value.recoveryKey),
|
||||
readOnly: true,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(Icons.copy_outlined),
|
||||
onPressed: () =>
|
||||
TatuShare.share(viewModel.value.recoveryKey!, context),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
CheckboxListTile.adaptive(
|
||||
value: viewModel.value.recoveryKeyDownloaded,
|
||||
onChanged: (copied) =>
|
||||
viewModel.toggleRecoveryKeyDownloaded(copied, context),
|
||||
title: Text(L10n.of(context).saveAsFile),
|
||||
),
|
||||
if (viewModel.supportsSecureStorage)
|
||||
CheckboxListTile.adaptive(
|
||||
value: viewModel.value.recoveryKeyStoredInSecureStorage,
|
||||
onChanged: viewModel.toggleRecoveryKeyStoredInSecureStorage,
|
||||
title: Text(_getSecureStorageLocalizedName(context)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _getSecureStorageLocalizedName(BuildContext context) {
|
||||
if (PlatformInfos.isAndroid) {
|
||||
return L10n.of(context).storeInAndroidKeystore;
|
||||
}
|
||||
if (PlatformInfos.isIOS || PlatformInfos.isMacOS) {
|
||||
return L10n.of(context).storeInAppleKeyChain;
|
||||
}
|
||||
return L10n.of(context).storeSecurlyOnThisDevice;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user