protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
        {
            Guard.ArgumentNotNull(repositoryHosts, nameof(repositoryHosts));
            Guard.ArgumentNotNull(browser, nameof(browser));

            RepositoryHosts = repositoryHosts;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                                       .IfNullOrEmpty(Resources.UsernameOrEmailValidatorEmpty)
                                       .IfMatch(@"\s", Resources.UsernameOrEmailValidatorSpaces);

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                                .IfNullOrEmpty(Resources.PasswordValidatorEmpty);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncObservable(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);

            Login.ThrownExceptions.Subscribe(ex =>
            {
                if (ex.IsCriticalException())
                {
                    return;
                }

                log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri, UsernameOrEmail), ex);

                if (ex is Octokit.ForbiddenException)
                {
                    Error = new UserError(Resources.LoginFailedForbiddenMessage, ex.Message);
                }
                else
                {
                    Error = new UserError(ex.Message);
                }
            });

            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = new RecoveryCommand(Resources.ForgotPasswordLink, _ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return(RecoveryOptionResult.RetryOperation);
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return(Observable.Return(Unit.Default));
            });
        }
        protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
        {
            RepositoryHosts = repositoryHosts;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                                       .IfNullOrEmpty("Please enter your username or email address")
                                       .IfMatch(@"\s", "Username or email address must not have spaces");

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                                .IfNullOrEmpty("Please enter your password");

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncObservable(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);

            Login.ThrownExceptions.Subscribe(ex =>
            {
                if (ex.IsCriticalException())
                {
                    return;
                }

                log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri,
                                       UsernameOrEmail), ex);
                if (ex is Octokit.ForbiddenException)
                {
                    ShowLogInFailedError = true;
                    LoginFailedMessage   = "Make sure to use your password and not a Personal Access token to log in.";
                }
                else
                {
                    ShowConnectingToHostFailed = true;
                }
            });

            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return(Observable.Return(Unit.Default));
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return(Observable.Return(Unit.Default));
            });
        }
Beispiel #3
0
        protected LoginTabViewModel(
            IConnectionManager connectionManager,
            IVisualStudioBrowser browser)
        {
            Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
            Guard.ArgumentNotNull(browser, nameof(browser));

            ConnectionManager = connectionManager;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                                       .IfNullOrEmpty(Resources.UsernameOrEmailValidatorEmpty)
                                       .IfMatch(@"\s", Resources.UsernameOrEmailValidatorSpaces);

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                                .IfNullOrEmpty(Resources.PasswordValidatorEmpty);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateFromTask(LogIn, this.WhenAny(x => x.CanLogin, x => x.Value));
            Login.ThrownExceptions.Subscribe(HandleError);
            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            LoginViaOAuth = ReactiveCommand.CreateFromTask(
                LogInViaOAuth,
                this.WhenAnyValue(x => x.IsLoggingIn, x => !x));
            LoginViaOAuth.ThrownExceptions.Subscribe(HandleError);

            Reset = ReactiveCommand.CreateFromTask(Clear);

            NavigateForgotPassword = new RecoveryCommand(Resources.ForgotPasswordLink, _ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return(RecoveryOptionResult.RetryOperation);
            });

            SignUp = ReactiveCommand.CreateFromObservable(() =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return(Observable.Return(Unit.Default));
            });
        }
        public LoginToGitHubForEnterpriseViewModel(IRepositoryHosts hosts, IVisualStudioBrowser browser) : base(hosts, browser)
        {
            EnterpriseUrlValidator = ReactivePropertyValidator.For(this, x => x.EnterpriseUrl)
                                     .IfNullOrEmpty("Please enter an Enterprise URL")
                                     .IfNotUri("Please enter a valid Enterprise URL")
                                     .IfGitHubDotComHost("Not an Enterprise server. Please enter an Enterprise URL");

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                x => x.EnterpriseUrlValidator.ValidationResult.IsValid,
                (x, y, z) => x.Value && y.Value && z.Value)
                       .ToProperty(this, x => x.CanLogin);

            NavigateLearnMore = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.LearnMore);
                return(Observable.Return(Unit.Default));
            });
        }
Beispiel #5
0
        public LoginToGitHubForEnterpriseViewModel(
            IConnectionManager connectionManager,
            IEnterpriseCapabilitiesService enterpriseCapabilities,
            IVisualStudioBrowser browser,
            IScheduler scheduler)
            : base(connectionManager, browser)
        {
            Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
            Guard.ArgumentNotNull(enterpriseCapabilities, nameof(enterpriseCapabilities));
            Guard.ArgumentNotNull(browser, nameof(browser));

            this.enterpriseCapabilities = enterpriseCapabilities;

            EnterpriseUrlValidator = ReactivePropertyValidator.For(this, x => x.EnterpriseUrl)
                                     .IfNullOrEmpty(Resources.EnterpriseUrlValidatorEmpty)
                                     .IfNotUri(Resources.EnterpriseUrlValidatorInvalid)
                                     .IfGitHubDotComHost(Resources.EnterpriseUrlValidatorNotAGitHubHost);

            canLogin = this.WhenAnyValue(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                x => x.SupportedLoginMethods,
                (x, y, z) => (x || (z & EnterpriseLoginMethods.Token) != 0) && y)
                       .ToProperty(this, x => x.CanLogin);

            canSsoLogin = this.WhenAnyValue(
                x => x.EnterpriseUrlValidator.ValidationResult.IsValid)
                          .ToProperty(this, x => x.CanLogin);

            this.WhenAnyValue(x => x.EnterpriseUrl, x => x.EnterpriseUrlValidator.ValidationResult)
            .Throttle(TimeSpan.FromMilliseconds(500), scheduler)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => EnterpriseUrlChanged(x.Item1, x.Item2?.IsValid ?? false));

            NavigateLearnMore = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.LearnMore);
                return(Observable.Return(Unit.Default));
            });
        }
Beispiel #6
0
        public LoginToGitHubForEnterpriseViewModel(IRepositoryHosts hosts, IVisualStudioBrowser browser) : base(hosts, browser)
        {
            Guard.ArgumentNotNull(hosts, nameof(hosts));
            Guard.ArgumentNotNull(browser, nameof(browser));

            EnterpriseUrlValidator = ReactivePropertyValidator.For(this, x => x.EnterpriseUrl)
                                     .IfNullOrEmpty(Resources.EnterpriseUrlValidatorEmpty)
                                     .IfNotUri(Resources.EnterpriseUrlValidatorInvalid)
                                     .IfGitHubDotComHost(Resources.EnterpriseUrlValidatorNotAGitHubHost);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                x => x.EnterpriseUrlValidator.ValidationResult.IsValid,
                (x, y, z) => x.Value && y.Value && z.Value)
                       .ToProperty(this, x => x.CanLogin);

            NavigateLearnMore = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.LearnMore);
                return(Observable.Return(Unit.Default));
            });
        }