Ejemplo n.º 1
0
        private async void materialFlatButton1_Click(object sender, EventArgs e)
        {
            ClientSystem clientSystem = new ClientSystem();

            string accName     = regName.Text.ToString();
            string accSurname  = regSurname.Text.ToString();
            string accPassword = regPassword.Text.ToString();

            string accBirth = regBirth.SelectionRange.Start.ToShortDateString().ToString();
            string accLogin = regLogin.Text.ToString();

            if (!regCheck.Checked || string.IsNullOrEmpty(accName) || string.IsNullOrEmpty(accSurname) ||
                string.IsNullOrEmpty(accPassword) || string.IsNullOrEmpty(accBirth) || string.IsNullOrEmpty(accLogin))
            {
                label_status.Text = "Не все поля заполнены или не принято условие соглашения";
            }
            else
            {
                try {
                    label_status.Text = "Отправляем запрос к API";
                    string res = await Task.Run(() => clientSystem.registerAccountAsync(accLogin, accName, accSurname, accBirth, accPassword));

                    ResponceMessage responce = JsonConvert.DeserializeObject <ResponceMessage>(res);
                    if (responce.id != -2)
                    {
                        label_status.Text = "Успешная регистрация";
                        this.Close();
                    }
                    else
                    {
                        label_status.Text = "Логин уже используется";
                    }
                }
                catch (System.Net.WebException)
                {
                    label_status.Text = "Ошибка сервера - невозможно подключиться к API";
                }
            }
        }
Ejemplo n.º 2
0
        private async void authStart_Click(object sender, EventArgs e)
        {
            ClientSystem clientSystem = new ClientSystem();


            string accName     = input_name.Text;
            string accPassword = input_password.Text;

            if (string.IsNullOrEmpty(accName) || string.IsNullOrEmpty(accPassword))
            {
                label_status.Text = "Заполнены не все поля";
            }
            else
            {
                label_status.Text = "Происходит авторизация...";
                try {
                    string responce = await Task.Run(() => clientSystem.authAccount(input_name.Text, input_password.Text));

                    JObject res = JObject.Parse(responce);

                    ResponceMessage responceMessage = new ResponceMessage((int)res["id"], "");

                    if (responceMessage.id == 0)
                    {
                        string MessageResponce = res["message"].ToString();

                        Account parsedAccount = JsonConvert.DeserializeObject <Account>(MessageResponce);


                        if (parsedAccount.accBlocked)
                        {
                            label_status.Text = "Аккаунт заблокирован";
                        }
                        else
                        {
                            Program.clientSystem.AuthorizedAccount = parsedAccount;

                            Profile profile = new Profile();
                            profile.Show();

                            if (input_knowme.Checked)
                            {
                                Properties.Settings.Default.AccLogin    = accName;
                                Properties.Settings.Default.AccPassword = accPassword;

                                Properties.Settings.Default.Save();
                            }
                            Visible = false;
                        }
                    }
                    else
                    {
                        label_status.Text = "Введён неверный логин или пароль";
                    }
                }
                catch (System.Net.WebException)
                {
                    label_status.Text = "Ошибка подключения к серверу";
                }
                catch (Newtonsoft.Json.JsonReaderException)
                {
                    label_status.Text = "Произошла ошибка. Попробуйте ещё раз";
                }
            }

            //Decoding input params
        }