From d263bafe567dfcb793d7dad99088ac6c008869b1 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:55:51 +0530 Subject: [PATCH] DebugMode: Add support to pick creds from env Signed-off-by: Neeraj Gupta <254676+ua741@users.noreply.github.com> --- lib/ui/account/login_page.dart | 66 ++++++++------ .../account/login_pwd_verification_page.dart | 87 +++++++++++-------- 2 files changed, 89 insertions(+), 64 deletions(-) diff --git a/lib/ui/account/login_page.dart b/lib/ui/account/login_page.dart index ca80a6c15..c52f461d1 100644 --- a/lib/ui/account/login_page.dart +++ b/lib/ui/account/login_page.dart @@ -1,4 +1,5 @@ import 'package:email_validator/email_validator.dart'; +import "package:flutter/foundation.dart"; import 'package:flutter/material.dart'; import "package:logging/logging.dart"; import 'package:photos/core/configuration.dart'; @@ -28,7 +29,11 @@ class _LoginPageState extends State { @override void initState() { - _email = _config.getEmail(); + if ((_config.getEmail() ?? '').isNotEmpty) { + updateEmail(_config.getEmail()!); + } else if (kDebugMode) { + updateEmail(const String.fromEnvironment("email")); + } super.initState(); } @@ -143,19 +148,12 @@ class _LoginPageState extends State { ), onChanged: (value) { setState(() { - _email = value.trim(); - _emailIsValid = EmailValidator.validate(_email!); - if (_emailIsValid) { - _emailInputFieldColor = - const Color.fromRGBO(45, 194, 98, 0.2); - } else { - _emailInputFieldColor = null; - } + updateEmail(value); }); }, autocorrect: false, keyboardType: TextInputType.emailAddress, - //initialValue: _email, + initialValue: _email, autofocus: true, ), ), @@ -179,31 +177,33 @@ class _LoginPageState extends State { .copyWith(fontSize: 12), tags: { 'u-terms': StyledTextActionTag( - (String? text, Map attrs) => Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) { - return WebPage( - S.of(context).termsOfServicesTitle, - "https://ente.io/terms", - ); - }, - ), + (String? text, Map attrs) => + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) { + return WebPage( + S.of(context).termsOfServicesTitle, + "https://ente.io/terms", + ); + }, ), + ), style: const TextStyle( decoration: TextDecoration.underline, ), ), 'u-policy': StyledTextActionTag( - (String? text, Map attrs) => Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) { - return WebPage( - S.of(context).privacyPolicyTitle, - "https://ente.io/privacy", - ); - }, - ), + (String? text, Map attrs) => + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) { + return WebPage( + S.of(context).privacyPolicyTitle, + "https://ente.io/privacy", + ); + }, ), + ), style: const TextStyle( decoration: TextDecoration.underline, ), @@ -226,4 +226,14 @@ class _LoginPageState extends State { ], ); } + + void updateEmail(String value) { + _email = value.trim(); + _emailIsValid = EmailValidator.validate(_email!); + if (_emailIsValid) { + _emailInputFieldColor = const Color.fromRGBO(45, 194, 98, 0.2); + } else { + _emailInputFieldColor = null; + } + } } diff --git a/lib/ui/account/login_pwd_verification_page.dart b/lib/ui/account/login_pwd_verification_page.dart index 20c04ceff..f29827a31 100644 --- a/lib/ui/account/login_pwd_verification_page.dart +++ b/lib/ui/account/login_pwd_verification_page.dart @@ -1,4 +1,4 @@ - +import "package:flutter/foundation.dart"; import 'package:flutter/material.dart'; import 'package:photos/core/configuration.dart'; import "package:photos/generated/l10n.dart"; @@ -15,14 +15,17 @@ import "package:photos/utils/dialog_util.dart"; // volatile password. class LoginPasswordVerificationPage extends StatefulWidget { final SrpAttributes srpAttributes; - const LoginPasswordVerificationPage({Key? key, required this.srpAttributes}) : super(key: key); + + const LoginPasswordVerificationPage({Key? key, required this.srpAttributes}) + : super(key: key); @override - State createState() => _LoginPasswordVerificationPageState(); + State createState() => + _LoginPasswordVerificationPageState(); } -class _LoginPasswordVerificationPageState extends -State { +class _LoginPasswordVerificationPageState + extends State { final _passwordController = TextEditingController(); final FocusNode _passwordFocusNode = FocusNode(); String? email; @@ -33,6 +36,9 @@ State { void initState() { super.initState(); email = Configuration.instance.getEmail(); + if (kDebugMode) { + _passwordController.text = const String.fromEnvironment("password"); + } _passwordFocusNode.addListener(() { setState(() { _passwordInFocus = _passwordFocusNode.hasFocus; @@ -79,9 +85,11 @@ State { buttonText: S.of(context).logInLabel, onPressedFunction: () async { FocusScope.of(context).unfocus(); - await UserService.instance.verifyEmailViaPassword(context, widget - .srpAttributes, - _passwordController.text,); + await UserService.instance.verifyEmailViaPassword( + context, + widget.srpAttributes, + _passwordController.text, + ); }, ), floatingActionButtonLocation: fabLocation(), @@ -97,17 +105,22 @@ State { child: ListView( children: [ Padding( - padding: - const EdgeInsets.only(top: 30, left: 20, right: 20), + padding: const EdgeInsets.only(top: 30, left: 20, right: 20), child: Text( S.of(context).enterPassword, style: Theme.of(context).textTheme.headlineMedium, ), ), Padding( - padding: const EdgeInsets.only(bottom: 30, left: 22, right: - 20,), - child: Text(email ?? '', style: getEnteTextTheme(context).smallMuted,), + padding: const EdgeInsets.only( + bottom: 30, + left: 22, + right: 20, + ), + child: Text( + email ?? '', + style: getEnteTextTheme(context).smallMuted, + ), ), Visibility( // hidden textForm for suggesting auto-fill service for saving @@ -138,19 +151,19 @@ State { ), suffixIcon: _passwordInFocus ? IconButton( - icon: Icon( - _passwordVisible - ? Icons.visibility - : Icons.visibility_off, - color: Theme.of(context).iconTheme.color, - size: 20, - ), - onPressed: () { - setState(() { - _passwordVisible = !_passwordVisible; - }); - }, - ) + icon: Icon( + _passwordVisible + ? Icons.visibility + : Icons.visibility_off, + color: Theme.of(context).iconTheme.color, + size: 20, + ), + onPressed: () { + setState(() { + _passwordVisible = !_passwordVisible; + }); + }, + ) : null, ), style: const TextStyle( @@ -181,9 +194,11 @@ State { GestureDetector( behavior: HitTestBehavior.opaque, onTap: () async { - await UserService.instance - .sendOtt(context, email!, - isResetPasswordScreen: true,); + await UserService.instance.sendOtt( + context, + email!, + isResetPasswordScreen: true, + ); }, child: Center( child: Text( @@ -192,9 +207,9 @@ State { .textTheme .titleMedium! .copyWith( - fontSize: 14, - decoration: TextDecoration.underline, - ), + fontSize: 14, + decoration: TextDecoration.underline, + ), ), ), ), @@ -218,9 +233,9 @@ State { .textTheme .titleMedium! .copyWith( - fontSize: 14, - decoration: TextDecoration.underline, - ), + fontSize: 14, + decoration: TextDecoration.underline, + ), ), ), ), @@ -234,4 +249,4 @@ State { ], ); } -} \ No newline at end of file +}