Login
This commit is contained in:
parent
4b98a651f8
commit
bbd2e3d288
|
|
@ -85,6 +85,8 @@ class UserSignUpRequest implements StartLoading {
|
||||||
this.email,
|
this.email,
|
||||||
this.password,
|
this.password,
|
||||||
this.platform,
|
this.platform,
|
||||||
|
this.photoUrl,
|
||||||
|
this.oauthId,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Completer completer;
|
final Completer completer;
|
||||||
|
|
@ -93,4 +95,6 @@ class UserSignUpRequest implements StartLoading {
|
||||||
final String email;
|
final String email;
|
||||||
final String password;
|
final String password;
|
||||||
final String platform;
|
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/redux/dashboard/dashboard_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/app_builder.dart';
|
import 'package:invoiceninja_flutter/ui/app/app_builder.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/strings.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
|
import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
|
||||||
|
|
@ -41,6 +42,7 @@ class LoginVM {
|
||||||
@required this.onLoginPressed,
|
@required this.onLoginPressed,
|
||||||
@required this.onSignUpPressed,
|
@required this.onSignUpPressed,
|
||||||
@required this.onGoogleLoginPressed,
|
@required this.onGoogleLoginPressed,
|
||||||
|
@required this.onGoogleSignUpPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
bool isLoading;
|
bool isLoading;
|
||||||
|
|
@ -67,6 +69,7 @@ class LoginVM {
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
static LoginVM fromStore(Store<AppState> store) {
|
static LoginVM fromStore(Store<AppState> store) {
|
||||||
final GoogleSignIn _googleSignIn = GoogleSignIn(
|
final GoogleSignIn _googleSignIn = GoogleSignIn(
|
||||||
|
|
@ -118,6 +121,28 @@ class LoginVM {
|
||||||
print(error);
|
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: (
|
onSignUpPressed: (
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Completer<Null> completer, {
|
Completer<Null> completer, {
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,19 @@ String toSnakeCase(String value) {
|
||||||
return value.replaceAllMapped(
|
return value.replaceAllMapped(
|
||||||
RegExp(r'[A-Z]'), (Match match) => '_' + match[0].toLowerCase());
|
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