示例#1
0
        public TwoFactorDialogViewModel(
            IVisualStudioBrowser browser,
            IDelegatingTwoFactorChallengeHandler twoFactorChallengeHandler)
        {
            Guard.ArgumentNotNull(browser, nameof(browser));
            Guard.ArgumentNotNull(twoFactorChallengeHandler, nameof(twoFactorChallengeHandler));

            Title = Resources.TwoFactorTitle;
            twoFactorChallengeHandler.SetViewModel(this);

            var canVerify = this.WhenAny(
                x => x.AuthenticationCode,
                x => x.IsBusy,
                (code, busy) => !string.IsNullOrEmpty(code.Value) && code.Value.Length == 6 && !busy.Value);

            OkCommand = ReactiveCommand.Create(canVerify);
            Cancel.Subscribe(_ => TwoFactorType = TwoFactorType.None);
            NavigateLearnMore = ReactiveCommand.Create();
            NavigateLearnMore.Subscribe(x => browser.OpenUrl(GitHubUrls.TwoFactorLearnMore));
            //TODO: ShowHelpCommand.Subscribe(x => browser.OpenUrl(twoFactorHelpUri));
            ResendCodeCommand = ReactiveCommand.Create();

            showErrorMessage = this.WhenAny(
                x => x.IsAuthenticationCodeSent,
                x => x.InvalidAuthenticationCode,
                (authSent, invalid) => invalid.Value && !authSent.Value)
                               .ToProperty(this, x => x.ShowErrorMessage);

            description = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                          .Select(type =>
            {
                switch (type)
                {
                case TwoFactorType.Sms:
                    return(Resources.TwoFactorSms);

                case TwoFactorType.AuthenticatorApp:
                    return(Resources.TwoFactorApp);

                case TwoFactorType.Unknown:
                    return(Resources.TwoFactorUnknown);

                default:
                    return(null);
                }
            })
                          .ToProperty(this, x => x.Description);

            isShowing = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                        .Select(factorType => factorType != TwoFactorType.None)
                        .ToProperty(this, x => x.IsShowing);

            isSms = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                    .Select(factorType => factorType == TwoFactorType.Sms)
                    .ToProperty(this, x => x.IsSms);
        }
示例#2
0
        public LoginViewModel(
            ILoginCredentialsViewModel credentials,
            ILogin2FaViewModel twoFactor,
            IDelegatingTwoFactorChallengeHandler twoFactorHandler)
        {
            twoFactorHandler.SetViewModel(twoFactor);

            Content = credentials;
            Done    = credentials.Done;

            twoFactor.WhenAnyValue(x => x.TwoFactorType)
            .Subscribe(x =>
            {
                Content = x == TwoFactorType.None ?
                          (IDialogContentViewModel)credentials :
                          twoFactor;
            });
        }