Ejemplo n.º 1
0
        private IObservable <UserError> HandleLoginException(Exception e)
        {
            TwoFactor = null;

            if (e is Octokit.TwoFactorRequiredException)
            {
                _alertDialogService
                .PromptTextBox("Authentication Error",
                               "Please provide the two-factor authentication code for this account.",
                               string.Empty, "Login")
                .ToObservable()
                .Do(x => TwoFactor = x)
                .Select(_ => Unit.Default)
                .InvokeReactiveCommand(LoginCommand);

                return(Observable.Empty <UserError>());
            }

            if (e is Octokit.NotFoundException err)
            {
                return(Observable.Return(
                           new UserError($"The provided domain was incorrect. The host could not be found.")));
            }

            if (e is Octokit.ForbiddenException && TokenAuthentication)
            {
                return(Observable.Return(
                           new UserError("The provided token is invalid! Please try again or " +
                                         "create a new token as this one might have been revoked.")));
            }

            return(Observable.Return(new UserError("Unable to login!", e)));
        }
Ejemplo n.º 2
0
 private void HandleLoginException(Exception e)
 {
     if (e is UnauthorizedException authException && authException.Headers.Contains("X-GitHub-OTP"))
     {
         _alertDialogService
         .PromptTextBox("Authentication Error", "Please provide the two-factor authentication code for this account.", string.Empty, "Login")
         .ToObservable()
         .Do(x => TwoFactor = x)
         .InvokeCommand(LoginCommand);
     }
Ejemplo n.º 3
0
        private async Task Stuff()
        {
            try
            {
                var response = await _alertDialogService.PromptTextBox("Enterprise URL",
                                                                       "Please enter the webpage address for the GitHub Enterprise installation",
                                                                       ViewModel.WebDomain, "Ok");

                ViewModel.WebDomain = response;
                LoadRequest();
            }
            catch (Exception)
            {
                ViewModel.DismissCommand.ExecuteIfCan();
            }
        }
Ejemplo n.º 4
0
        public override void ViewDidLoad()
        {
            Title = "Login";
            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Images.BackButton, UIBarButtonItemStyle.Plain, (s, e) => ViewModel.DismissCommand.ExecuteIfCan());

            base.ViewDidLoad();

            ViewModel.LoginCommand.IsExecuting.Skip(1).Subscribe(x =>
            {
                if (x)
                {
                    _statusIndicatorService.Show("Logging in...");
                }
                else
                {
                    _statusIndicatorService.Hide();
                }
            });

            ViewModel.LoginCommand.ThrownExceptions.Subscribe(x =>
            {
                if (x is LoginService.TwoFactorRequiredException)
                {
                    _alertDialogService.PromptTextBox("Two Factor Authentication",
                                                      "This account requires a two factor authentication code", string.Empty, "Ok")
                    .ContinueWith(t =>
                    {
                        ViewModel.TwoFactor = t.Result;
                        ViewModel.LoginCommand.ExecuteIfCan();
                    }, TaskContinuationOptions.OnlyOnRanToCompletion);
                }
            });

            User.ValueChanged += (sender, args) => ViewModel.Username = User.Text;
            ViewModel.WhenAnyValue(x => x.Username).Subscribe(x => User.Text = x);

            Password.ValueChanged += (sender, args) => ViewModel.Password = Password.Text;
            ViewModel.WhenAnyValue(x => x.Password).Subscribe(x => Password.Text = x);

            Domain.ValueChanged += (sender, args) => ViewModel.Domain = Domain.Text;
            ViewModel.WhenAnyValue(x => x.Domain).Subscribe(x => Domain.Text = x);

            LoginButton.TouchUpInside += (sender, args) => ViewModel.LoginCommand.ExecuteIfCan();



            View.BackgroundColor = UIColor.FromRGB(239, 239, 244);
            Logo.Image           = Images.Logos.GitHub;

            if (ViewModel.IsEnterprise)
            {
                LoginButton.SetTitleColor(UIColor.White, UIControlState.Normal);
                LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);
            }
            else
            {
                LoginButton.SetBackgroundImage(Images.Buttons.GreyButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

                //Hide the domain, slide everything up
                Domain.Hidden = true;
                var f = User.Frame;
                f.Y       -= 39;
                User.Frame = f;

                var p = Password.Frame;
                p.Y           -= 39;
                Password.Frame = p;

                var l = LoginButton.Frame;
                l.Y -= 39;
                LoginButton.Frame = l;
            }

            //Set some generic shadowing
            LoginButton.Layer.ShadowColor   = UIColor.Black.CGColor;
            LoginButton.Layer.ShadowOffset  = new SizeF(0, 1);
            LoginButton.Layer.ShadowOpacity = 0.3f;

            Domain.ShouldReturn = delegate {
                User.BecomeFirstResponder();
                return(true);
            };

            User.ShouldReturn = delegate {
                Password.BecomeFirstResponder();
                return(true);
            };
            Password.ShouldReturn = delegate {
                Password.ResignFirstResponder();
                LoginButton.SendActionForControlEvents(UIControlEvent.TouchUpInside);
                return(true);
            };


            ScrollView.ContentSize = new SizeF(View.Frame.Width, LoginButton.Frame.Bottom + 10f);
        }
Ejemplo n.º 5
0
        public LoginViewModel(ILoginService loginFactory,
                              IAccountsService accountsService,
                              IActionMenuService actionMenuService,
                              IStatusIndicatorService statusIndicatorService,
                              IAlertDialogService alertDialogService)
        {
            _loginFactory = loginFactory;

            Title = "Login";

            GoToOldLoginWaysCommand = ReactiveCommand.Create();
            GoToOldLoginWaysCommand.Subscribe(_ => ShowViewModel(CreateViewModel <AddAccountViewModel>()));

            var loginCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Code).Select(x => !string.IsNullOrEmpty(x)), _ => Login(Code));

            loginCommand.Subscribe(x => accountsService.ActiveAccount = x);
            loginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage()));
            LoginCommand = loginCommand;

            ShowLoginOptionsCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var actionMenu = actionMenuService.Create(Title);
                actionMenu.AddButton("Login via BASIC", GoToOldLoginWaysCommand);
                return(actionMenu.Show());
            });

            LoginCommand.IsExecuting.Skip(1).Subscribe(x =>
            {
                if (x)
                {
                    statusIndicatorService.Show("Logging in...");
                }
                else
                {
                    statusIndicatorService.Hide();
                }
            });

            _loginUrl = this.WhenAnyValue(x => x.WebDomain)
                        .IsNotNull()
                        .Select(x => x.TrimEnd('/'))
                        .Select(x =>
                                string.Format(x + "/login/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                                              ClientId, Uri.EscapeDataString(RedirectUri), Uri.EscapeDataString("user,repo,notifications,gist")))
                        .ToProperty(this, x => x.LoginUrl);

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                if (IsEnterprise && string.IsNullOrEmpty(WebDomain))
                {
                    var response = await alertDialogService.PromptTextBox("Enterprise URL",
                                                                          "Please enter the webpage address for the GitHub Enterprise installation",
                                                                          DefaultWebDomain, "Ok");
                    WebDomain = response;
                }
                else
                {
                    WebDomain = DefaultWebDomain;
                }
            });

            LoadCommand.ThrownExceptions.Take(1).Subscribe(x => DismissCommand.ExecuteIfCan());
        }