示例#1
0
        public AccountsBaseViewModel(IUserDialogs userDialogs,
                                     IMvxMessenger mvxMessenger, AppHelper appHelper,
                                     IOAuthService oauthService, INotificationService notificationService,
                                     IAuthenticationService authenticationService)
            : base(userDialogs, mvxMessenger, appHelper)
        {
            _oAuthService          = oauthService;
            _notificationService   = notificationService;
            _authenticationService = authenticationService;

            // Create Reactive Commands
            LoginWithFacebookCommand = ReactiveCommand.CreateFromObservable <Unit, string>(
                (param) =>
            {
                ResetCommonProps();

                return(oauthService
                       .Authenticate(new ParentFacebookOAuth2())
                       .Do(AuthDict =>
                {
                    if (!AuthDict.ContainsKey("access_token") || string.IsNullOrEmpty(AuthDict["access_token"]))
                    {
                        throw new OAuthInvalidAccessTokenException();
                    }

                    HandleIsExecuting(true, AppResources.Login_Authenticating_Facebook, FontAwesomeFont.Facebook);
                })
                       .SelectMany(AuthDict => authenticationService.LoginWithFacebook(AuthDict["access_token"])));
            });


            LoginWithFacebookCommand.Subscribe(HandleAuthSuccess);


            LoginWithFacebookCommand.ThrownExceptions.Subscribe(HandleExceptions);


            LoginWithGoogleCommand = ReactiveCommand.CreateFromObservable <Unit, string>(
                (param) =>
            {
                ResetCommonProps();

                return(oauthService
                       .Authenticate(new ParentGoogleOAuth2())
                       .Do(AuthDict =>
                {
                    if (!AuthDict.ContainsKey("access_token") || string.IsNullOrEmpty(AuthDict["access_token"]))
                    {
                        throw new OAuthInvalidAccessTokenException();
                    }

                    HandleIsExecuting(true, AppResources.Login_Authenticating_Google, FontAwesomeFont.Google);
                })
                       .SelectMany(AuthDict => authenticationService.LoginWithGoogle(AuthDict["access_token"])));
            });

            LoginWithGoogleCommand.Subscribe(HandleAuthSuccess);

            LoginWithGoogleCommand.ThrownExceptions.Subscribe(HandleExceptions);
        }
示例#2
0
        public LoginPageViewModel(INavigationService navigationService, IGoogleLoginService googleLoginService, IPageDialogService pageDialogService) : base(navigationService)
        {
            _googleLoginService = googleLoginService;
            _pageDialogService  = pageDialogService;

            _googleLoginService.LoginCompletedNotifier
            .ObserveOn(SynchronizationContext.Current)
            .SelectMany(_ =>
            {
                var navigation = NavigationFactory.Create <MainPageViewModel>()
                                 .Add(NavigationNameProvider.DefaultNavigationPageName)
                                 .Add <HomePageViewModel>();
                return(NavigateAsync(navigation, noHistory: true));
            })
            .Subscribe()
            .AddTo(_disposables);

            _googleLoginService.LoginErrorNotifier
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(_ => _pageDialogService.DisplayAlertAsync("エラー", "ログインに失敗しました", "OK"))
            .AddTo(_disposables);

            _googleLoginService.IsLoggingIn
            .Skip(1)
            .Where(b => b)
            .ObserveOn(SynchronizationContext.Current)
            .SelectMany(_ => NavigateAsync <LoadingPageViewModel>())
            .Subscribe()
            .AddTo(_disposables);

            _googleLoginService.IsLoggingIn
            .Skip(1)
            .Where(b => !b)
            .ObserveOn(SynchronizationContext.Current)
            .SelectMany(_ => GoBackAsync())
            .Subscribe()
            .AddTo(_disposables);

            LoginWithGoogleCommand = _isIdle.ToAsyncReactiveCommand();
            LoginWithGoogleCommand.Subscribe(async() => await _googleLoginService.Login());

            LoginWithEmailCommand = _isIdle.ToAsyncReactiveCommand();
            LoginWithEmailCommand.Subscribe(async() => await NavigateAsync <EmailLoginPageViewModel>());

            SignupCommand = _isIdle.ToAsyncReactiveCommand();
            SignupCommand.Subscribe(async() => await NavigateAsync <SignupPageViewModel>());
        }