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 kProductPlanEnterprise20 = 'v1_enterprise_20_yearly';
|
||||
|
||||
const String kOAuthProviderMicrosoft = 'microsoft';
|
||||
const String kOAuthProviderGoogle = 'google';
|
||||
|
||||
const kProductPlans = [
|
||||
kProductPlanPro,
|
||||
kProductPlanEnterprise2,
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ abstract class UserEntity extends Object
|
|||
UserEntity._();
|
||||
|
||||
static const OAUTH_PROVIDER_GOOGLE = 'google';
|
||||
static const OAUTH_PROVIDER_MICROSOFT = 'microsoft';
|
||||
|
||||
@override
|
||||
@memoized
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ import 'package:flutter/material.dart';
|
|||
|
||||
// Package imports:
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
// Project imports:
|
||||
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_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
|
||||
|
|
@ -171,7 +171,7 @@ class LoginVM {
|
|||
url: _formatApiUrl(url),
|
||||
secret: secret.trim(),
|
||||
platform: getPlatform(context),
|
||||
provider: kOAuthProviderGoogle,
|
||||
provider: UserEntity.OAUTH_PROVIDER_GOOGLE,
|
||||
oneTimePassword: oneTimePassword,
|
||||
));
|
||||
completer.future.then((_) => _handleLogin(context: context));
|
||||
|
|
@ -200,7 +200,7 @@ class LoginVM {
|
|||
completer: completer,
|
||||
idToken: idToken,
|
||||
accessToken: accessToken,
|
||||
provider: kOAuthProviderGoogle,
|
||||
provider: UserEntity.OAUTH_PROVIDER_GOOGLE,
|
||||
));
|
||||
completer.future
|
||||
.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/oauth.dart';
|
||||
|
||||
import 'package:invoiceninja_flutter/utils/web_stub.dart'
|
||||
if (dart.library.html) 'package:invoiceninja_flutter/utils/web.dart';
|
||||
|
||||
class UserDetailsScreen extends StatelessWidget {
|
||||
const UserDetailsScreen({Key key}) : super(key: key);
|
||||
static const String route = '/$kSettings/$kSettingsUserDetails';
|
||||
|
|
@ -51,6 +54,8 @@ class UserDetailsVM {
|
|||
@required this.onConnectGmailPressed,
|
||||
@required this.onDisconnectGmailPressed,
|
||||
@required this.onDisableTwoFactorPressed,
|
||||
@required this.onConnectMicrosoftPressed,
|
||||
@required this.onDisconnectMicrosoftPressed,
|
||||
});
|
||||
|
||||
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) {
|
||||
Debouncer.runOnComplete(() {
|
||||
final localization = AppLocalization.of(context);
|
||||
|
|
@ -265,6 +320,8 @@ class UserDetailsVM {
|
|||
final Function(BuildContext) onSavePressed;
|
||||
final Function(BuildContext) onConnectGooglePressed;
|
||||
final Function(BuildContext) onDisconnectGooglePressed;
|
||||
final Function(BuildContext) onConnectMicrosoftPressed;
|
||||
final Function(BuildContext) onDisconnectMicrosoftPressed;
|
||||
final Function(BuildContext, Completer, String) onConnectGmailPressed;
|
||||
final Function(BuildContext) onDisconnectGmailPressed;
|
||||
final Function(BuildContext) onDisableTwoFactorPressed;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
static final Map<String, Map<String, String>> _localizedValues = {
|
||||
'en': {
|
||||
// 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_up': 'Sign up with Microsoft',
|
||||
'emailed_purchase_order': 'Successfully queued purchase order to be sent',
|
||||
|
|
@ -70711,6 +70713,16 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
_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
|
||||
|
||||
String lookup(String key) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue