Support token login
This commit is contained in:
parent
eaa6ffe85d
commit
e3a349c811
|
|
@ -37,6 +37,11 @@ class OAuthLoginRequest implements StartLoading {
|
||||||
final String oneTimePassword;
|
final String oneTimePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TokenLogin {
|
||||||
|
TokenLogin(this.token);
|
||||||
|
final String token;
|
||||||
|
}
|
||||||
|
|
||||||
class UserLoadUrl {
|
class UserLoadUrl {
|
||||||
UserLoadUrl({this.url});
|
UserLoadUrl({this.url});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
|
||||||
import 'package:invoiceninja_flutter/constants.dart';
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
|
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/buttons/app_text_button.dart';
|
import 'package:invoiceninja_flutter/ui/app/buttons/app_text_button.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/app/buttons/elevated_button.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/dialogs/alert_dialog.dart';
|
import 'package:invoiceninja_flutter/ui/app/dialogs/alert_dialog.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/forms/app_toggle_buttons.dart';
|
import 'package:invoiceninja_flutter/ui/app/forms/app_toggle_buttons.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/forms/decorated_form_field.dart';
|
import 'package:invoiceninja_flutter/ui/app/forms/decorated_form_field.dart';
|
||||||
|
|
@ -46,6 +47,7 @@ class _LoginState extends State<LoginView> {
|
||||||
final _urlController = TextEditingController();
|
final _urlController = TextEditingController();
|
||||||
final _secretController = TextEditingController();
|
final _secretController = TextEditingController();
|
||||||
final _oneTimePasswordController = TextEditingController();
|
final _oneTimePasswordController = TextEditingController();
|
||||||
|
final _tokenController = TextEditingController();
|
||||||
|
|
||||||
final _buttonController = RoundedLoadingButtonController();
|
final _buttonController = RoundedLoadingButtonController();
|
||||||
|
|
||||||
|
|
@ -53,6 +55,7 @@ class _LoginState extends State<LoginView> {
|
||||||
|
|
||||||
String _loginError = '';
|
String _loginError = '';
|
||||||
|
|
||||||
|
bool _tokenLogin = false;
|
||||||
bool _emailLogin = false;
|
bool _emailLogin = false;
|
||||||
bool _isSelfHosted = false;
|
bool _isSelfHosted = false;
|
||||||
bool _createAccount = true;
|
bool _createAccount = true;
|
||||||
|
|
@ -110,6 +113,8 @@ class _LoginState extends State<LoginView> {
|
||||||
_passwordController.dispose();
|
_passwordController.dispose();
|
||||||
_urlController.dispose();
|
_urlController.dispose();
|
||||||
_secretController.dispose();
|
_secretController.dispose();
|
||||||
|
_oneTimePasswordController.dispose();
|
||||||
|
_tokenController.dispose();
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
@ -294,9 +299,34 @@ class _LoginState extends State<LoginView> {
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launch(kSiteUrl, forceSafariVC: false, forceWebView: false);
|
launch(kSiteUrl, forceSafariVC: false, forceWebView: false);
|
||||||
},
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
if (kReleaseMode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() => _tokenLogin = !_tokenLogin);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (_tokenLogin)
|
||||||
|
FormCard(
|
||||||
|
forceNarrow: calculateLayout(context) != AppLayout.mobile,
|
||||||
|
children: [
|
||||||
|
DecoratedFormField(
|
||||||
|
label: localization.token,
|
||||||
|
controller: _tokenController,
|
||||||
|
),
|
||||||
|
AppButton(
|
||||||
|
label: localization.submit.toUpperCase(),
|
||||||
|
onPressed: () {
|
||||||
|
final Completer<Null> completer = Completer<Null>();
|
||||||
|
viewModel.onTokenLoginPressed(context, completer,
|
||||||
|
token: _tokenController.text);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
AnimatedOpacity(
|
AnimatedOpacity(
|
||||||
duration: Duration(milliseconds: 500),
|
duration: Duration(milliseconds: 500),
|
||||||
opacity: viewModel.authState.isAuthenticated ? 0 : 1,
|
opacity: viewModel.authState.isAuthenticated ? 0 : 1,
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ class LoginVM {
|
||||||
@required this.onSignUpPressed,
|
@required this.onSignUpPressed,
|
||||||
@required this.onGoogleLoginPressed,
|
@required this.onGoogleLoginPressed,
|
||||||
@required this.onGoogleSignUpPressed,
|
@required this.onGoogleSignUpPressed,
|
||||||
|
@required this.onTokenLoginPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
AppState state;
|
AppState state;
|
||||||
|
|
@ -79,6 +80,12 @@ class LoginVM {
|
||||||
@required String password,
|
@required String password,
|
||||||
}) onSignUpPressed;
|
}) onSignUpPressed;
|
||||||
|
|
||||||
|
final Function(
|
||||||
|
BuildContext,
|
||||||
|
Completer<Null> completer, {
|
||||||
|
@required String token,
|
||||||
|
}) onTokenLoginPressed;
|
||||||
|
|
||||||
final Function(BuildContext, Completer<Null> completer,
|
final Function(BuildContext, Completer<Null> completer,
|
||||||
{String url, String secret, String oneTimePassword}) onGoogleLoginPressed;
|
{String url, String secret, String oneTimePassword}) onGoogleLoginPressed;
|
||||||
final Function(BuildContext, Completer<Null> completer) onGoogleSignUpPressed;
|
final Function(BuildContext, Completer<Null> completer) onGoogleSignUpPressed;
|
||||||
|
|
@ -174,8 +181,8 @@ class LoginVM {
|
||||||
idToken: idToken,
|
idToken: idToken,
|
||||||
accessToken: accessToken,
|
accessToken: accessToken,
|
||||||
));
|
));
|
||||||
completer.future.then(
|
completer.future
|
||||||
(_) => _handleLogin(context: context, isSignUp: true));
|
.then((_) => _handleLogin(context: context, isSignUp: true));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!signedIn) {
|
if (!signedIn) {
|
||||||
|
|
@ -246,6 +253,11 @@ class LoginVM {
|
||||||
oneTimePassword: oneTimePassword.trim(),
|
oneTimePassword: oneTimePassword.trim(),
|
||||||
));
|
));
|
||||||
completer.future.then((_) => _handleLogin(context: context));
|
completer.future.then((_) => _handleLogin(context: context));
|
||||||
});
|
},
|
||||||
|
onTokenLoginPressed: (BuildContext context, Completer<Null> completer,
|
||||||
|
{@required String token}) {
|
||||||
|
//
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue