コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: holtcl/TechWizard
        private async void LoginButton_OnClicked(object sender, EventArgs e)
        {
            var success = await HttpAuthHandler.login(email_entry.Text, password_entry.Text);

            if (success)
            {
                Profile profile = new Profile();
                Application.Current.MainPage = new NavigationPage(profile);
            }
            else
            {
                await DisplayAlert("Oops!", "Invalid username/password combo.", "Ok");
            }

            //       User user = new User (email_entry.text, password_entry.text);
        }
コード例 #2
0
        private async void SignUpButton_OnClicked(object sender, EventArgs e)
        {
            if (!isValidEmail(EmailEnt.Text))
            {
                await DisplayAlert("Error", "Email is not valid.", "OK");

                return;
            }

            //todo: validate zip


            //todo: validate phone


            //todo: validate password


            //todo: validate zip


            User user = new User()
            {
                UserName  = EmailEnt.Text,
                FirstName = FirstNameEnt.Text,
                LastName  = LastNameEnt.Text,
                Address   = Address_ent.Text,
                City      = City_ent.Text,
                State     = state_ent.SelectedItem.ToString(),
                Zip       = Int32.Parse(zip_ent.Text),
                Email     = EmailEnt.Text,
                Phone     = Phone_ent.Text,
                Password  = PasswordEnt.Text
            };


            var json    = JsonConvert.SerializeObject(user);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpClient client = new HttpClient();

            var result = await client.PostAsync(HttpAuthHandler.API_URL + "api/User/", content);

            var loginsuccess = await HttpAuthHandler.login(user.UserName, user.Password);

            if (result.StatusCode == HttpStatusCode.Created && loginsuccess)
            {
                await DisplayAlert("Success", "Your account has been created", "Find a Wizard");

                Profile profile = new Profile();
                Application.Current.MainPage = new NavigationPage(profile);
            }
            else
            {
                await DisplayAlert("Error", result.StatusCode + result.ReasonPhrase, "ok");
            }



            //await Navigation.PushAsync(new Profile());
        }