Esempio n. 1
0
        protected IObservable <AuthenticationResult> LogInToHost(HostAddress hostAddress)
        {
            Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));

            return(Observable.Defer(() =>
            {
                return hostAddress != null ?
                RepositoryHosts.LogIn(hostAddress, UsernameOrEmail, Password)
                    : Observable.Return(AuthenticationResult.CredentialFailure);
            })
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .Do(authResult => {
                switch (authResult)
                {
                case AuthenticationResult.CredentialFailure:
                    Error = new UserError(
                        Resources.LoginFailedText,
                        Resources.LoginFailedMessage,
                        new[] { NavigateForgotPassword });
                    break;

                case AuthenticationResult.VerificationFailure:
                    break;

                case AuthenticationResult.EnterpriseServerNotFound:
                    Error = new UserError(Resources.CouldNotConnectToGitHub);
                    break;
                }
            })
                   .SelectMany(authResult =>
            {
                switch (authResult)
                {
                case AuthenticationResult.CredentialFailure:
                case AuthenticationResult.EnterpriseServerNotFound:
                case AuthenticationResult.VerificationFailure:
                    Password = "";
                    return Observable.FromAsync(PasswordValidator.ResetAsync)
                    .Select(_ => AuthenticationResult.CredentialFailure);

                case AuthenticationResult.Success:
                    return Reset.ExecuteAsync()
                    .ContinueAfter(() => Observable.Return(AuthenticationResult.Success));

                default:
                    return Observable.Throw <AuthenticationResult>(
                        new InvalidOperationException("Unknown EnterpriseLoginResult: " + authResult));
                }
            }));
        }
Esempio n. 2
0
        protected IObservable <AuthenticationResult> LogInToHost(HostAddress hostAddress)
        {
            return(Observable.Defer(() =>
            {
                ShowLogInFailedError = false;
                ShowConnectingToHostFailed = false;

                return hostAddress != null ?
                RepositoryHosts.LogIn(hostAddress, UsernameOrEmail, Password)
                    : Observable.Return(AuthenticationResult.CredentialFailure);
            })
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .Do(authResult => {
                switch (authResult)
                {
                case AuthenticationResult.CredentialFailure:
                    ShowLogInFailedError = true;
                    break;

                case AuthenticationResult.VerificationFailure:
                    break;

                case AuthenticationResult.EnterpriseServerNotFound:
                    ShowConnectingToHostFailed = true;
                    break;
                }
            })
                   .SelectMany(authResult =>
            {
                switch (authResult)
                {
                case AuthenticationResult.CredentialFailure:
                case AuthenticationResult.EnterpriseServerNotFound:
                case AuthenticationResult.VerificationFailure:
                    Password = "";
                    return Observable.FromAsync(PasswordValidator.ResetAsync)
                    .Select(_ => AuthenticationResult.CredentialFailure);

                case AuthenticationResult.Success:
                    return Reset.ExecuteAsync()
                    .ContinueAfter(() => Observable.Return(AuthenticationResult.Success));

                default:
                    return Observable.Throw <AuthenticationResult>(
                        new InvalidOperationException("Unknown EnterpriseLoginResult: " + authResult));
                }
            }));
        }