private async Task PromptForTwoFactor() { var result = await _alertDialogFactory.PromptTextBox("Two Factor Authentication", "This account requires a two factor authentication code", string.Empty, "Ok"); TwoFactor = result; LoginCommand.ExecuteIfCan(); }
public LoginViewModel(ILoginService loginFactory, IAccountsService accountsService, IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogService) { _loginFactory = loginFactory; Title = "Login"; GoToOldLoginWaysCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.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) { alertDialogService.Show("Logging in..."); } else { alertDialogService.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 => Dismiss()); }
public override void ViewDidLoad() { base.ViewDidLoad(); ViewModel.LoginCommand.IsExecuting.Skip(1).Subscribe(x => { if (x) { _alertDialogService.Show("Logging in..."); } else { _alertDialogService.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.EditingChanged += (sender, args) => ViewModel.Username = User.Text; ViewModel.WhenAnyValue(x => x.Username).Subscribe(x => User.Text = x); Password.EditingChanged += (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(); ViewModel.LoginCommand.CanExecuteObservable.Subscribe(x => LoginButton.Enabled = x); 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 CGSize(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 CGSize(View.Frame.Width, LoginButton.Frame.Bottom + 10f); }