2020-08-26 02:34:13 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
2021-01-26 11:48:17 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2020-08-26 02:34:13 +00:00
|
|
|
import 'package:photos/core/configuration.dart';
|
2021-02-05 13:56:51 +00:00
|
|
|
import 'package:photos/core/event_bus.dart';
|
|
|
|
import 'package:photos/events/subscription_purchased_event.dart';
|
2021-01-06 16:09:42 +00:00
|
|
|
import 'package:photos/services/billing_service.dart';
|
2020-10-24 21:07:12 +00:00
|
|
|
import 'package:photos/ui/common_elements.dart';
|
2021-01-06 16:09:42 +00:00
|
|
|
import 'package:photos/ui/subscription_page.dart';
|
2020-08-26 02:34:13 +00:00
|
|
|
import 'package:photos/utils/dialog_util.dart';
|
|
|
|
|
2021-01-05 14:27:02 +00:00
|
|
|
class PasswordReentryPage extends StatefulWidget {
|
|
|
|
PasswordReentryPage({Key key}) : super(key: key);
|
2020-08-26 02:34:13 +00:00
|
|
|
|
|
|
|
@override
|
2021-01-05 14:27:02 +00:00
|
|
|
_PasswordReentryPageState createState() => _PasswordReentryPageState();
|
2020-08-26 02:34:13 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 14:27:02 +00:00
|
|
|
class _PasswordReentryPageState extends State<PasswordReentryPage> {
|
2021-01-05 15:26:10 +00:00
|
|
|
final _passwordController = TextEditingController();
|
2020-08-26 02:34:13 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: Icon(Icons.lock),
|
|
|
|
title: Text(
|
2021-01-05 15:26:10 +00:00
|
|
|
"encryption password",
|
2020-08-26 02:34:13 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
body: _getBody(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getBody() {
|
|
|
|
return SingleChildScrollView(
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.fromLTRB(16, 40, 16, 16),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2020-09-27 18:53:47 +00:00
|
|
|
Image.asset(
|
|
|
|
"assets/vault.png",
|
2020-08-26 02:34:13 +00:00
|
|
|
width: 196,
|
|
|
|
height: 196,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.all(20)),
|
2021-01-05 15:26:10 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
|
|
|
|
child: TextFormField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "enter your password",
|
|
|
|
contentPadding: EdgeInsets.all(20),
|
|
|
|
),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
controller: _passwordController,
|
|
|
|
autofocus: false,
|
|
|
|
autocorrect: false,
|
|
|
|
obscureText: true,
|
|
|
|
keyboardType: TextInputType.visiblePassword,
|
|
|
|
onChanged: (_) {
|
|
|
|
setState(() {});
|
|
|
|
},
|
2020-08-26 02:34:13 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.all(12)),
|
2020-10-24 21:07:12 +00:00
|
|
|
Container(
|
2020-12-12 00:31:06 +00:00
|
|
|
padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
|
2020-08-26 02:34:13 +00:00
|
|
|
width: double.infinity,
|
2020-12-12 00:31:06 +00:00
|
|
|
height: 64,
|
2020-10-24 21:07:12 +00:00
|
|
|
child: button(
|
2021-01-05 15:26:10 +00:00
|
|
|
"sign in",
|
|
|
|
fontSize: 18,
|
|
|
|
onPressed: _passwordController.text.isNotEmpty
|
2020-08-26 02:34:13 +00:00
|
|
|
? () async {
|
|
|
|
final dialog =
|
2021-01-05 15:26:10 +00:00
|
|
|
createProgressDialog(context, "please wait...");
|
2020-08-26 02:34:13 +00:00
|
|
|
await dialog.show();
|
2020-09-05 08:53:23 +00:00
|
|
|
try {
|
|
|
|
await Configuration.instance.decryptAndSaveKey(
|
2021-01-05 15:26:10 +00:00
|
|
|
_passwordController.text,
|
2020-09-05 08:53:23 +00:00
|
|
|
Configuration.instance.getKeyAttributes());
|
|
|
|
} catch (e) {
|
2021-01-26 11:48:17 +00:00
|
|
|
Logger("PRP").warning(e);
|
2020-09-05 08:53:23 +00:00
|
|
|
await dialog.hide();
|
2021-01-05 15:26:10 +00:00
|
|
|
showErrorDialog(context, "incorrect password",
|
|
|
|
"please try again");
|
2020-09-05 08:53:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-26 02:34:13 +00:00
|
|
|
await dialog.hide();
|
2021-01-26 11:48:17 +00:00
|
|
|
if (!BillingService.instance
|
|
|
|
.hasActiveSubscription()) {
|
2021-02-05 11:47:08 +00:00
|
|
|
Navigator.of(context).pushReplacement(
|
2021-01-06 16:09:42 +00:00
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) {
|
2021-02-25 15:14:31 +00:00
|
|
|
return SubscriptionPage(isOnboarding: true);
|
2021-01-06 16:09:42 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2021-01-26 11:48:17 +00:00
|
|
|
} else {
|
2021-02-05 13:56:51 +00:00
|
|
|
Bus.instance.fire(SubscriptionPurchasedEvent());
|
2021-01-26 11:48:17 +00:00
|
|
|
Navigator.of(context)
|
|
|
|
.popUntil((route) => route.isFirst);
|
2021-01-06 16:09:42 +00:00
|
|
|
}
|
2020-08-26 02:34:13 +00:00
|
|
|
}
|
|
|
|
: null,
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|