Exemplo n.º 1
0
        public void HttpRequest(string userName, string password)
        {
            Task.Run(() =>
            {
                string postData    = "un=" + userName + "&pw=" + password;
                string method      = "POST";
                string phpFileName = "login.php";

                string jsonStr = "";
                string error   = "";
                try
                {
                    jsonStr = WebReq.WebRq(postData, method, phpFileName, "");
                }
                catch (System.Exception e)
                {
                    error = e.ToString();
                    Task.Run(() =>
                    {
                        InfoBarAsync("", error);
                        errorMessage   = error;
                        loadingLabelOn = false;
                    });
                }

                LogInObject logInUserObject = JsonConvert.DeserializeObject <LogInObject>(jsonStr);


                if (logInUserObject.success == 1)
                {
                    Dispatcher.Invoke(() =>
                    {
                        LoggedInWindow mainLogInWindow = new LoggedInWindow(logInUserObject);
                        mainLogInWindow.Show();
                        this.Close();
                    });
                }
                else if (logInUserObject.success != 1)
                {
                    Task.Run(() =>
                    {
                        InfoBarAsync("", logInUserObject.msg);
                        loadingLabelOn = false;
                    });
                }
            });
        }
Exemplo n.º 2
0
        private void ButtonRegister_Click(object sender, RoutedEventArgs e)
        {
            userName       = TextBoxUserName.Text;
            password       = PasswordBox.Password;
            reTypePassword = PasswordBoxRetype.Password;
            eMail          = TextBoxEmail.Text;
            reTypeEMail    = TextBoxEmailRetype.Text;

            if (showRegistrationFields == false)
            {
                showRegistrationFields = true;
                ShowRegistration();
            }
            else
            {
                if (UserInputValidation.InputValidator(userName, false).ValidInput)
                {
                    Task.Run(() =>
                    {
                        string postData    = "un=" + userName + "&pw=" + password + "&email=" + eMail;
                        string method      = "POST";
                        string phpFileName = "regUser.php";
                        //WebReq.WebRq(postData, method, phpFileName);
                        string jsonStr = "";
                        string error   = "";

                        if (eMail == reTypeEMail && password == reTypePassword)
                        {
                            try
                            {
                                jsonStr = WebReq.WebRq(postData, method, phpFileName, "");
                            }
                            catch (System.Exception err)
                            {
                                error = err.ToString();
                                Task.Run(() =>
                                {
                                    InfoBarAsync("", error);
                                    errorMessage   = error;
                                    loadingLabelOn = false;
                                });
                            }

                            LogInObject logInUserObject = JsonConvert.DeserializeObject <LogInObject>(jsonStr);


                            if (logInUserObject.success == 1)
                            {
                                Dispatcher.Invoke(() =>
                                {
                                    LoggedInWindow mainLogInWindow = new LoggedInWindow(logInUserObject);
                                    mainLogInWindow.Show();
                                    this.Close();
                                });
                            }
                            else if (logInUserObject.success != 1)
                            {
                                Task.Run(() =>
                                {
                                    InfoBarAsync("", logInUserObject.msg);
                                    loadingLabelOn = false;
                                });
                            }
                        }
                        else
                        {
                            if (eMail != reTypeEMail)
                            {
                                InfoBarAsync("", "E-mails do not match.");
                                errorMessage = "E-mails do not match.";
                            }
                            else
                            {
                                InfoBarAsync("", "Passwords do not match.");
                                errorMessage = "Passwords do not match.";
                            }
                        }
                    });
                }
            }
        }