Пример #1
0
 public async void GoogleLoginAsync()
 {
     _googleClientManager.OnLogin += OnGoogleLoginCompleted;
     try
     {
         await _googleClientManager.LoginAsync();
     }
     catch (GoogleClientSignInNetworkErrorException e)
     {
         await App.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
     }
     catch (GoogleClientSignInCanceledErrorException e)
     {
         await App.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
     }
     catch (GoogleClientSignInInvalidAccountErrorException e)
     {
         await App.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
     }
     catch (GoogleClientSignInInternalErrorException e)
     {
         await App.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
     }
     catch (GoogleClientNotInitializedErrorException e)
     {
         await App.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
     }
     catch (GoogleClientBaseException e)
     {
         await App.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
     }
 }
Пример #2
0
        async Task LoginGoogleAsync(AuthNetwork authNetwork)
        {
            try
            {
                if (!string.IsNullOrEmpty(_googleService.AccessToken))
                {
                    //Always require user authentication
                    _googleService.Logout();
                }

                EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null;
                userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) =>
                {
                    switch (e.Status)
                    {
                    case GoogleActionStatus.Completed:
#if DEBUG
                        var googleUserString = JsonConvert.SerializeObject(e.Data);
                        Debug.WriteLine($"Google Logged in succesfully: {googleUserString}");
#endif

                        var socialLoginData = new NetworkAuthData
                        {
                            Logo       = authNetwork.Icon,
                            Foreground = authNetwork.Foreground,
                            Background = authNetwork.Background,
                            Name       = e.Data.Name,
                        };

                        //await App.Current.MainPage.Navigation.PushModalAsync(new HomePage(socialLoginData));
                        break;

                    case GoogleActionStatus.Canceled:
                        await App.Current.MainPage.DisplayAlert("Google Auth", "Canceled", "Ok");

                        break;

                    case GoogleActionStatus.Error:
                        await App.Current.MainPage.DisplayAlert("Google Auth", "Error", "Ok");

                        break;

                    case GoogleActionStatus.Unauthorized:
                        await App.Current.MainPage.DisplayAlert("Google Auth", "Unauthorized", "Ok");

                        break;
                    }

                    //_googleService.OnLogin -= userLoginDelegate;
                };

                //_googleService.OnLogin += userLoginDelegate;

                await _googleService.LoginAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
Пример #3
0
 private async void InicioSesionCommand()
 {
     googleClientManager.OnLogin += OnLoginCompleted;
     try
     {
         await googleClientManager.LoginAsync();
     }
     catch (Exception e)
     {
         await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");
     }
 }
Пример #4
0
        private async void InicioSesionCommand()
        {
            EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null;

            userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) =>
            {
                if (e != null)
                {
                    GoogleUser user = e.Data;
                    Usuario = new UsuarioModel()
                    {
                        idUsuario   = 0,
                        Apodo       = user.Email.Remove(user.Email.LastIndexOf('@')),
                        NombreP     = user.GivenName,
                        ApellidoP   = user.FamilyName,
                        FotoPerfilP = "",
                        EstadoP     = "Activo"
                    };
                    await SeleccionarUsuario();

                    if (Usuario.idUsuario == 0)
                    {
                        await CrearUsuario();
                        await SeleccionarUsuario();
                    }
                    if (Usuario.idUsuario != 0)
                    {
                        StorageUser(Usuario);
                        await loadDataHandler.PersistenceDataAsync("Usuario", Usuario);

                        Application.Current.MainPage = new MainPage();
                    }
                    else
                    {
                        ((MessageViewModel)PopUp.BindingContext).Message = "Error al conectar con el servidor";
                        await PopupNavigation.Instance.PushAsync(PopUp);
                    }
                }
            };
            googleClientManager.OnLogin += userLoginDelegate;
            try
            {
                await googleClientManager.LoginAsync();
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            BtnLogout.Hidden         = true;
            BtnLogout.TouchUpInside += (object sender, EventArgs e) =>
            {
                _googleClientManager.Logout();
                BtnLogin.Hidden  = false;
                BtnLogout.Hidden = true;
                _googleClientManager.OnLogout += (object s, EventArgs ee) =>
                {
                    LblUsername.Text     = string.Empty;
                    LblEmailAddress.Text = string.Empty;
                    FullImageView.Image  = new UIImage();
                };
            };

            BtnLogin.TouchUpInside += async delegate
            {
                _googleClientManager.OnLogin += _googleClientManager_OnLogin;
                try
                {
                    await _googleClientManager.LoginAsync();
                }
                catch (GoogleClientSignInNetworkErrorException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (GoogleClientSignInCanceledErrorException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (GoogleClientSignInInvalidAccountErrorException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (GoogleClientSignInInternalErrorException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (GoogleClientBaseException e)
                {
                    Console.WriteLine(e.Message);
                }
            };
        }
        async Task LoginGoogleAsync()
        {
            try
            {
                if (!string.IsNullOrEmpty(_googleService.ActiveToken))
                {
                    //Always require user authentication
                    _googleService.Logout();
                }
                EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null;
                userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) =>
                {
                    switch (e.Status)
                    {
                    case GoogleActionStatus.Completed:
                        await App.Current.MainPage.Navigation.PushModalAsync(new WelcomePage(e.Data));

                        break;

                    case GoogleActionStatus.Canceled:
                        await App.Current.MainPage.DisplayAlert("Google Auth", "Canceled", "Ok");

                        break;

                    case GoogleActionStatus.Error:
                        await App.Current.MainPage.DisplayAlert("Google Auth", "Error", "Ok");

                        break;

                    case GoogleActionStatus.Unauthorized:
                        await App.Current.MainPage.DisplayAlert("Google Auth", "Unauthorized", "Ok");

                        break;
                    }
                    _googleService.OnLogin -= userLoginDelegate;
                };
                _googleService.OnLogin += userLoginDelegate;
                await _googleService.LoginAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
Пример #7
0
        async Task LoginGoogleAsync()
        {
            try
            {
                if (!string.IsNullOrEmpty(_googleService.AccessToken))
                {
                    //Always require user authentication
                    _googleService.Logout();
                }

                EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null;
                userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) =>
                {
                    switch (e.Status)
                    {
                    case GoogleActionStatus.Completed:
#if DEBUG
                        var googleUserString = JsonConvert.SerializeObject(e.Data);
                        Debug.WriteLine($"Google Logged in succesfully: {googleUserString}");
#endif

                        var socialLoginData = new EquipmentsViewModel.Nav
                        {
                            Data = new NetworkAuthData
                            {
                                Id      = e.Data.Id,
                                Picture = e.Data.Picture.AbsoluteUri,
                                Name    = e.Data.Name,
                            }
                        };
                        //await this.CoreMethods.PushPageModel<EquipmentsViewModel>(socialLoginData, true);
                        var page = FreshPageModelResolver.ResolvePageModel <EquipmentsViewModel>(socialLoginData);
                        var basicNavContainer = new FreshNavigationContainer(page);
                        Application.Current.MainPage = basicNavContainer;
                        break;

                    case GoogleActionStatus.Canceled:
                        await this.CoreMethods.DisplayAlert("Google Auth", "Canceled", "Ok");

                        break;

                    case GoogleActionStatus.Error:
                        await this.CoreMethods.DisplayAlert("Google Auth", "Error", "Ok");

                        break;

                    case GoogleActionStatus.Unauthorized:
                        await this.CoreMethods.DisplayAlert("Google Auth", "Unauthorized", "Ok");

                        break;
                    }

                    _googleService.OnLogin -= userLoginDelegate;
                };

                _googleService.OnLogin += userLoginDelegate;

                await _googleService.LoginAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
Пример #8
0
        private async Task LoginGoogleAsync()
        {
            try
            {
                //Check if the user is already logged in
                //potentially will remove this in the future otherwise create appropriate handler
                if (!string.IsNullOrEmpty((googleClient.AccessToken)))
                {
                    googleClient.Logout();
                }

                //Create the event/delegate of Google user type and initialize it
                EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null;

                //Lets do the login
                userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) =>
                {
                    switch (e.Status)
                    {
                    case GoogleActionStatus.Completed:
                        var googleResultString = JsonConvert.SerializeObject(e.Data);

                        //A check with the user profile image is empty
                        string url = string.Empty;
                        if (e.Data.Picture.AbsoluteUri != null)
                        {
                            url = e.Data.Picture.AbsoluteUri;
                        }

                        //map the e.data into our SocialMediaUser model
                        var socialMediaUser = new SocialMediaUser
                        {
                            Email      = e.Data.Email,
                            Name       = e.Data.Name,
                            PictureURL = url
                        };

                        //Once the model is set, send it to the selectLeague page
                        await App.Current.MainPage.Navigation.PushModalAsync(new SelectLeagues());

                        break;

                    case GoogleActionStatus.Canceled:
                        /*For now we will display an alert here but we will move this elsewhere
                         * so that we can just return a msg into that VM and display it properly
                         * and finally navigate to login page
                         */
                        await App.Current.MainPage.DisplayAlert("Google Login", "Google Login Cancelled by user", "OK");

                        await App.Current.MainPage.Navigation.PushModalAsync(new LoginPage());

                        break;

                    case GoogleActionStatus.Error:
                        /*For now we will display an alert here but we will move this elsewhere
                         * so that we can just return a msg into that VM and display it properly
                         * and finally navigate to login page
                         */
                        await App.Current.MainPage.DisplayAlert("Google Login", "Error from Google signing in", "OK");

                        await App.Current.MainPage.Navigation.PushModalAsync(new LoginPage());

                        break;
                    }
                    googleClient.OnLogin -= userLoginDelegate;
                };

                googleClient.OnLogin += userLoginDelegate;

                await googleClient.LoginAsync();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                //await App.Current.MainPage.DisplayAlert("Google Login", e.Message, "OK");
            }
        }
 public void LoginAsync()
 {
     googleClientManager.OnLogin += OnLoginCompleted;
     googleClientManager.LoginAsync();
 }