Create account

This commit is contained in:
Hillel Coren 2019-08-26 10:13:25 +03:00
parent 4a4dc21a47
commit 278d3b0cf6
4 changed files with 134 additions and 97 deletions

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
// This version must be updated in tandem with the pubspec version. // This version must be updated in tandem with the pubspec version.
const String kAppVersion = '0.1.47'; const String kAppVersion = '0.1.47';
const String kSiteUrl = 'https://invoiceninja.com';
const String kAppUrl = 'https://app.invoiceninja.com'; const String kAppUrl = 'https://app.invoiceninja.com';
const String kAppleStoreUrl = const String kAppleStoreUrl =

View File

@ -17,9 +17,7 @@ class ProgressButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return isLoading
padding: padding ?? EdgeInsets.only(left: 16.0, right: 16.0, top: 2.0),
child: isLoading
? Center( ? Center(
child: SizedBox( child: SizedBox(
height: 48, height: 48,
@ -31,7 +29,6 @@ class ProgressButton extends StatelessWidget {
width: double.infinity, width: double.infinity,
label: label, label: label,
onPressed: () => this.onPressed(), onPressed: () => this.onPressed(),
),
); );
} }
} }

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_state.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_state.dart';
import 'package:invoiceninja_flutter/ui/app/buttons/elevated_button.dart'; import 'package:invoiceninja_flutter/ui/app/buttons/elevated_button.dart';
import 'package:invoiceninja_flutter/ui/app/progress_button.dart'; import 'package:invoiceninja_flutter/ui/app/progress_button.dart';
@ -7,6 +8,7 @@ import 'package:invoiceninja_flutter/utils/formatting.dart';
import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/ui/app/form_card.dart'; import 'package:invoiceninja_flutter/ui/app/form_card.dart';
import 'package:invoiceninja_flutter/utils/platforms.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart';
import 'package:url_launcher/url_launcher.dart';
class LoginView extends StatefulWidget { class LoginView extends StatefulWidget {
const LoginView({ const LoginView({
@ -33,6 +35,7 @@ class _LoginState extends State<LoginView> {
final FocusNode _focusNode1 = new FocusNode(); final FocusNode _focusNode1 = new FocusNode();
bool _createAccount = false;
bool _isSelfHosted = false; bool _isSelfHosted = false;
bool _autoValidate = false; bool _autoValidate = false;
@ -166,8 +169,8 @@ class _LoginState extends State<LoginView> {
focusNode: _focusNode1, focusNode: _focusNode1,
onFieldSubmitted: (value) => _submitForm(), onFieldSubmitted: (value) => _submitForm(),
), ),
_isSelfHosted if (_isSelfHosted)
? TextFormField( TextFormField(
controller: _urlController, controller: _urlController,
key: ValueKey(localization.url), key: ValueKey(localization.url),
autocorrect: false, autocorrect: false,
@ -179,23 +182,21 @@ class _LoginState extends State<LoginView> {
? localization.pleaseEnterYourUrl ? localization.pleaseEnterYourUrl
: null, : null,
keyboardType: TextInputType.url, keyboardType: TextInputType.url,
) ),
: Container(), if (_isSelfHosted)
_isSelfHosted TextFormField(
? TextFormField(
controller: _secretController, controller: _secretController,
key: ValueKey(localization.secret), key: ValueKey(localization.secret),
autocorrect: false, autocorrect: false,
decoration: InputDecoration( decoration: InputDecoration(
labelText: localization.secret), labelText: localization.secret),
obscureText: true, obscureText: true,
) ),
: Container(),
], ],
), ),
viewModel.authState.error == null || error.contains(OTP_ERROR) if (viewModel.authState.error != null &&
? Container() !error.contains(OTP_ERROR))
: Container( Container(
padding: EdgeInsets.only(top: 26.0), padding: EdgeInsets.only(top: 26.0),
child: Center( child: Center(
child: Text( child: Text(
@ -207,18 +208,44 @@ class _LoginState extends State<LoginView> {
), ),
), ),
), ),
SizedBox(height: 24.0), Padding(
ProgressButton( padding: EdgeInsets.only(top: 35, bottom: 10),
padding: EdgeInsets.only(top: 12.0, bottom: 12.0), child: Row(
children: <Widget>[
Expanded(
child: ProgressButton(
isLoading: viewModel.isLoading, isLoading: viewModel.isLoading,
label: localization.login.toUpperCase(), label: localization.emailLogin.toUpperCase(),
onPressed: () => _submitForm(), onPressed: () => _submitForm(),
), ),
isOneTimePassword ),
? Container() SizedBox(width: 20),
: Row( Expanded(
child: ElevatedButton(
label: localization.googleLogin.toUpperCase(),
onPressed: () => viewModel.onGoogleLoginPressed(
context,
_urlController.text,
_secretController.text),
),
),
],
),
),
if (!isOneTimePassword)
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[ children: <Widget>[
_createAccount
? FlatButton(
onPressed: () =>
setState(() => _createAccount = false),
child: Text(localization.login))
: FlatButton(
key: ValueKey(localization.selfhostLogin),
onPressed: () =>
setState(() => _createAccount = true),
child: Text(localization.createAccount)),
_isSelfHosted _isSelfHosted
? FlatButton( ? FlatButton(
onPressed: () => onPressed: () =>
@ -230,15 +257,18 @@ class _LoginState extends State<LoginView> {
setState(() => _isSelfHosted = true), setState(() => _isSelfHosted = true),
child: Text(localization.selfhostLogin)), child: Text(localization.selfhostLogin)),
FlatButton( FlatButton(
onPressed: () => viewModel.onGoogleLoginPressed( child: Text(localization.viewWebsite),
context, onPressed: () async {
_urlController.text, if (await canLaunch(kSiteUrl)) {
_secretController.text), await launch(kSiteUrl,
child: Text(localization.googleLogin)), forceSafariVC: false, forceWebView: false);
}
},
),
], ],
), ),
isOneTimePassword && !viewModel.isLoading if (isOneTimePassword && !viewModel.isLoading)
? Padding( Padding(
padding: EdgeInsets.only(top: 12.0, bottom: 12.0), padding: EdgeInsets.only(top: 12.0, bottom: 12.0),
child: ElevatedButton( child: ElevatedButton(
label: localization.cancel.toUpperCase(), label: localization.cancel.toUpperCase(),
@ -250,8 +280,7 @@ class _LoginState extends State<LoginView> {
viewModel.onCancel2FAPressed(); viewModel.onCancel2FAPressed();
}, },
), ),
) ),
: Container(),
], ],
), ),
), ),

View File

@ -14,6 +14,9 @@ abstract class LocaleCodeAware {
mixin LocalizationsProvider on LocaleCodeAware { mixin LocalizationsProvider on LocaleCodeAware {
static final Map<String, Map<String, String>> _localizedValues = { static final Map<String, Map<String, String>> _localizedValues = {
'en': { 'en': {
'view_website': 'View Website',
'create_account': 'Create Account',
'email_login': 'Email Login',
'create_new': 'Create New', 'create_new': 'Create New',
'no_record_selected': 'No record selected', 'no_record_selected': 'No record selected',
'error_unsaved_changes': 'Please save or cancel your changes', 'error_unsaved_changes': 'Please save or cancel your changes',
@ -13803,6 +13806,13 @@ mixin LocalizationsProvider on LocaleCodeAware {
String get createNew => _localizedValues[localeCode]['create_new']; String get createNew => _localizedValues[localeCode]['create_new'];
String get emailLogin => _localizedValues[localeCode]['email_login'];
String get createAccount => _localizedValues[localeCode]['create_account'];
String get viewWebsite => _localizedValues[localeCode]['view_website'];
String lookup(String key) { String lookup(String key) {
final lookupKey = toSnakeCase(key); final lookupKey = toSnakeCase(key);
return _localizedValues[localeCode][lookupKey] ?? return _localizedValues[localeCode][lookupKey] ??