ente/lib/ui/password_reentry_page.dart

172 lines
5.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/events/subscription_purchased_event.dart';
2020-10-24 21:07:12 +00:00
import 'package:photos/ui/common_elements.dart';
2021-03-30 12:13:13 +00:00
import 'package:photos/ui/recovery_page.dart';
import 'package:photos/utils/dialog_util.dart';
2021-08-15 19:35:16 +00:00
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2021-01-05 14:27:02 +00:00
class PasswordReentryPage extends StatefulWidget {
PasswordReentryPage({Key key}) : super(key: key);
@override
2021-01-05 14:27:02 +00:00
_PasswordReentryPageState createState() => _PasswordReentryPageState();
}
2021-01-05 14:27:02 +00:00
class _PasswordReentryPageState extends State<PasswordReentryPage> {
2021-01-05 15:26:10 +00:00
final _passwordController = TextEditingController();
2021-05-12 16:20:30 +00:00
FocusNode _passwordFocusNode = FocusNode();
bool _passwordInFocus = false;
bool _passwordVisible = false;
@override
void initState() {
super.initState();
_passwordFocusNode.addListener(() {
setState(() {
_passwordInFocus = _passwordFocusNode.hasFocus;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
2021-04-01 14:40:32 +00:00
"password",
),
),
body: _getBody(),
);
}
Widget _getBody() {
2021-03-30 11:36:36 +00:00
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
child: TextFormField(
decoration: InputDecoration(
hintText: "enter your password",
contentPadding: EdgeInsets.all(20),
2021-05-12 16:20:30 +00:00
suffixIcon: _passwordInFocus
? IconButton(
icon: Icon(
_passwordVisible
? Icons.visibility
: Icons.visibility_off,
color: Colors.white.withOpacity(0.5),
size: 20,
),
onPressed: () {
setState(() {
_passwordVisible = !_passwordVisible;
});
},
)
: null,
),
2021-03-30 11:36:36 +00:00
style: TextStyle(
fontSize: 14,
),
2021-03-30 11:36:36 +00:00
controller: _passwordController,
autofocus: false,
autocorrect: false,
2021-05-12 16:20:30 +00:00
obscureText: !_passwordVisible,
2021-03-30 11:36:36 +00:00
keyboardType: TextInputType.visiblePassword,
2021-05-12 16:20:30 +00:00
focusNode: _passwordFocusNode,
2021-03-30 11:36:36 +00:00
onChanged: (_) {
setState(() {});
},
),
),
2021-03-30 11:36:36 +00:00
Padding(padding: EdgeInsets.all(12)),
Container(
2021-03-30 12:13:13 +00:00
padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
width: double.infinity,
height: 64,
child: button(
2021-08-15 19:35:16 +00:00
AppLocalizations.of(context).log_in,
2021-03-30 12:13:13 +00:00
fontSize: 18,
onPressed: _passwordController.text.isNotEmpty
? () async {
final dialog =
createProgressDialog(context, "please wait...");
await dialog.show();
try {
await Configuration.instance.decryptAndSaveSecrets(
2021-03-30 12:13:13 +00:00
_passwordController.text,
Configuration.instance.getKeyAttributes());
} catch (e) {
Logger("PRP").warning(e);
2021-03-30 11:36:36 +00:00
await dialog.hide();
2021-03-30 12:13:13 +00:00
showErrorDialog(
context, "incorrect password", "please try again");
return;
2021-03-30 11:36:36 +00:00
}
2021-03-30 12:13:13 +00:00
await dialog.hide();
Bus.instance.fire(SubscriptionPurchasedEvent());
Navigator.of(context).popUntil((route) => route.isFirst);
2021-03-30 12:13:13 +00:00
}
: null,
),
),
Padding(padding: EdgeInsets.all(30)),
2021-03-30 12:13:13 +00:00
GestureDetector(
behavior: HitTestBehavior.opaque,
2021-03-30 12:13:13 +00:00
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return RecoveryPage();
},
),
);
},
child: Container(
padding: EdgeInsets.all(10),
2021-03-30 12:13:13 +00:00
child: Center(
child: Text(
"forgot password?",
style: TextStyle(
decoration: TextDecoration.underline,
fontSize: 12,
),
),
),
),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
2021-08-09 17:57:00 +00:00
onTap: () async {
final dialog = createProgressDialog(context, "please wait...");
2021-08-09 18:05:34 +00:00
await dialog.show();
2021-08-09 17:57:00 +00:00
await Configuration.instance.logout();
2021-08-09 18:05:34 +00:00
await dialog.hide();
Navigator.of(context).popUntil((route) => route.isFirst);
},
child: Container(
padding: EdgeInsets.all(16),
child: Center(
child: Text(
"change email?",
style: TextStyle(
decoration: TextDecoration.underline,
fontSize: 12,
),
),
),
),
),
2021-03-30 11:36:36 +00:00
],
);
}
}