Simplify EmailEntryPage

This commit is contained in:
Vishnu Mohandas 2020-08-26 04:32:43 +05:30
parent 12a1ccd8cd
commit fd074e96ee
4 changed files with 26 additions and 27 deletions

View file

@ -11,6 +11,7 @@ import 'package:photos/folder_service.dart';
import 'package:photos/memories_service.dart';
import 'package:photos/photo_sync_manager.dart';
import 'package:photos/ui/home_widget.dart';
import 'package:photos/user_authenticator.dart';
import 'package:sentry/sentry.dart';
import 'package:super_logging/super_logging.dart';
import 'package:logging/logging.dart';
@ -96,6 +97,9 @@ Future<void> initDeepLinks() async {
// Attach a listener to the stream
getLinksStream().listen((String link) {
_logger.info("Link received: " + link);
final ott = Uri.parse(link).queryParameters["ott"];
_logger.info("Ott: " + ott);
// UserAuthenticator.instance.getCredentials(context, ott);
}, onError: (err) {
_logger.severe(err);
});

View file

@ -2,23 +2,23 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/svg.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/user_authenticator.dart';
class EmailEntryPage extends StatefulWidget {
final String email;
EmailEntryPage({this.email, Key key}) : super(key: key);
EmailEntryPage({Key key}) : super(key: key);
@override
_EmailEntryPageState createState() => _EmailEntryPageState();
}
class _EmailEntryPageState extends State<EmailEntryPage> {
String _email;
TextEditingController _emailController;
@override
void initState() {
_email = widget.email;
_emailController =
TextEditingController(text: Configuration.instance.getEmail());
super.initState();
}
@ -48,22 +48,19 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
hintText: 'email@domain.com',
contentPadding: EdgeInsets.all(20),
),
initialValue: widget.email == null ? "" : widget.email,
controller: _emailController,
autofocus: true,
autocorrect: false,
keyboardType: TextInputType.emailAddress,
onChanged: (email) {
setState(() {
_email = email;
});
},
),
Padding(padding: EdgeInsets.all(8)),
SizedBox(
width: double.infinity,
child: RaisedButton(
onPressed: () {
UserAuthenticator.instance.getOtt(context, _email);
final email = _emailController.text;
Configuration.instance.setEmail(email);
UserAuthenticator.instance.getOtt(context, email);
},
padding: const EdgeInsets.fromLTRB(8, 12, 8, 12),
child: Text("Sign In"),

View file

@ -3,12 +3,12 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/ui/email_entry_page.dart';
import 'package:photos/user_authenticator.dart';
class OTTVerificationPage extends StatefulWidget {
final String email;
OTTVerificationPage(this.email, {Key key}) : super(key: key);
OTTVerificationPage({Key key}) : super(key: key);
@override
_OTTVerificationPageState createState() => _OTTVerificationPageState();
@ -48,7 +48,7 @@ class _OTTVerificationPageState extends State<OTTVerificationPage> {
children: <TextSpan>[
TextSpan(text: "We've sent a mail to "),
TextSpan(
text: widget.email,
text: Configuration.instance.getEmail(),
style: TextStyle(
color: Theme.of(context).accentColor,
)),
@ -85,8 +85,8 @@ class _OTTVerificationPageState extends State<OTTVerificationPage> {
_verificationCodeController.text.isEmpty
? null
: () {
UserAuthenticator.instance.getCredentials(context,
widget.email, _verificationCodeController.text);
UserAuthenticator.instance.getCredentials(
context, _verificationCodeController.text);
},
padding: const EdgeInsets.fromLTRB(8, 12, 8, 12),
child: Text(
@ -103,7 +103,7 @@ class _OTTVerificationPageState extends State<OTTVerificationPage> {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return EmailEntryPage(email: widget.email);
return EmailEntryPage();
},
),
);

View file

@ -36,7 +36,7 @@ class UserAuthenticator {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return OTTVerificationPage(email);
return OTTVerificationPage();
},
),
);
@ -46,14 +46,13 @@ class UserAuthenticator {
});
}
Future<void> getCredentials(
BuildContext context, String email, String ott) async {
Future<void> getCredentials(BuildContext context, String ott) async {
final dialog = createProgressDialog(context, "Please wait...");
await dialog.show();
await Dio().get(
Configuration.instance.getHttpEndpoint() + "/users/credentials",
queryParameters: {
"email": email,
"email": Configuration.instance.getEmail(),
"ott": ott,
},
).catchError((e) async {
@ -63,7 +62,7 @@ class UserAuthenticator {
}).then((response) async {
await dialog.hide();
if (response.statusCode == 200) {
_saveConfiguration(email, response);
_saveConfiguration(response);
Navigator.of(context).pop();
} else {
showErrorDialog(
@ -80,7 +79,7 @@ class UserAuthenticator {
"password": password,
}).then((response) {
if (response.statusCode == 200 && response.data != null) {
_saveConfiguration(username, response);
_saveConfiguration(response);
Bus.instance.fire(UserAuthenticatedEvent());
return true;
} else {
@ -99,7 +98,7 @@ class UserAuthenticator {
"password": password,
}).then((response) {
if (response.statusCode == 200 && response.data != null) {
_saveConfiguration(username, response);
_saveConfiguration(response);
return true;
} else {
if (response.data != null && response.data["message"] != null) {
@ -126,8 +125,7 @@ class UserAuthenticator {
);
}
void _saveConfiguration(String email, Response response) {
Configuration.instance.setEmail(email);
void _saveConfiguration(Response response) {
Configuration.instance.setUserID(response.data["id"]);
Configuration.instance.setToken(response.data["token"]);
final String encryptedKey = response.data["encryptedKey"];