Beispiel #1
0
        /// <summary>
        ///     Обработка нажатия кнопки регистрации
        /// </summary>
        private void Register_OnClick(object sender, RoutedEventArgs e)
        {
            if (LoginBox.Text.Length >= 20 || LoginBox.Text == "" || LoginBox.Text.Contains(" "))
            {
                WarningText.Text = "Invalid nickname format";
                return;
            }

            if (CheckNickUnicall())
            {
                WarningText.Text = "Nickname is busy";
                return;
            }

            if (PasswordBox1.Password != PasswordBox2.Password)
            {
                WarningText.Text = "Passwords do not match";
                return;
            }

            var httpWebRequest =
                (HttpWebRequest)WebRequest.Create(
                    $"http://{ConfigManager.Config.IP}:{ConfigManager.Config.Port}/api/Login");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            var regData = new RegData {
                Username = LoginBox.Text, Password = PasswordBox1.Password
            };
            var json         = JsonConvert.SerializeObject(regData);
            var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());

            streamWriter.Write(json);
            streamWriter.Close();

            string result;

            try
            {
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                var streamReader = new StreamReader(httpResponse.GetResponseStream());
                result = streamReader.ReadToEnd();
            }
            catch (Exception)
            {
                WarningText.Text = "Unauthorized";
                return;
            }

            var temp = JsonConvert.DeserializeAnonymousType(result, new Config {
                Token = ""
            });

            ConfigManager.Config.Token = temp.Token;

            ConfigManager.Config.RegData = regData;
            WarningText.Text             = "Success!";
            ConfigManager.WriteConfig();
            var nvMain = (NavigationView)Frame.FindName("nvMain");

            nvMain.SelectedItem = nvMain.MenuItems.OfType <NavigationViewItem>().Last();
        }
 /// <summary>
 ///     Обработчик сохранения настроек в файл
 /// </summary>
 private void Page_LosingFocus(UIElement sender, LosingFocusEventArgs args)
 {
     ConfigManager.WriteConfig();
 }
Beispiel #3
0
        /// <summary>
        ///     Обработка нажатия кнопки регистрации
        /// </summary>
        private void Register_OnClick(object sender, RoutedEventArgs e)
        {
            if (LoginBox.Text.Length >= 20 || LoginBox.Text == "" || LoginBox.Text.Contains(" "))
            {
                WarningText.Text = "Нам нужны ваши ДОКУМЕНТЫ.";
                return;
            }

            if (CheckNickUnicall())
            {
                WarningText.Text = "Нам нужны ВАШИ документы.";
                return;
            }

            if (PasswordBox1.Password != PasswordBox2.Password)
            {
                WarningText.Text = "Контрольные суммы кодов не совпали";
                return;
            }

            var httpWebRequest =
                (HttpWebRequest)WebRequest.Create(
                    $"http://{ConfigManager.Config.IP}:{ConfigManager.Config.Port}/api/Login");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            var regData = new RegData {
                Username = LoginBox.Text, Password = PasswordBox1.Password
            };
            var json         = JsonConvert.SerializeObject(regData);
            var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());

            streamWriter.Write(json);
            streamWriter.Close();

            string result;

            try
            {
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                var streamReader = new StreamReader(httpResponse.GetResponseStream());
                result = streamReader.ReadToEnd();
            }
            catch (Exception)
            {
                WarningText.Text = "Шпион!";
                return;
            }

            var temp = JsonConvert.DeserializeAnonymousType(result, new Config {
                Token = ""
            });

            ConfigManager.Config.Token = temp.Token;

            ConfigManager.Config.RegData = regData;
            WarningText.Text             = "Соединение успешно.";
            ConfigManager.WriteConfig();
            var nvMain = (NavigationView)Frame.FindName("nvMain");

            nvMain.SelectedItem = nvMain.MenuItems.OfType <NavigationViewItem>().Last();
        }