Beispiel #1
0
        async void ForgotPassword_Clicked(object sender, System.EventArgs e)
        {
            if (Email_Entry.Text == null || Email_Entry.Text == "")
            {             //if entry box was not touched (null) or is touched but empty ("")
                await DisplayAlert("Error: Email", "Please enter an email", "OK");

                return;
            }

            //ask user before sending email
            var answer = await DisplayAlert("Forgot Password?", "Would you like us to send your password to the email provided?", "Yes", "No");

            if (answer == false) //user changed their mind
            {
                return;
            }

            //create the item we want to send
            var item = new ForgotPasswordItem();

            item.Email = Email_Entry.Text;

            sts.send(uri, item, async() =>
            {
                await DisplayAlert("Email Sent", sts.responseItem.Response, "OK");
            });
        }
Beispiel #2
0
        async void ForgotPassword_Clicked(object sender, System.EventArgs e)
        {
            if (Email_Entry.Text == null || Email_Entry.Text == "")
            {             //if entry box was not touched (null) or is touched but empty ("")
                await DisplayAlert("Error: Email", "Please enter an email", "OK");

                return;
            }

            //ask user before sending email
            var answer = await DisplayAlert("Forgot Password?", "Would you like us to send your password to the email provided?", "Yes", "No");

            if (answer == false) //user changed their mind
            {
                return;
            }

            //create the item we want to send
            var item = new ForgotPasswordItem();

            item.Email = Email_Entry.Text;

            //set ip address to connect to
            var uri = new Uri("http://54.193.30.236/index.py");

            //serialize object and make it ready for sending over the internet
            var json    = JsonConvert.SerializeObject(item);
            var content = new StringContent(json, Encoding.UTF8, "application/json");             //StringContent contains http headers

            //wait for response, then handle it
            var response = await App.client.PostAsync(uri, content);             //post

            if (response.IsSuccessStatusCode)
            {             //success
                //get our JSON response and convert it to a ResponseItem object
                ResponseItem resItem = new ResponseItem();
                try
                {
                    resItem = JsonConvert.DeserializeObject <ResponseItem>(await response.Content.ReadAsStringAsync());
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Unexpected Error", ex.Message, "OK");
                }

                //if no errors, do something
                if (resItem.Success)
                {
                    //todo:alert successful?
                    testLabel.Text = resItem.Success.ToString();
                }
                else //else, display error
                {
                    await DisplayAlert("Error", resItem.Response, "OK");
                }
            }
            else
            {             //error
                await DisplayAlert("Unexpected Error", response.ToString(), "OK");

                return;
            }
        }