Login
This commit is contained in:
parent
4b98a651f8
commit
bbd2e3d288
|
|
@ -85,6 +85,8 @@ class UserSignUpRequest implements StartLoading {
|
|||
this.email,
|
||||
this.password,
|
||||
this.platform,
|
||||
this.photoUrl,
|
||||
this.oauthId,
|
||||
});
|
||||
|
||||
final Completer completer;
|
||||
|
|
@ -93,4 +95,6 @@ class UserSignUpRequest implements StartLoading {
|
|||
final String email;
|
||||
final String password;
|
||||
final String platform;
|
||||
final String photoUrl;
|
||||
final String oauthId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
|||
import 'package:invoiceninja_flutter/redux/dashboard/dashboard_actions.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/app_builder.dart';
|
||||
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
||||
import 'package:invoiceninja_flutter/utils/strings.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
|
||||
|
|
@ -41,6 +42,7 @@ class LoginVM {
|
|||
@required this.onLoginPressed,
|
||||
@required this.onSignUpPressed,
|
||||
@required this.onGoogleLoginPressed,
|
||||
@required this.onGoogleSignUpPressed,
|
||||
});
|
||||
|
||||
bool isLoading;
|
||||
|
|
@ -67,6 +69,7 @@ class LoginVM {
|
|||
|
||||
final Function(BuildContext, Completer<Null> completer,
|
||||
{String url, String secret, String oneTimePassword}) onGoogleLoginPressed;
|
||||
final Function(BuildContext, Completer<Null> completer) onGoogleSignUpPressed;
|
||||
|
||||
static LoginVM fromStore(Store<AppState> store) {
|
||||
final GoogleSignIn _googleSignIn = GoogleSignIn(
|
||||
|
|
@ -118,6 +121,28 @@ class LoginVM {
|
|||
print(error);
|
||||
}
|
||||
},
|
||||
onGoogleSignUpPressed:
|
||||
(BuildContext context, Completer<Null> completer) async {
|
||||
try {
|
||||
final account = await _googleSignIn.signIn();
|
||||
|
||||
if (account != null) {
|
||||
account.authentication.then((GoogleSignInAuthentication value) {
|
||||
store.dispatch(UserSignUpRequest(
|
||||
completer: completer,
|
||||
email: account.email,
|
||||
firstName: getFirstName(account.displayName),
|
||||
lastName: getLastName(account.displayName),
|
||||
photoUrl: account.photoUrl,
|
||||
oauthId: account.id,
|
||||
));
|
||||
completer.future.then((_) => _handleLogin(context));
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
print(error);
|
||||
}
|
||||
},
|
||||
onSignUpPressed: (
|
||||
BuildContext context,
|
||||
Completer<Null> completer, {
|
||||
|
|
|
|||
|
|
@ -2,3 +2,19 @@ String toSnakeCase(String value) {
|
|||
return value.replaceAllMapped(
|
||||
RegExp(r'[A-Z]'), (Match match) => '_' + match[0].toLowerCase());
|
||||
}
|
||||
|
||||
String getFirstName(String value) {
|
||||
final parts = value.split(' ');
|
||||
if (parts.length > 1) {
|
||||
parts.removeLast();
|
||||
}
|
||||
return parts.join(' ');
|
||||
}
|
||||
|
||||
String getLastName(String value) {
|
||||
final parts = value.split(' ');
|
||||
if (parts.length <= 1) {
|
||||
return '';
|
||||
}
|
||||
return parts.last;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue