示例#1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var scopes = string.Join(", ", OctokitClientFactory.Scopes);

            DescriptionLabel.Text = string.Format("The provided Personal Access Token must allow access to the following scopes: {0}", scopes);

            TokenText.EditingChanged += (sender, args) => ViewModel.Token = TokenText.Text;
            ViewModel.WhenAnyValue(x => x.Token).Subscribe(x => TokenText.Text = x);

            LoginButton.TouchUpInside += (sender, args) => ViewModel.LoginCommand.ExecuteIfCan();
            ViewModel.LoginCommand.CanExecuteObservable.Subscribe(x => LoginButton.Enabled = x);

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

            LoginButton.SetBackgroundImage(Images.Buttons.GreyButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

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

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

            this.ViewportObservable().Subscribe(x => ScrollView.Frame = x);

            ImageHeight.Constant = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 192 : 86;
        }
示例#2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ViewModel.WhenAnyValue(x => x.Username).Subscribe(x => User.Text     = x);
            ViewModel.WhenAnyValue(x => x.Password).Subscribe(x => Password.Text = x);
            ViewModel.WhenAnyValue(x => x.Domain).Subscribe(x => Domain.Text     = x);

            User.EditingChanged += (sender, args) =>
                                   ViewModel.Username = User.Text;
            Password.EditingChanged += (sender, args) =>
                                       ViewModel.Password = Password.Text;
            Domain.EditingChanged += (sender, args) =>
                                     ViewModel.Domain = Domain.Text;

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

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

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

            LoginButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
            LoginButton.SetBackgroundImage(Images.GreyButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

            //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);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var scopes = string.Join(", ", OctokitClientFactory.Scopes);

            DescriptionLabel.Text      = string.Format("The provided Personal Access Token must allow access to the following scopes: {0}", scopes);
            DescriptionLabel.TextColor = ComponentTextColor;

            TokenText.AttributedPlaceholder = new Foundation.NSAttributedString("Token", foregroundColor: ComponentPlaceholderColor);
            TokenText.BackgroundColor       = ComponentBackgroundColor;
            TokenText.TextColor             = ComponentTextColor;

            DomainText.AttributedPlaceholder = new Foundation.NSAttributedString("Domain", foregroundColor: ComponentPlaceholderColor);
            DomainText.BackgroundColor       = ComponentBackgroundColor;
            DomainText.TextColor             = ComponentTextColor;

            View.BackgroundColor = BackgroundColor;
            LogoImageView.Image  = Images.Logos.Enterprise;

            LoginButton.SetTitleColor(ComponentTextColor, UIControlState.Normal);
            LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

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

            this.ViewportObservable().Subscribe(x => ScrollView.Frame = x);

            ImageHeight.Constant = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 192 : 86;

            OnActivation(d => {
                d(TokenText.GetChangedObservable().Subscribe(x => ViewModel.Token    = x));
                d(ViewModel.WhenAnyValue(x => x.Token).Subscribe(x => TokenText.Text = x));

                d(DomainText.GetChangedObservable().Subscribe(x => ViewModel.Domain    = x));
                d(ViewModel.WhenAnyValue(x => x.Domain).Subscribe(x => DomainText.Text = x));

                d(LoginButton.GetClickedObservable().InvokeCommand(ViewModel.LoginCommand));
                d(ViewModel.LoginCommand.CanExecuteObservable.Subscribe(x => LoginButton.Enabled = x));

                DomainText.ShouldReturn = delegate {
                    TokenText.BecomeFirstResponder();
                    return(true);
                };

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

                d(Disposable.Create(() => {
                    DomainText.ShouldReturn = null;
                    TokenText.ShouldReturn  = null;
                }));
            });
        }
示例#4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Login";


            View.BackgroundColor = EnterpriseBackgroundColor;
            Logo.Image           = Images.Logos.EnterpriseMascot;

            LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);
            LoginButton.Enabled = true;

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

            var attributes = new UIStringAttributes {
                ForegroundColor = UIColor.LightGray,
            };

            Domain.AttributedPlaceholder   = new NSAttributedString("Domain", attributes);
            User.AttributedPlaceholder     = new NSAttributedString("Username", attributes);
            Password.AttributedPlaceholder = new NSAttributedString("Password", attributes);

            foreach (var i in new [] { Domain, User, Password })
            {
                i.Layer.BorderColor  = UIColor.Black.CGColor;
                i.Layer.BorderWidth  = 1;
                i.Layer.CornerRadius = 4;
            }

            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);
            };

            OnActivation(d =>
            {
                d(User.GetChangedObservable().Subscribe(x => ViewModel.Username     = x));
                d(Password.GetChangedObservable().Subscribe(x => ViewModel.Password = x));
                d(Domain.GetChangedObservable().Subscribe(x => ViewModel.Domain     = x));
                d(LoginButton.GetClickedObservable().BindCommand(ViewModel.LoginCommand));
                d(ViewModel.Bind(x => x.IsLoggingIn).SubscribeStatus("Logging in..."));
                d(ViewModel.LoginCommand.ThrownExceptions.Subscribe(HandleLoginException));
            });
        }
示例#5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Username.BackgroundColor       = ComponentBackgroundColor;
            Username.AttributedPlaceholder = new Foundation.NSAttributedString("Username", foregroundColor: ComponentPlaceholderColor);
            Username.TextColor             = ComponentTextColor;
            Username.EditingChanged       += (sender, args) =>
                                             ViewModel.Username = Username.Text;
            ViewModel.WhenAnyValue(x => x.Username).Subscribe(x => Username.Text = x);

            Password.BackgroundColor       = ComponentBackgroundColor;
            Password.AttributedPlaceholder = new Foundation.NSAttributedString("Password", foregroundColor: ComponentPlaceholderColor);
            Password.TextColor             = ComponentTextColor;
            Password.EditingChanged       += (sender, args) =>
                                             ViewModel.Password = Password.Text;
            ViewModel.WhenAnyValue(x => x.Password).Subscribe(x => Password.Text = x);

            Domain.BackgroundColor       = ComponentBackgroundColor;
            Domain.AttributedPlaceholder = new Foundation.NSAttributedString("Domain", foregroundColor: ComponentPlaceholderColor);
            Domain.TextColor             = ComponentTextColor;
            Domain.EditingChanged       += (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 = BackgroundColor;
            LogoImageView.Image  = Images.Logos.Enterprise;

            LoginButton.SetTitleColor(ComponentTextColor, UIControlState.Normal);
            LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

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

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

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

            this.ViewportObservable().Subscribe(x => ScrollView.Frame = x);

            ImageHeight.Constant = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 192 : 86;
        }
示例#6
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            pathToDatabase = Path.Combine(documentsFolder, "users_db.db");
            int count = 0;

            using (var connection = new SQLiteConnection(pathToDatabase))
            {
                var query = connection.Table <LocalUser>().Where(us => us.LoggedIn == true);
                count = query.Count();
            }
            if (count != 0)
            {
                LoginButton.SendActionForControlEvents(UIControlEvent.TouchUpInside);
            }
            else
            {
                LoginToFaceBook();
            }
        }
示例#7
0
        public override void ViewDidLoad()
        {
            var set = this.CreateBindingSet <AddAccountView, AddAccountViewModel>();

            set.Bind(User).To(x => x.Username);
            set.Bind(Password).To(x => x.Password);
            set.Bind(Domain).To(x => x.Domain);
            set.Bind(LoginButton).To(x => x.LoginCommand);
            set.Apply();

            base.ViewDidLoad();

            ViewModel.Bind(x => x.IsLoggingIn, x =>
            {
                if (x)
                {
                    _hud.Show("Logging in...");
                }
                else
                {
                    _hud.Hide();
                }
            });

            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);
        }
示例#8
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);
        }
示例#9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Username.BackgroundColor       = ComponentBackgroundColor;
            Username.AttributedPlaceholder = new Foundation.NSAttributedString("Username", foregroundColor: ComponentPlaceholderColor);
            Username.TextColor             = ComponentTextColor;

            Password.BackgroundColor       = ComponentBackgroundColor;
            Password.AttributedPlaceholder = new Foundation.NSAttributedString("Password", foregroundColor: ComponentPlaceholderColor);
            Password.TextColor             = ComponentTextColor;

            Domain.BackgroundColor       = ComponentBackgroundColor;
            Domain.AttributedPlaceholder = new Foundation.NSAttributedString("Domain", foregroundColor: ComponentPlaceholderColor);
            Domain.TextColor             = ComponentTextColor;

            View.BackgroundColor = BackgroundColor;
            LogoImageView.Image  = Images.Logos.Enterprise;

            LoginButton.SetTitleColor(ComponentTextColor, UIControlState.Normal);
            LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

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

            this.ViewportObservable().Subscribe(x => ScrollView.Frame = x);

            ImageHeight.Constant = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 192 : 86;

            OnActivation(d => {
                d(Username.GetChangedObservable().Subscribe(x => ViewModel.Username         = x));
                d(this.WhenAnyValue(x => x.ViewModel.Username).Subscribe(x => Username.Text = x));
                d(Password.GetChangedObservable().Subscribe(x => ViewModel.Password         = x));
                d(this.WhenAnyValue(x => x.ViewModel.Password).Subscribe(x => Password.Text = x));
                d(Domain.GetChangedObservable().Subscribe(x => ViewModel.Domain             = x));
                d(this.WhenAnyValue(x => x.ViewModel.Domain).Subscribe(x => Domain.Text     = x));
                d(LoginButton.GetClickedObservable().InvokeCommand(ViewModel.LoginCommand));
                d(ViewModel.LoginCommand.CanExecuteObservable.Subscribe(x => LoginButton.Enabled = x));

                d(this.WhenAnyValue(x => x.ViewModel.ShowLoginOptionsCommand)
                  .ToBarButtonItem(UIBarButtonSystemItem.Action, x => NavigationItem.RightBarButtonItem = x));

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

                Username.ShouldReturn = delegate {
                    Password.BecomeFirstResponder();
                    return(true);
                };

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

                d(Disposable.Create(() => {
                    Domain.ShouldReturn   = null;
                    Username.ShouldReturn = null;
                    Password.ShouldReturn = null;
                }));
            });
        }
示例#10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var scopes = string.Join(", ", OctokitClientFactory.Scopes);

            DescriptionLabel.Text      = string.Format("The provided Personal Access Token must allow access to the following scopes: {0}", scopes);
            DescriptionLabel.TextColor = ComponentTextColor;

            AuthenticationSelector.TintColor = ComponentTextColor.ColorWithAlpha(0.9f);

            View.BackgroundColor = EnterpriseBackgroundColor;
            Logo.Image           = Images.Logos.EnterpriseMascot;

            LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);
            LoginButton.Enabled = true;

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

            var attributes = new UIStringAttributes {
                ForegroundColor = UIColor.LightGray,
            };

            Domain.AttributedPlaceholder         = new NSAttributedString("Domain", attributes);
            User.AttributedPlaceholder           = new NSAttributedString("Username", attributes);
            Password.AttributedPlaceholder       = new NSAttributedString("Password", attributes);
            TokenTextField.AttributedPlaceholder = new NSAttributedString("Token", attributes);

            foreach (var i in new [] { Domain, User, Password, TokenTextField })
            {
                i.Layer.BorderColor  = UIColor.Black.CGColor;
                i.Layer.BorderWidth  = 1;
                i.Layer.CornerRadius = 4;
            }

            SelectAuthenticationScheme(0);

            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);
            };

            OnActivation(d =>
            {
                d(User.GetChangedObservable()
                  .Subscribe(x => ViewModel.Username = x));

                d(Password.GetChangedObservable()
                  .Subscribe(x => ViewModel.Password = x));

                d(Domain.GetChangedObservable()
                  .Subscribe(x => ViewModel.Domain = x));

                d(TokenTextField.GetChangedObservable()
                  .Subscribe(x => ViewModel.Token = x));

                d(LoginButton.GetClickedObservable()
                  .InvokeReactiveCommand(ViewModel.LoginCommand));

                d(AuthenticationSelector.GetChangedObservable()
                  .Do(x => ViewModel.TokenAuthentication = x == 1)
                  .Subscribe(SelectAuthenticationScheme));

                d(this.WhenAnyObservable(x => x.ViewModel.LoginCommand.CanExecute)
                  .Subscribe(x => LoginButton.Enabled = x));

                d(this.WhenAnyValue(x => x.ViewModel.TokenAuthentication)
                  .Subscribe(x => AuthenticationSelector.SelectedSegment = x ? 1 : 0));
            });
        }
示例#11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Login";

            View.BackgroundColor = EnterpriseBackgroundColor;
            Logo.Image           = Images.StashLogo.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
            Logo.TintColor       = UIColor.FromRGB(239, 239, 244);

            LoginButton.BackgroundColor = UIColor.FromRGB(0x10, 0x40, 0x71);
            LoginButton.Enabled         = true;

            LoginButton.Layer.BorderColor  = UIColor.Black.CGColor;
            LoginButton.Layer.BorderWidth  = 1;
            LoginButton.Layer.CornerRadius = 4;

            var attributes = new UIStringAttributes
            {
                ForegroundColor = UIColor.LightGray
            };

            Domain.AttributedPlaceholder   = new NSAttributedString("Domain", attributes);
            User.AttributedPlaceholder     = new NSAttributedString("Username", attributes);
            Password.AttributedPlaceholder = new NSAttributedString("Password", attributes);

            foreach (var i in new[] { Domain, User, Password })
            {
                i.BackgroundColor    = UIColor.FromRGB(0x10, 0x40, 0x71);
                i.Layer.BorderColor  = UIColor.Black.CGColor;
                i.Layer.BorderWidth  = 1;
                i.Layer.CornerRadius = 4;
            }

            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);
            };

            OnActivation(d =>
            {
                User.GetChangedObservable().Subscribe(x => ViewModel.Username     = x).AddTo(d);
                Password.GetChangedObservable().Subscribe(x => ViewModel.Password = x).AddTo(d);
                Domain.GetChangedObservable().Subscribe(x => ViewModel.Domain     = x).AddTo(d);
                LoginButton.GetClickedObservable().BindCommand(ViewModel.LoginCommand).AddTo(d);
                ViewModel.WhenAnyValue(x => x.IsLoggingIn).SubscribeStatus("Logging in...").AddTo(d);
                ViewModel.LoginCommand.ThrownExceptions.Subscribe(HandleLoginException).AddTo(d);
            });
        }
示例#12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            link_profile.Frame = new CGRect(this.View.Frame.Width / 2 - 150, 206, 300, 60);

            link_profile.TouchUpInside += delegate {
                Console.WriteLine("presing facebook link");

                loginView.SendActionForControlEvents(UIControlEvent.TouchUpInside);
            };

            back_button.TouchUpInside += delegate
            {
                ViewModel.ShowBubbleBoard();
            };

            addBubble_button.TouchUpInside += delegate
            {
                {
                    ViewModel.description = txtfield.Text;

                    ViewModel.AddBubble();
                }
            };

            var screenTap = new UITapGestureRecognizer(() =>
            {
                txtfield.ResignFirstResponder();
            });

            this.View.AddGestureRecognizer(screenTap);

            txtfield.ShouldReturn = (textField) =>
            {
                txtfield.ResignFirstResponder();
                return(true);
            };

            addBubble_button.BackgroundColor = UIColor.FromRGB(75, 171, 229);

            Profile.Notifications.ObserveDidChange((sender, e) => {
                if (e.NewProfile == null)
                {
                    return;
                }
                if (AccessToken.CurrentAccessToken != null)
                {
                    var request = new GraphRequest("/me?fields=first_name,last_name,name,email,picture,birthday,gender", null, AccessToken.CurrentAccessToken.TokenString, null, "GET");
                    request.Start((connection, result, error) =>
                    {
                        // Handle if something went wrong with the request
                        if (error != null)
                        {
                            //showAlert("Error", error.Description);
                            return;
                        }

                        //fbReponseFromSDK facebookSDKLoginItem = new fbReponseFromSDK();
                        // Get your profile name
                        var userInfo = result as NSDictionary;
                        if (userInfo["id"] != null)
                        {
                            //ViewModel.provider_id = userInfo["id"].ToString();

                            //ViewModel.user_login_provider.user_provider_id = userInfo["id"].ToString();

                            Console.WriteLine("id is: " + userInfo["id"].ToString());
                        }
                        if (userInfo["name"] != null)
                        {
                            //ViewModel.user_login_provider.user_provider_name = userInfo["name"].ToString();

                            Console.WriteLine("name is: " + userInfo["name"].ToString());
                        }

                        if (userInfo["first_name"] != null)
                        {
                            //ViewModel.first_name = userInfo["first_name"].ToString();

                            Console.WriteLine("first_name is: " + userInfo["first_name"].ToString());
                        }

                        if (userInfo["last_name"] != null)
                        {
                            //ViewModel.last_name = userInfo["last_name"].ToString();

                            Console.WriteLine("last_name is: " + userInfo["last_name"].ToString());
                        }

                        if (userInfo["email"] != null)
                        {
                            //ViewModel.email = userInfo["email"].ToString();

                            Console.WriteLine("email is: " + userInfo["email"].ToString());
                        }

                        if (userInfo["picture"] != null)
                        {
                            Console.WriteLine("profile image is: " + userInfo["picture"].ToString());
                        }

                        if (userInfo["birthday"] != null)
                        {
                            var formatted = DateTime.Parse(userInfo["birthday"].ToString());
                            //ViewModel.birth_date = formatted.ToString("yyyy-MM-dd");
                            Console.WriteLine("birthday is: " + userInfo["birthday"].ToString());
                        }

                        if (userInfo["gender"] != null)
                        {
                            if (userInfo["gender"].Equals("male"))
                            {
                                //ViewModel.gender = "MALE";
                            }
                            else if (userInfo["gender"].Equals("female"))
                            {
                                //ViewModel.gender = "FEMALE";
                            }
                            Console.WriteLine("gender is: " + userInfo["gender"].ToString());
                        }
                        //(Success) Do what you want next :
                        //doneFacbookLogin();

                        //loginView.LoggedOut();

                        //ViewModel.user_login_provider.provider = "FACEBOOK";

                        //ViewModel.EmailVerification();
                    });
                }

                //nameLabel.Text = e.NewProfile.Name;
            });

            loginView = new LoginButton(new CGRect(0, 0, link_profile.Frame.Width, link_profile.Frame.Height))
            {
                LoginBehavior = LoginBehavior.Browser,
                Permissions   = readPermissions.ToArray()
            };



            var attributes = new UIStringAttributes
            {
                //BackgroundColor = UIColor.FromRGB(75, 171, 229),

                ForegroundColor = UIColor.White,
                Font            = UIFont.FromName("Helvetica-Bold", 17f)
            };
            var titleText = new NSAttributedString("Link Facebook profile", attributes);

            loginView.SetAttributedTitle(titleText, UIControlState.Normal);

            loginView.SetBackgroundImage(null, UIControlState.Normal);



            loginView.BackgroundColor = UIColor.FromRGB(75, 171, 229);
            // Handle actions once the user is logged in
            loginView.Completed += (sender, e) => {
                if (e.Error != null)
                {
                    // Handle if there was an error
                }

                if (e.Result.IsCancelled)
                {
                    // Handle if the user cancelled the login request
                }

                // Handle your successful login
            };

            // Handle actions once the user is logged out
            loginView.LoggedOut += (sender, e) => {
                Profile.CurrentProfile = null;
                // Handle your logout
            };



            // The user image profile is set automatically once is logged in


            // Add views to main view

            Console.WriteLine();

            loginView.Layer.CornerRadius = 20;

            link_profile.BackgroundColor = UIColor.FromRGB(75, 171, 229);

            //link_profile.AddSubview(loginView);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            loginFacebookButton.TouchUpInside += delegate {
                Console.WriteLine("presing facebook link");

                loginView.SendActionForControlEvents(UIControlEvent.TouchUpInside);
            };



            get_helplbl.TextColor = UIColor.FromRGB(112, 112, 112);

            back_button.SetTitleColor(UIColor.FromRGB(75, 171, 229), UIControlState.Normal);

            loginButton.BackgroundColor = UIColor.FromRGB(75, 171, 229);



            signup_lbl.TextColor = UIColor.FromRGB(112, 112, 112);

            passwordText.SecureTextEntry = true;

            Profile.CurrentProfile = null;

            AccessToken.CurrentAccessToken = null;

            NSHttpCookieStorage storage = NSHttpCookieStorage.SharedStorage;

            foreach (NSHttpCookie cookie in storage.Cookies)
            {
                if (cookie.Domain == "facebook.com")
                {
                    storage.DeleteCookie(cookie);
                }
            }


            NSUrlCache.SharedCache.RemoveAllCachedResponses();
            var cookies = NSHttpCookieStorage.SharedStorage.Cookies;

            foreach (var c in cookies)
            {
                NSHttpCookieStorage.SharedStorage.DeleteCookie(c);
            }

            var websiteDataTypes = new NSSet <NSString>(new[]
            {
                //Choose which ones you want to remove
                WKWebsiteDataType.Cookies,
                WKWebsiteDataType.DiskCache,
                WKWebsiteDataType.IndexedDBDatabases,
                WKWebsiteDataType.LocalStorage,
                WKWebsiteDataType.MemoryCache,
                WKWebsiteDataType.OfflineWebApplicationCache,
                WKWebsiteDataType.SessionStorage,
                WKWebsiteDataType.WebSQLDatabases
            });

            WKWebsiteDataStore.DefaultDataStore.FetchDataRecordsOfTypes(websiteDataTypes, (NSArray records) =>
            {
                for (nuint i = 0; i < records.Count; i++)
                {
                    var record = records.GetItem <WKWebsiteDataRecord>(i);

                    WKWebsiteDataStore.DefaultDataStore.RemoveDataOfTypes(record.DataTypes,
                                                                          new[] { record }, () => { Console.Write($"deleted: {record.DisplayName}"); });
                }
            });

            NavigationController.NavigationBarHidden = true;

            this.View.BringSubviewToFront(passwordText);

            this.View.BringSubviewToFront(emailText);

            this.View.BringSubviewToFront(back_button);

            var screenTap = new UITapGestureRecognizer(() =>
            {
                emailText.ResignFirstResponder();
                passwordText.ResignFirstResponder();
            });

            var show_signup = new UITapGestureRecognizer(() =>
            {
                ViewModel.ShowSignUp();
            });

            this.View.AddGestureRecognizer(screenTap);

            this.signup_lbl.AddGestureRecognizer(show_signup);

            this.signup_lbl.UserInteractionEnabled = true;

            back_button.TouchUpInside += (sender, e) => {
                ViewModel.BackIntroduction();
            };

            ViewModel.ForPropertyChange(x => x.ErrorMessage, y =>
            {
                //Debug.WriteLine("PORPOISE LOGO CHANGED");

                var okAlertController = UIAlertController.Create("Error message", ViewModel.ErrorMessage, UIAlertControllerStyle.Alert);

                //Add Action
                okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

                // Present Alert
                PresentViewController(okAlertController, true, null);
            });



            loginButton.TouchUpInside += (sender, e) => {
                if (!string.IsNullOrEmpty(emailText.Text) && !string.IsNullOrEmpty(passwordText.Text))
                {
                    ViewModel.email = emailText.Text;

                    ViewModel.password = passwordText.Text;

                    ViewModel.Login();
                }

                else if (string.IsNullOrEmpty(emailText.Text))
                {
                    var okAlertController = UIAlertController.Create("Error message", "Please enter email", UIAlertControllerStyle.Alert);

                    //Add Action
                    okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

                    // Present Alert
                    PresentViewController(okAlertController, true, null);
                }

                else if (string.IsNullOrEmpty(passwordText.Text))
                {
                    var okAlertController = UIAlertController.Create("Error message", "Please enter password", UIAlertControllerStyle.Alert);

                    //Add Action
                    okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

                    // Present Alert
                    PresentViewController(okAlertController, true, null);
                }

                //UsingOauth();
            };



            Profile.Notifications.ObserveDidChange((sender, e) => {
                if (e.NewProfile == null)
                {
                    return;
                }
                if (AccessToken.CurrentAccessToken != null)
                {
                    var request = new GraphRequest("/me?fields=first_name,last_name,name,email,picture,birthday,gender", null, AccessToken.CurrentAccessToken.TokenString, null, "GET");
                    request.Start((connection, result, error) =>
                    {
                        // Handle if something went wrong with the request
                        if (error != null)
                        {
                            //showAlert("Error", error.Description);
                            return;
                        }

                        //fbReponseFromSDK facebookSDKLoginItem = new fbReponseFromSDK();
                        // Get your profile name
                        var userInfo = result as NSDictionary;
                        if (userInfo["id"] != null)
                        {
                            ViewModel.provider_id = userInfo["id"].ToString();

                            ViewModel.user_login_provider.user_provider_id = userInfo["id"].ToString();

                            Console.WriteLine("id is: " + userInfo["id"].ToString());
                        }
                        if (userInfo["name"] != null)
                        {
                            ViewModel.user_login_provider.user_provider_name = userInfo["name"].ToString();

                            Console.WriteLine("name is: " + userInfo["name"].ToString());
                        }

                        if (userInfo["first_name"] != null)
                        {
                            ViewModel.first_name = userInfo["first_name"].ToString();

                            Console.WriteLine("first_name is: " + userInfo["first_name"].ToString());
                        }

                        if (userInfo["last_name"] != null)
                        {
                            ViewModel.last_name = userInfo["last_name"].ToString();

                            Console.WriteLine("last_name is: " + userInfo["last_name"].ToString());
                        }

                        if (userInfo["email"] != null)
                        {
                            ViewModel.email = userInfo["email"].ToString();

                            Console.WriteLine("email is: " + userInfo["email"].ToString());
                        }

                        if (userInfo["picture"] != null)
                        {
                            Console.WriteLine("profile image is: " + userInfo["picture"].ToString());
                        }

                        if (userInfo["birthday"] != null)
                        {
                            var formatted        = DateTime.Parse(userInfo["birthday"].ToString());
                            ViewModel.birth_date = formatted.ToString("yyyy-MM-dd");
                            Console.WriteLine("birthday is: " + userInfo["birthday"].ToString());
                        }

                        if (userInfo["gender"] != null)
                        {
                            if (userInfo["gender"].Equals("male"))
                            {
                                ViewModel.gender = "MALE";
                            }
                            else if (userInfo["gender"].Equals("female"))
                            {
                                ViewModel.gender = "FEMALE";
                            }
                            Console.WriteLine("gender is: " + userInfo["gender"].ToString());
                        }
                        //(Success) Do what you want next :
                        //doneFacbookLogin();

                        //loginView.LoggedOut();

                        ViewModel.user_login_provider.provider = "FACEBOOK";

                        ViewModel.EmailVerification();
                    });
                }

                nameLabel.Text = e.NewProfile.Name;
            });

            // Set the Read and Publish permissions you want to get
            loginView = new LoginButton(new CGRect(0, 0, loginFacebookButton.Frame.Width, loginFacebookButton.Frame.Height))
            {
                //LoginBehavior = LoginBehavior.,
                Permissions = readPermissions.ToArray()
            };



            var attributes = new UIStringAttributes
            {
                BackgroundColor = UIColor.FromRGB(75, 171, 229),

                ForegroundColor = UIColor.White,
                Font            = UIFont.FromName("System Semibold", 17f)
            };
            var titleText = new NSAttributedString("Log In With Facebook", attributes);

            loginView.SetAttributedTitle(titleText, UIControlState.Normal);

            loginView.SetBackgroundImage(null, UIControlState.Normal);

            loginView.BackgroundColor = UIColor.FromRGB(75, 171, 229);
            // Handle actions once the user is logged in
            loginView.Completed += (sender, e) => {
                if (e.Error != null)
                {
                    // Handle if there was an error
                }

                if (e.Result.IsCancelled)
                {
                    // Handle if the user cancelled the login request
                }

                // Handle your successful login
            };

            // Handle actions once the user is logged out
            loginView.LoggedOut += (sender, e) => {
                Profile.CurrentProfile = null;
                // Handle your logout
            };

            // The user image profile is set automatically once is logged in
            pictureView = new ProfilePictureView(new CGRect(50, 50, 220, 220));

            // Create the label that will hold user's facebook name
            nameLabel = new UILabel(new RectangleF(20, 319, 280, 21))
            {
                TextAlignment   = UITextAlignment.Center,
                BackgroundColor = UIColor.Clear
            };

            // Add views to main view

            Console.WriteLine();

            loginFacebookButton.BackgroundColor = UIColor.FromRGB(75, 171, 229);

            //loginFacebookButton.AddSubview(loginView);
        }