예제 #1
0
        async void CheckAuthAndRefresh()
        {
            //this is how we refresh the list items, once we know we're authenticated
            Action refreshList = async() => {
                //fetch gist
                listFetchingActivity.IsRunning = true;
                listFetchingActivity.IsVisible = true;
                try
                {
                    var links = await UserLinksDataStore.GetLinks();

                    urlView.ItemsSource = links;
                }
                catch (KeyNotFoundException ex) {
                    DisplayAlert("You haven't made any links yet", "Please make sure you create a GitHub gist called 'AppyLinks' and create links in the format Title [New Line] Url [New Line]. Leave an empty line between links.", "I'll go do that!", null);
                }
                catch (Exception ex) {
                    DisplayAlert("Error", "Unkown error. Message: " + ex.Message, "OK", null);
                }

                listFetchingActivity.IsRunning = false;
                listFetchingActivity.IsVisible = false;
            };

            //if not authenticated, display authentication overlay first
            var isAuthenticated = await UserLinksDataStore.IsAuthenticated();

            if (!isAuthenticated)
            {
                Navigation.PushModalAsync(new AuthorizationView(() => {
                    Navigation.PopModalAsync();
                    refreshList();
                }));
            }
            else
            {
                refreshList();
            }
        }
예제 #2
0
        public AuthorizationView(Action authorizationComplete)
        {
            InitializeComponent();

            //could not get the XAML <FileImageSource /> working correctly, so falling back to this pattern
            Logo.Source = ImageSource.FromFile("Images/appylinkslogo.png");

            //setup behaviour for authentication via github
            GithubLoginUserAction.Clicked += async(sender, e) => {
                //show that we are waiting for authorization to happen
                AuthenticationInProgressIndicator.IsVisible = true;
                AuthenticationInProgressIndicator.IsRunning = true;
                //prevent user submitting again until we're finished
                GithubLoginUserAction.IsEnabled = false;
                //TODO: username and password inputs and message about how credentials won't be stored
                try {
                    await UserLinksDataStore.Authorize(GithubUsername.Text, GithubPassword.Text);

                    DisplayAlert("Github Authentication", "Sucessfully logged in via github. To revoke access please visit your account settings page on GitHub.com", "OK", null);

                    //notify our owner of completion and let it decide what to do (probably hide this view)
                    if (authorizationComplete != null)
                    {
                        authorizationComplete();
                    }
                } catch (Exception ex) {
                    DisplayAlert("Error", "There was a problem authenticating with github: " + ex.Message, "Dismiss", null);
                    //allow user to try again
                    //show that we are no longer waiting for authorization to happen
                    AuthenticationInProgressIndicator.IsVisible = false;
                    AuthenticationInProgressIndicator.IsRunning = false;
                    //allow user to submit again
                    GithubLoginUserAction.IsEnabled = true;
                }
            };
        }