コード例 #1
0
 private async Task LoginGoogle(String token)
 {
     if (await _firebaseService.SignInWithGoogle(token))
     {
         //await NavigationService.NavigateToAsync<MainViewModel>();
     }
 }
コード例 #2
0
ファイル: SignInViewModel.cs プロジェクト: cabauman/SSBakery
        private IObservable <Unit> AuthenticateWithFirebase(string authToken)
        {
            IObservable <Unit> result = null;

            if (_provider == "google")
            {
                result = _firebaseAuthService
                         .SignInWithGoogle(null, authToken);
            }
            else if (_provider == "facebook")
            {
                result = _firebaseAuthService
                         .SignInWithFacebook(authToken);
            }

            return(result);
        }
コード例 #3
0
        private IObservable <Unit> AuthenticateWithFirebase(string authToken)
        {
            IObservable <Unit> result = null;

            if (_provider == "google")
            {
                //result = _firebaseAuthService.CurrentUser
                //    .LinkWithGoogle(null, authToken).Select(_ => Unit.Default);
                result = _firebaseAuthService
                         .SignInWithGoogle(null, authToken);
            }
            else if (_provider == "facebook")
            {
                result = _firebaseAuthService
                         .SignInWithFacebook(authToken);
            }

            return(result);
        }
コード例 #4
0
ファイル: LoginViewModel.cs プロジェクト: gorojou/firebaseapp
 private async Task LoginGoogleCommandExecute()
 {
     _firebaseService.SignInWithGoogle();
 }
コード例 #5
0
        public SignupPageViewModel(
            INavigationService navigationService,
            IContainerRegistry containerRegistry,
            IUserDataStore userDataStore,
            IUserDialogs dialogService,
            IFirebaseAuthService firebaseAuthService) : base(navigationService)
        {
            Title = "Sign Up";
            _containerRegistry = containerRegistry;
            _userDataStore     = userDataStore;

            // we want to disable all commands when any one is running. We'll do that by using a
            // behavior subject to play all of the command events through
            BehaviorSubject <bool> canExecute = new BehaviorSubject <bool>(true);

            SignInWithGoogle = ReactiveCommand.CreateFromTask(async() =>
            {
                if (!AgreeWithTermsAndConditions)
                {
                    await ShowTermsAndConditionsValidationMessage(dialogService).ConfigureAwait(false);
                    return;
                }

                if (await firebaseAuthService.SignInWithGoogle())
                {
                    var userId  = firebaseAuthService.GetCurrentUserId();
                    var account = await new FakeUserDataStore().GetUserById(userId);

                    if (account != null)
                    {
                        // if the account is not null, the user is already registered. Just log them
                        // in and head to the home screen
                        _containerRegistry.RegisterInstance <IUserService>(new UserService(account));

                        await NavigationService.NavigateHomeAsync().ConfigureAwait(false);
                    }
                    else
                    {
                        // The account does not yet exist. Go through the registration process
                        await NavigationService
                        .NavigateAsync(
                            nameof(RegistrationTypeSelectionPage),
                            new NavigationParameters
                        {
                            { "user_id", userId }
                        }).ConfigureAwait(false);
                    }
                }
            },
                                                              canExecute);

            SignInWithFacebook = ReactiveCommand.CreateFromTask(async() =>
            {
                if (!AgreeWithTermsAndConditions)
                {
                    await ShowTermsAndConditionsValidationMessage(dialogService).ConfigureAwait(false);
                    return;
                }

                await dialogService.AlertAsync("Coming Soon!").ConfigureAwait(false);
            },
                                                                canExecute);

            SignInWithTwitter = ReactiveCommand.CreateFromTask(async() =>
            {
                if (!AgreeWithTermsAndConditions)
                {
                    await ShowTermsAndConditionsValidationMessage(dialogService).ConfigureAwait(false);
                    return;
                }

                await dialogService.AlertAsync("Coming Soon!").ConfigureAwait(false);
            },
                                                               canExecute);

            var commandsExecuting = Observable.CombineLatest(
                SignInWithGoogle.IsExecuting,
                SignInWithFacebook.IsExecuting,
                SignInWithTwitter.IsExecuting,
                (googleExecuting, facebookExecuting, twitterExecuting) => googleExecuting || facebookExecuting || twitterExecuting)
                                    .DistinctUntilChanged()
                                    .Publish()
                                    .RefCount();

            // when any of the commands are executing, update the busy state
            commandsExecuting
            .StartWith(false)
            .ToProperty(this, x => x.IsBusy, out _isBusy, scheduler: RxApp.MainThreadScheduler);

            // when any of the commands are executing, update the "can execute" state
            commandsExecuting
            .Select(isExecuting => !isExecuting)
            .Subscribe(canExecute);

            // When an exception is thrown from a command, log the error and let the user handle the exception
            SignInWithGoogle.ThrownExceptions
            .Merge(SignInWithFacebook.ThrownExceptions)
            .Merge(SignInWithTwitter.ThrownExceptions)
            .SelectMany(exception =>
            {
                this.Log().ErrorException("Error signing up", exception);

                //return SharedInteractions.Error.Handle(exception);
                return(Observable.Return(Unit.Default));
            })
            .Subscribe();
        }
コード例 #6
0
        public LoginPageViewModel(
            INavigationService navigationService,
            IContainerRegistry containerRegistry,
            IUserDataStore userDataStore,
            IUserDialogs dialogs,
            IFirebaseAuthService firebaseAuthService) : base(navigationService)
        {
            Title = "Login";
            _containerRegistry = containerRegistry;

            // we want to disable all commands when any one is running. We'll do that by using a
            // behavior subject to play all of the command events through
            BehaviorSubject <bool> canExecute = new BehaviorSubject <bool>(true);

            SignInWithGoogle = ReactiveCommand.CreateFromTask(async() =>
            {
                if (await firebaseAuthService.SignInWithGoogle())
                {
                    var userId  = firebaseAuthService.GetCurrentUserId();
                    var account = await new FakeUserDataStore().GetUserById(userId);
                    account     = null; // TODO: Remove this

                    if (account == null)
                    {
                        // if the account doesn't exist, prompt the user to register
                        var shouldSignUp = await dialogs.ConfirmAsync(
                            new ConfirmConfig
                        {
                            Message = "The account does not appear to exist.  Would you like to sign up?",
                            OkText  = "Sign Up!"
                        });
                        if (shouldSignUp)
                        {
                            await NavigationService
                            .NavigateAsync(
                                nameof(RegistrationTypeSelectionPage),
                                new NavigationParameters
                            {
                                { "user_id", userId }
                            }).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        // the account exists. Head to the home page
                        _containerRegistry.RegisterInstance <IUserService>(new UserService(account));

                        await NavigationService.NavigateHomeAsync().ConfigureAwait(false);
                    }
                }
                else
                {
                    await dialogs.AlertAsync(
                        new AlertConfig
                    {
                        Title   = "Error",
                        Message = "Login failed"
                    }).ConfigureAwait(false);

                    // TODO: Should call log out just to be safe?
                }
            },
                                                              canExecute);

            SignInWithFacebook = ReactiveCommand.CreateFromTask(async() =>
            {
                await dialogs.AlertAsync("Coming Soon!").ConfigureAwait(false);
            },
                                                                canExecute);

            SignInWithTwitter = ReactiveCommand.CreateFromTask(async() =>
            {
                await dialogs.AlertAsync("Coming Soon!").ConfigureAwait(false);
            },
                                                               canExecute);

            var commandsExecuting = Observable.CombineLatest(
                SignInWithGoogle.IsExecuting,
                SignInWithFacebook.IsExecuting,
                SignInWithTwitter.IsExecuting,
                (googleExecuting, facebookExecuting, twitterExecuting) => googleExecuting || facebookExecuting || twitterExecuting)
                                    .DistinctUntilChanged()
                                    .Publish()
                                    .RefCount();

            // when any of the commands are executing, update the busy state
            commandsExecuting
            .StartWith(false)
            .ToProperty(this, x => x.IsBusy, out _isBusy, scheduler: RxApp.MainThreadScheduler);

            // when any of the commands are executing, update the "can execute" state
            commandsExecuting
            .Select(isExecuting => !isExecuting)
            .Subscribe(canExecute);

            // When an exception is thrown from a command, log the error and let the user handle the exception
            SignInWithGoogle.ThrownExceptions
            .Merge(SignInWithFacebook.ThrownExceptions)
            .Merge(SignInWithTwitter.ThrownExceptions)
            .SelectMany(exception =>
            {
                this.Log().ErrorException("Error logging in", exception);

                //return SharedInteractions.Error.Handle(exception);
                return(Observable.Return(Unit.Default));
            })
            .Subscribe();
        }
コード例 #7
0
 private void LoginGoogleCommandExecute()
 {
     _firebaseService.SignInWithGoogle();
 }