2022-11-01 06:13:06 +00:00
|
|
|
import 'package:email_validator/email_validator.dart';
|
|
|
|
import 'package:ente_auth/core/configuration.dart';
|
2023-07-24 06:13:17 +00:00
|
|
|
import 'package:ente_auth/core/errors.dart';
|
2023-04-08 10:04:32 +00:00
|
|
|
import "package:ente_auth/l10n/l10n.dart";
|
2023-08-02 07:46:48 +00:00
|
|
|
import 'package:ente_auth/models/api/user/srp.dart';
|
2022-11-01 06:13:06 +00:00
|
|
|
import 'package:ente_auth/services/user_service.dart';
|
2023-07-24 06:13:17 +00:00
|
|
|
import 'package:ente_auth/ui/account/login_pwd_verification_page.dart';
|
2022-11-01 06:13:06 +00:00
|
|
|
import 'package:ente_auth/ui/common/dynamic_fab.dart';
|
|
|
|
import 'package:ente_auth/ui/common/web_page.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-07-24 06:13:17 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2023-04-08 10:04:32 +00:00
|
|
|
import "package:styled_text/styled_text.dart";
|
2022-11-01 06:13:06 +00:00
|
|
|
|
|
|
|
class LoginPage extends StatefulWidget {
|
2023-04-08 10:04:32 +00:00
|
|
|
const LoginPage({Key? key}) : super(key: key);
|
2022-11-01 06:13:06 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<LoginPage> createState() => _LoginPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LoginPageState extends State<LoginPage> {
|
|
|
|
final _config = Configuration.instance;
|
|
|
|
bool _emailIsValid = false;
|
2023-04-08 10:04:32 +00:00
|
|
|
String? _email;
|
|
|
|
Color? _emailInputFieldColor;
|
2023-07-24 06:13:17 +00:00
|
|
|
final Logger _logger = Logger('_LoginPageState');
|
2022-11-01 06:13:06 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_email = _config.getEmail();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100;
|
|
|
|
|
2023-04-08 10:04:32 +00:00
|
|
|
FloatingActionButtonLocation? fabLocation() {
|
2022-11-01 06:13:06 +00:00
|
|
|
if (isKeypadOpen) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return FloatingActionButtonLocation.centerFloat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
resizeToAvoidBottomInset: isKeypadOpen,
|
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
color: Theme.of(context).iconTheme.color,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: _getBody(),
|
|
|
|
floatingActionButton: DynamicFAB(
|
|
|
|
isKeypadOpen: isKeypadOpen,
|
|
|
|
isFormValid: _emailIsValid,
|
2023-04-08 10:04:32 +00:00
|
|
|
buttonText: context.l10n.logInLabel,
|
2023-07-24 06:13:17 +00:00
|
|
|
onPressedFunction: () async {
|
2023-04-08 10:04:32 +00:00
|
|
|
UserService.instance.setEmail(_email!);
|
2023-08-02 07:46:48 +00:00
|
|
|
SrpAttributes? attr;
|
|
|
|
bool isEmailVerificationEnabled = true;
|
2023-07-24 06:13:17 +00:00
|
|
|
try {
|
2023-08-02 07:46:48 +00:00
|
|
|
attr = await UserService.instance.getSrpAttributes(_email!);
|
2023-08-02 12:09:00 +00:00
|
|
|
isEmailVerificationEnabled = attr.isEmailMFAEnabled;
|
2023-08-02 07:46:48 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (e is! SrpSetupNotCompleteError) {
|
|
|
|
_logger.severe('Error getting SRP attributes', e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (attr != null && !isEmailVerificationEnabled) {
|
2023-07-24 06:13:17 +00:00
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return LoginPasswordVerificationPage(
|
2023-08-02 07:46:48 +00:00
|
|
|
srpAttributes: attr!,
|
2023-07-24 06:13:17 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2023-08-02 07:46:48 +00:00
|
|
|
} else {
|
2023-07-24 06:13:17 +00:00
|
|
|
await UserService.instance
|
|
|
|
.sendOtt(context, _email!, isCreateAccountScreen: false);
|
|
|
|
}
|
2022-11-01 06:13:06 +00:00
|
|
|
FocusScope.of(context).unfocus();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
floatingActionButtonLocation: fabLocation(),
|
|
|
|
floatingActionButtonAnimator: NoScalingAnimation(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getBody() {
|
2023-04-08 10:04:32 +00:00
|
|
|
final l10n = context.l10n;
|
2022-11-01 06:13:06 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: AutofillGroup(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
|
|
|
|
child: Text(
|
2023-04-10 04:17:45 +00:00
|
|
|
l10n.welcomeBack,
|
2023-08-22 04:47:15 +00:00
|
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
2022-11-01 06:13:06 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
|
|
|
|
child: TextFormField(
|
|
|
|
autofillHints: const [AutofillHints.email],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
fillColor: _emailInputFieldColor,
|
|
|
|
filled: true,
|
2023-04-08 10:04:32 +00:00
|
|
|
hintText: l10n.email,
|
2022-11-01 06:13:06 +00:00
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 15,
|
|
|
|
vertical: 15,
|
|
|
|
),
|
|
|
|
border: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide.none,
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
),
|
|
|
|
suffixIcon: _emailIsValid
|
|
|
|
? Icon(
|
|
|
|
Icons.check,
|
|
|
|
size: 20,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.inputDecorationTheme
|
2023-04-08 10:04:32 +00:00
|
|
|
.focusedBorder!
|
2022-11-01 06:13:06 +00:00
|
|
|
.borderSide
|
|
|
|
.color,
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_email = value.trim();
|
2023-04-08 10:04:32 +00:00
|
|
|
_emailIsValid = EmailValidator.validate(_email!);
|
2022-11-01 06:13:06 +00:00
|
|
|
if (_emailIsValid) {
|
|
|
|
_emailInputFieldColor =
|
|
|
|
const Color.fromARGB(51, 157, 45, 194);
|
|
|
|
} else {
|
|
|
|
_emailInputFieldColor = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
autocorrect: false,
|
|
|
|
keyboardType: TextInputType.emailAddress,
|
|
|
|
//initialValue: _email,
|
|
|
|
autofocus: true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 18),
|
|
|
|
child: Divider(
|
|
|
|
thickness: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
flex: 5,
|
2023-04-08 10:04:32 +00:00
|
|
|
child: StyledText(
|
|
|
|
text: context.l10n.loginTerms,
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
2023-08-22 04:47:15 +00:00
|
|
|
.titleMedium!
|
2023-04-08 10:04:32 +00:00
|
|
|
.copyWith(fontSize: 12),
|
|
|
|
tags: {
|
|
|
|
'u-terms': StyledTextActionTag(
|
2023-08-22 04:47:15 +00:00
|
|
|
(String? text, Map<String?, String?> attrs) => Navigator.of(context).push(
|
2023-04-08 10:04:32 +00:00
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return WebPage(
|
|
|
|
context.l10n.termsOfServicesTitle,
|
|
|
|
"https://ente.io/terms",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-08-22 04:47:15 +00:00
|
|
|
),
|
2023-04-08 10:04:32 +00:00
|
|
|
style: const TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
2022-11-01 06:13:06 +00:00
|
|
|
),
|
2023-04-08 10:04:32 +00:00
|
|
|
),
|
|
|
|
'u-policy': StyledTextActionTag(
|
2023-08-22 04:47:15 +00:00
|
|
|
(String? text, Map<String?, String?> attrs) => Navigator.of(context).push(
|
2023-04-08 10:04:32 +00:00
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return WebPage(
|
|
|
|
context.l10n.privacyPolicyTitle,
|
|
|
|
"https://ente.io/privacy",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-08-22 04:47:15 +00:00
|
|
|
),
|
2023-04-08 10:04:32 +00:00
|
|
|
style: const TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
2022-11-01 06:13:06 +00:00
|
|
|
),
|
2023-04-08 10:04:32 +00:00
|
|
|
)
|
|
|
|
},
|
2022-11-01 06:13:06 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 2,
|
|
|
|
child: Container(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Padding(padding: EdgeInsets.all(8)),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|