Microsoft Login
This commit is contained in:
parent
8be64fdf29
commit
daf7768dfd
|
|
@ -94,9 +94,6 @@ const String kProductPlanEnterprise5 = 'v1_enterprise_5_yearly';
|
||||||
const String kProductPlanEnterprise10 = 'v1_enterprise_10_yearly';
|
const String kProductPlanEnterprise10 = 'v1_enterprise_10_yearly';
|
||||||
const String kProductPlanEnterprise20 = 'v1_enterprise_20_yearly';
|
const String kProductPlanEnterprise20 = 'v1_enterprise_20_yearly';
|
||||||
|
|
||||||
const String kOAuthProviderMicrosoft = 'microsoft';
|
|
||||||
const String kOAuthProviderGoogle = 'google';
|
|
||||||
|
|
||||||
const kProductPlans = [
|
const kProductPlans = [
|
||||||
kProductPlanPro,
|
kProductPlanPro,
|
||||||
kProductPlanEnterprise2,
|
kProductPlanEnterprise2,
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,7 @@ abstract class UserEntity extends Object
|
||||||
UserEntity._();
|
UserEntity._();
|
||||||
|
|
||||||
static const OAUTH_PROVIDER_GOOGLE = 'google';
|
static const OAUTH_PROVIDER_GOOGLE = 'google';
|
||||||
|
static const OAUTH_PROVIDER_MICROSOFT = 'microsoft';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@memoized
|
@memoized
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
// Package imports:
|
// Package imports:
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
// Project imports:
|
// Project imports:
|
||||||
import 'package:invoiceninja_flutter/constants.dart';
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/token_model.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_actions.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';
|
||||||
|
|
@ -171,7 +171,7 @@ class LoginVM {
|
||||||
url: _formatApiUrl(url),
|
url: _formatApiUrl(url),
|
||||||
secret: secret.trim(),
|
secret: secret.trim(),
|
||||||
platform: getPlatform(context),
|
platform: getPlatform(context),
|
||||||
provider: kOAuthProviderGoogle,
|
provider: UserEntity.OAUTH_PROVIDER_GOOGLE,
|
||||||
oneTimePassword: oneTimePassword,
|
oneTimePassword: oneTimePassword,
|
||||||
));
|
));
|
||||||
completer.future.then((_) => _handleLogin(context: context));
|
completer.future.then((_) => _handleLogin(context: context));
|
||||||
|
|
@ -200,7 +200,7 @@ class LoginVM {
|
||||||
completer: completer,
|
completer: completer,
|
||||||
idToken: idToken,
|
idToken: idToken,
|
||||||
accessToken: accessToken,
|
accessToken: accessToken,
|
||||||
provider: kOAuthProviderGoogle,
|
provider: UserEntity.OAUTH_PROVIDER_GOOGLE,
|
||||||
));
|
));
|
||||||
completer.future
|
completer.future
|
||||||
.then((_) => _handleLogin(context: context, isSignUp: true));
|
.then((_) => _handleLogin(context: context, isSignUp: true));
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,9 @@ import 'package:invoiceninja_flutter/utils/dialogs.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/oauth.dart';
|
import 'package:invoiceninja_flutter/utils/oauth.dart';
|
||||||
|
|
||||||
|
import 'package:invoiceninja_flutter/utils/web_stub.dart'
|
||||||
|
if (dart.library.html) 'package:invoiceninja_flutter/utils/web.dart';
|
||||||
|
|
||||||
class UserDetailsScreen extends StatelessWidget {
|
class UserDetailsScreen extends StatelessWidget {
|
||||||
const UserDetailsScreen({Key key}) : super(key: key);
|
const UserDetailsScreen({Key key}) : super(key: key);
|
||||||
static const String route = '/$kSettings/$kSettingsUserDetails';
|
static const String route = '/$kSettings/$kSettingsUserDetails';
|
||||||
|
|
@ -51,6 +54,8 @@ class UserDetailsVM {
|
||||||
@required this.onConnectGmailPressed,
|
@required this.onConnectGmailPressed,
|
||||||
@required this.onDisconnectGmailPressed,
|
@required this.onDisconnectGmailPressed,
|
||||||
@required this.onDisableTwoFactorPressed,
|
@required this.onDisableTwoFactorPressed,
|
||||||
|
@required this.onConnectMicrosoftPressed,
|
||||||
|
@required this.onDisconnectMicrosoftPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
static UserDetailsVM fromStore(Store<AppState> store) {
|
static UserDetailsVM fromStore(Store<AppState> store) {
|
||||||
|
|
@ -201,6 +206,56 @@ class UserDetailsVM {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onDisconnectMicrosoftPressed: (context) {
|
||||||
|
if (!state.user.hasPassword) {
|
||||||
|
showErrorDialog(
|
||||||
|
context: context,
|
||||||
|
message: AppLocalization.of(context).pleaseFirstSetAPassword);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmCallback(
|
||||||
|
context: context,
|
||||||
|
callback: (_) {
|
||||||
|
passwordCallback(
|
||||||
|
context: context,
|
||||||
|
callback: (password, idToken) {
|
||||||
|
final completer = snackBarCompleter<Null>(context,
|
||||||
|
AppLocalization.of(context).disconnectedMicrosoft);
|
||||||
|
store.dispatch(
|
||||||
|
SaveAuthUserRequest(
|
||||||
|
user: state.user.rebuild((b) => b..oauthProvider = ''),
|
||||||
|
password: password,
|
||||||
|
idToken: idToken,
|
||||||
|
completer: completer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onConnectMicrosoftPressed: (context) {
|
||||||
|
final completer = snackBarCompleter<Null>(
|
||||||
|
context, AppLocalization.of(context).connectedMicrosoft);
|
||||||
|
|
||||||
|
passwordCallback(
|
||||||
|
context: context,
|
||||||
|
callback: (password, idToken) async {
|
||||||
|
try {
|
||||||
|
WebUtils.microsoftLogin((idToken, accessToken) {
|
||||||
|
store.dispatch(
|
||||||
|
ConnecOAuthUserRequest(
|
||||||
|
provider: UserEntity.OAUTH_PROVIDER_MICROSOFT,
|
||||||
|
password: password,
|
||||||
|
idToken: idToken,
|
||||||
|
completer: completer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
showErrorDialog(context: context, message: error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
onSavePressed: (context) {
|
onSavePressed: (context) {
|
||||||
Debouncer.runOnComplete(() {
|
Debouncer.runOnComplete(() {
|
||||||
final localization = AppLocalization.of(context);
|
final localization = AppLocalization.of(context);
|
||||||
|
|
@ -265,6 +320,8 @@ class UserDetailsVM {
|
||||||
final Function(BuildContext) onSavePressed;
|
final Function(BuildContext) onSavePressed;
|
||||||
final Function(BuildContext) onConnectGooglePressed;
|
final Function(BuildContext) onConnectGooglePressed;
|
||||||
final Function(BuildContext) onDisconnectGooglePressed;
|
final Function(BuildContext) onDisconnectGooglePressed;
|
||||||
|
final Function(BuildContext) onConnectMicrosoftPressed;
|
||||||
|
final Function(BuildContext) onDisconnectMicrosoftPressed;
|
||||||
final Function(BuildContext, Completer, String) onConnectGmailPressed;
|
final Function(BuildContext, Completer, String) onConnectGmailPressed;
|
||||||
final Function(BuildContext) onDisconnectGmailPressed;
|
final Function(BuildContext) onDisconnectGmailPressed;
|
||||||
final Function(BuildContext) onDisableTwoFactorPressed;
|
final Function(BuildContext) onDisableTwoFactorPressed;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
||||||
static final Map<String, Map<String, String>> _localizedValues = {
|
static final Map<String, Map<String, String>> _localizedValues = {
|
||||||
'en': {
|
'en': {
|
||||||
// STARTER: lang key - do not remove comment
|
// STARTER: lang key - do not remove comment
|
||||||
|
'connected_microsoft': 'Successfully connected Microsoft',
|
||||||
|
'disconnected_microsoft': 'Successfully disconnected Microsoft',
|
||||||
'microsoft_sign_in': 'Login with Microsoft',
|
'microsoft_sign_in': 'Login with Microsoft',
|
||||||
'microsoft_sign_up': 'Sign up with Microsoft',
|
'microsoft_sign_up': 'Sign up with Microsoft',
|
||||||
'emailed_purchase_order': 'Successfully queued purchase order to be sent',
|
'emailed_purchase_order': 'Successfully queued purchase order to be sent',
|
||||||
|
|
@ -70711,6 +70713,16 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
||||||
_localizedValues['en']['microsoft_sign_in'] ??
|
_localizedValues['en']['microsoft_sign_in'] ??
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
String get disconnectedMicrosoft =>
|
||||||
|
_localizedValues[localeCode]['disconnected_microsoft'] ??
|
||||||
|
_localizedValues['en']['disconnected_microsoft'] ??
|
||||||
|
'';
|
||||||
|
|
||||||
|
String get connectedMicrosoft =>
|
||||||
|
_localizedValues[localeCode]['connected_google'] ??
|
||||||
|
_localizedValues['en']['connected_googlek'] ??
|
||||||
|
'';
|
||||||
|
|
||||||
// STARTER: lang field - do not remove comment
|
// STARTER: lang field - do not remove comment
|
||||||
|
|
||||||
String lookup(String key) {
|
String lookup(String key) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue