Exemplo n.º 1
0
 public void Finished(Google.OpenSource.OAuth2Authentication auth, NSError error)
 {
     InvokeOnMainThread(async delegate {
         try {
             if (error == null)
             {
                 IsAuthenticating = true;
                 var token        = Google.Plus.SignIn.SharedInstance.Authentication.AccessToken;
                 var authManager  = ServiceContainer.Resolve <AuthManager> ();
                 var authRes      = await authManager.AuthenticateWithGoogle(token);
                 // No need to keep the users Google account access around anymore
                 Google.Plus.SignIn.SharedInstance.Disconnect();
                 if (authRes != AuthResult.Success)
                 {
                     var email = Google.Plus.SignIn.SharedInstance.Authentication.UserEmail;
                     AuthErrorAlert.Show(this, email, authRes, AuthErrorAlert.Mode.Login, googleAuth: true);
                 }
                 else
                 {
                     // Start the initial sync for the user
                     ServiceContainer.Resolve <ISyncManager> ().Run(SyncMode.Full);
                 }
             }
             else
             {
                 new UIAlertView("WelcomeGoogleErrorTitle".Tr(), "WelcomeGoogleErrorMessage".Tr(), null, "WelcomeGoogleErrorOk".Tr(), null).Show();
             }
         } catch (InvalidOperationException ex) {
             var log = ServiceContainer.Resolve <ILogger> ();
             log.Info(Tag, ex, "Failed to authenticate (G+) the user.");
         } finally {
             IsAuthenticating = false;
         }
     });
 }
Exemplo n.º 2
0
        public async Task AuthWithGoogleTokenAsync(SignIn signIn, GoogleUser user, Foundation.NSError error)
        {
            try {
                if (error == null)
                {
                    IsAuthenticating = true;

                    var token       = user.Authentication.AccessToken;
                    var authManager = ServiceContainer.Resolve <AuthManager> ();
                    var authRes     = await authManager.SignupWithGoogleAsync(token);

                    // No need to keep the users Google account access around anymore
                    signIn.DisconnectUser();

                    if (authRes != AuthResult.Success)
                    {
                        var email = user.Profile.Email;
                        AuthErrorAlert.Show(this, email, authRes, AuthErrorAlert.Mode.Signup, googleAuth: true);
                    }
                }
                else if (error.Code != -5)     // Cancel error code.
                {
                    new UIAlertView(
                        "WelcomeGoogleErrorTitle".Tr(),
                        "WelcomeGoogleErrorMessage".Tr(),
                        null, "WelcomeGoogleErrorOk".Tr(), null).Show();
                }
            } catch (InvalidOperationException ex) {
                var log = ServiceContainer.Resolve <ILogger> ();
                log.Info(Tag, ex, "Failed to authenticate (G+) the user.");
            } finally {
                IsAuthenticating = false;
            }
        }
Exemplo n.º 3
0
        private async void TryPasswordAuth()
        {
            if (IsAuthenticating)
            {
                return;
            }

            IsAuthenticating = true;

            try {
                var authManager = ServiceContainer.Resolve <AuthManager> ();
                var authRes     = await authManager.AuthenticateAsync(emailTextField.Text, passwordTextField.Text);

                if (authRes != AuthResult.Success)
                {
                    AuthErrorAlert.Show(this, emailTextField.Text, authRes, AuthErrorAlert.Mode.Login);
                }
                else
                {
                    // Start the initial sync for the user
                    ServiceContainer.Resolve <ISyncManager> ().Run(SyncMode.Full);
                }
            } catch (InvalidOperationException ex) {
                var log = ServiceContainer.Resolve <ILogger> ();
                log.Info(Tag, ex, "Failed to authenticate (password) the user.");
            } finally {
                IsAuthenticating = false;
            }
        }
Exemplo n.º 4
0
        public void Finished(Google.OpenSource.OAuth2Authentication auth, NSError error)
        {
            InvokeOnMainThread(async delegate {
                try {
                    if (error == null)
                    {
                        IsAuthenticating = true;

                        var token = Google.Plus.SignIn.SharedInstance.Authentication.AccessToken;

                        var authManager = ServiceContainer.Resolve <AuthManager> ();
                        var authRes     = await authManager.SignupWithGoogle(token);

                        // No need to keep the users Google account access around anymore
                        Google.Plus.SignIn.SharedInstance.Disconnect();

                        if (authRes != AuthResult.Success)
                        {
                            var email = Google.Plus.SignIn.SharedInstance.Authentication.UserEmail;
                            AuthErrorAlert.Show(this, email, authRes, AuthErrorAlert.Mode.Signup, googleAuth: true);
                        }
                    }
                    else
                    {
                        new UIAlertView(
                            "WelcomeGoogleErrorTitle".Tr(),
                            "WelcomeGoogleErrorMessage".Tr(),
                            null, "WelcomeGoogleErrorOk".Tr(), null).Show();
                    }
                } finally {
                    IsAuthenticating = false;
                }
            });
        }
Exemplo n.º 5
0
        public void Finished(string token, bool googleFailed)
        {
            DismissViewController(true, null);
            InvokeOnMainThread(async delegate {
                try {
                    if (!googleFailed)
                    {
                        if (token == null)
                        {
                            return;
                        }
                        IsAuthenticating = true;

                        var authManager = ServiceContainer.Resolve <AuthManager> ();
                        var authRes     = await authManager.SignupWithGoogleAsync(token);

                        if (authRes != AuthResult.Success)
                        {
                            AuthErrorAlert.Show(this, null, authRes, AuthErrorAlert.Mode.Signup, googleAuth: true);
                        }
                    }
                    else
                    {
                        new UIAlertView(
                            "WelcomeGoogleErrorTitle".Tr(),
                            "WelcomeGoogleErrorMessage".Tr(),
                            null, "WelcomeGoogleErrorOk".Tr(), null).Show();
                    }
                } finally {
                    IsAuthenticating = false;
                }
            });
        }
Exemplo n.º 6
0
        private async void TryPasswordAuth()
        {
            // Small UI trick to permit OBM testers
            // interact with the staging API
            if (emailTextField.Text == "staging")
            {
                var isStaging = !ServiceContainer.Resolve <ISettingsStore> ().IsStagingMode;
                ServiceContainer.Resolve <ISettingsStore> ().IsStagingMode = isStaging;
                var msg       = !isStaging ? "You're in Normal Mode" : "You're in Staging Mode";
                var alertView = new UIAlertView("Staging Mode", msg + "\nRestart the app to continue.", null, "Ok");
                alertView.Show();
                return;
            }

            if (IsAuthenticating)
            {
                return;
            }

            IsAuthenticating = true;

            try {
                var authManager = ServiceContainer.Resolve <AuthManager> ();
                var authRes     = await authManager.AuthenticateAsync(emailTextField.Text, passwordTextField.Text);

                if (authRes != AuthResult.Success)
                {
                    AuthErrorAlert.Show(this, emailTextField.Text, authRes, AuthErrorAlert.Mode.Login);
                }
                else
                {
                    // Start the initial sync for the user
                    ServiceContainer.Resolve <ISyncManager> ().Run(SyncMode.Full);
                }
            } catch (InvalidOperationException ex) {
                var log = ServiceContainer.Resolve <ILogger> ();
                log.Info(Tag, ex, "Failed to authenticate (password) the user.");
            } finally {
                IsAuthenticating = false;
            }
        }
Exemplo n.º 7
0
        private async void TryPasswordSignup()
        {
            if (IsAuthenticating)
            {
                return;
            }

            IsAuthenticating = true;

            try {
                var authManager = ServiceContainer.Resolve <AuthManager> ();
                var authRes     = await authManager.SignupAsync(emailTextField.Text, passwordTextField.Text);

                if (authRes != AuthResult.Success)
                {
                    AuthErrorAlert.Show(this, emailTextField.Text, authRes, AuthErrorAlert.Mode.Signup);
                }
            } finally {
                IsAuthenticating = false;
            }
        }
Exemplo n.º 8
0
 public void Finished(string token, bool googleFailed)
 {
     DismissViewController(true, null);
     InvokeOnMainThread(async delegate {
         try {
             if (!googleFailed)
             {
                 if (token == null)
                 {
                     return;
                 }
                 IsAuthenticating = true;
                 var authManager  = ServiceContainer.Resolve <AuthManager> ();
                 var authRes      = await authManager.AuthenticateWithGoogleAsync(token);
                 if (authRes != AuthResult.Success)
                 {
                     AuthErrorAlert.Show(this, null, authRes, AuthErrorAlert.Mode.Login, googleAuth: true);
                 }
                 else
                 {
                     // Start the initial sync for the user
                     ServiceContainer.Resolve <ISyncManager> ().Run(SyncMode.Full);
                 }
             }
             else
             {
                 new UIAlertView("WelcomeGoogleErrorTitle".Tr(), "WelcomeGoogleErrorMessage".Tr(), null, "WelcomeGoogleErrorOk".Tr(), null).Show();
             }
         } catch (InvalidOperationException ex) {
             var log = ServiceContainer.Resolve <ILogger> ();
             log.Info(Tag, ex, "Failed to authenticate (G+) the user.");
         } finally {
             IsAuthenticating = false;
         }
     });
 }