Ejemplo n.º 1
0
        /// <summary>
        /// Triggered by clicking the login button on LoginPage to
        /// authenticate the author.
        /// </summary>
        public async void OnLogin(object sender, EventArgs e)
        {
            // Show loading indicator
            UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);

            // Author object
            var author = new Author
            {
                Username = authorUsername.Text.ToLower(),
                Password = AppHelper.GeneratePasswordHash(
                    authorPassword.Text
                    )
            };

            IReadOnlyList <Page> pageStack = Application.Current.MainPage.Navigation.NavigationStack;

            // Authenticate author
            await AuthenticateAuthor(author);

            // Hide loading indicator
            UserDialogs.Instance.HideLoading();

            // Redirect to journals page
            if (!this.errored)
            {
                // Clear the login form
                authorUsername.Text = string.Empty;
                authorPassword.Text = string.Empty;
                authorUsername.Unfocus();
                authorPassword.Unfocus();

                await Navigation.PushAsync(new JournalsPage());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Triggered by clicking the register button on RegisterPage to
        /// create new authors
        /// </summary>
        public async void OnRegister(object sender, EventArgs e)
        {
            if (newAuthorFirstName.Text != null &&
                newAuthorLastName.Text != null &&
                newAuthorEmail.Text != null &&
                newAuthorDateOfBirth.Date != null &&
                newAuthorUsername.Text != null &&
                newAuthorPassword.Text != null &&
                newAuthorPassword.Text == newAuthorConfirmPassword.Text)
            {
                // Show loading indicator
                UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);

                // New author object
                var author = new Author
                {
                    FirstName   = newAuthorFirstName.Text,
                    LastName    = newAuthorLastName.Text,
                    Email       = newAuthorEmail.Text,
                    DateOfBirth = newAuthorDateOfBirth.Date,
                    Username    = newAuthorUsername.Text.ToLower(),
                    Password    = AppHelper.GeneratePasswordHash(
                        newAuthorPassword.Text
                        )
                };

                // Register author
                await RegisterAuthor(author);


                // Hide loading indicator
                UserDialogs.Instance.HideLoading();

                // Go back to login page on success
                if (this.errored != true)
                {
                    await Navigation.PopToRootAsync();
                }
            }
            else
            {
                if (newAuthorUsername.Text == null)
                {
                    await DisplayAlert("Error", "Your username can't be empty!", "Try again");
                }
                else if (newAuthorFirstName.Text == null)
                {
                    await DisplayAlert("Error", "Your first name can't be empty!", "Try again");
                }
                else if (newAuthorLastName.Text == null)
                {
                    await DisplayAlert("Error", "Your last name can't be empty!", "Try again");
                }
                else if (newAuthorEmail.Text == null)
                {
                    await DisplayAlert("Error", "Your email address can't be empty!", "Try again");
                }
                else if (newAuthorDateOfBirth.Date == null)
                {
                    await DisplayAlert("Error", "Your date of birth can't be empty!", "Try again");
                }
                else if (newAuthorPassword.Text == null)
                {
                    await DisplayAlert("Error", "Your password can't be empty!", "Try again");
                }
                else if (newAuthorPassword.Text != newAuthorConfirmPassword.Text)
                {
                    await DisplayAlert("Error", "Your passwords don't match!", "Try again");
                }
            }
        }