2022-03-23 14:07:52 +00:00
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
2022-03-03 17:38:30 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-03-23 14:07:52 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/forms/user/ssh_form_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/job.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
2022-03-03 17:38:30 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
import 'package:selfprivacy/config/brand_colors.dart';
|
|
|
|
import 'package:selfprivacy/config/brand_theme.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
2022-03-23 14:07:52 +00:00
|
|
|
|
|
|
|
part 'new_ssh_key.dart';
|
2022-03-03 17:38:30 +00:00
|
|
|
|
|
|
|
// Get user object as a parameter
|
|
|
|
class SshKeysPage extends StatefulWidget {
|
2022-06-05 22:40:34 +00:00
|
|
|
const SshKeysPage({required this.user, final super.key});
|
2022-03-03 17:38:30 +00:00
|
|
|
final User user;
|
|
|
|
|
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<SshKeysPage> createState() => _SshKeysPageState();
|
2022-03-03 17:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _SshKeysPageState extends State<SshKeysPage> {
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) => BrandHeroScreen(
|
|
|
|
heroTitle: 'ssh.title'.tr(),
|
|
|
|
heroSubtitle: widget.user.login,
|
|
|
|
heroIcon: BrandIcons.key,
|
|
|
|
children: <Widget>[
|
|
|
|
if (widget.user.login == 'root')
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
// Show alert card if user is root
|
|
|
|
BrandCards.outlined(
|
|
|
|
child: ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
Icons.warning_rounded,
|
|
|
|
color: Theme.of(context).colorScheme.error,
|
|
|
|
),
|
|
|
|
title: Text('ssh.root.title'.tr()),
|
|
|
|
subtitle: Text('ssh.root.subtitle'.tr()),
|
2022-03-03 17:38:30 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
BrandCards.outlined(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'ssh.create'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
leading: const Icon(Icons.add_circle_outline_rounded),
|
|
|
|
onTap: () {
|
|
|
|
showModalBottomSheet<void>(
|
|
|
|
context: context,
|
|
|
|
isScrollControlled: true,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
builder: (final BuildContext context) => Padding(
|
|
|
|
padding: MediaQuery.of(context).viewInsets,
|
|
|
|
child: _NewSshKey(widget.user),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2022-03-03 17:38:30 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
const Divider(height: 0),
|
|
|
|
// show a list of ListTiles with ssh keys
|
|
|
|
// Clicking on one should delete it
|
|
|
|
Column(
|
|
|
|
children: widget.user.sshKeys.map((final String key) {
|
|
|
|
final publicKey =
|
|
|
|
key.split(' ').length > 1 ? key.split(' ')[1] : key;
|
|
|
|
final keyType = key.split(' ')[0];
|
|
|
|
final keyName = key.split(' ').length > 2
|
|
|
|
? key.split(' ')[2]
|
|
|
|
: 'ssh.no_key_name'.tr();
|
|
|
|
return ListTile(
|
2022-03-23 14:07:52 +00:00
|
|
|
title: Text('$keyName ($keyType)'),
|
2022-03-03 17:38:30 +00:00
|
|
|
// do not overflow text
|
2022-06-05 22:40:34 +00:00
|
|
|
subtitle: Text(
|
|
|
|
publicKey,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
2022-03-03 17:38:30 +00:00
|
|
|
onTap: () {
|
2022-03-23 14:07:52 +00:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
2022-06-05 22:40:34 +00:00
|
|
|
builder: (final BuildContext context) => AlertDialog(
|
|
|
|
title: Text('ssh.delete'.tr()),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ListBody(
|
|
|
|
children: <Widget>[
|
|
|
|
Text('ssh.delete_confirm_question'.tr()),
|
|
|
|
Text('$keyName ($keyType)'),
|
|
|
|
Text(publicKey),
|
|
|
|
],
|
2022-03-23 14:07:52 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: Text('basis.cancel'.tr()),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
child: Text(
|
|
|
|
'basis.delete'.tr(),
|
|
|
|
style: const TextStyle(
|
|
|
|
color: BrandColors.red1,
|
2022-03-23 14:07:52 +00:00
|
|
|
),
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
onPressed: () {
|
|
|
|
context.read<JobsCubit>().addJob(
|
|
|
|
DeleteSSHKeyJob(
|
|
|
|
user: widget.user,
|
|
|
|
publicKey: key,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
Navigator.of(context)
|
|
|
|
..pop()
|
|
|
|
..pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-03-23 14:07:52 +00:00
|
|
|
);
|
2022-06-05 22:40:34 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-03-03 17:38:30 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
],
|
|
|
|
);
|
2022-03-03 17:38:30 +00:00
|
|
|
}
|