private void RegistrationAndAuthorizationWindow_Closing(object sender, CancelEventArgs cancelEventArgs)
 {
     if (!_whetherToCreate)
     {
         return;
     }
     _loading.Close();
     new MainWindow(ConnectionSocket, _ai).Show();
 }
        private void signInButton_Click(object sender, RoutedEventArgs e)
        {
            if (LoginTextBox.Text == "" || PasswordPasswordBox.Password == "")
            {
                return;
            }
            _loading = new Loading(this);
            _loading.Show();

            ConnectionSocket = Functions.ReturnNewSocket(ConnectionSocket);
            Functions.SerializeAndSend(new Authorization(LoginTextBox.Text, PasswordPasswordBox.Password), ConnectionSocket);

            object obj;

            {
                byte[] byteBuffer = new byte[1024];
                if (ConnectionSocket.Receive(byteBuffer) == 0)
                {
                    MessageBox.Show("Получено 0 байт");
                }
                obj = Functions.Deserialize(byteBuffer);
            }
            if (!(obj is AccountInformation))
            {
                return;
            }
            AccountInformation accountInf = obj as AccountInformation;

            if (accountInf.IsNull)
            {
                MessageBox.Show("Ошибка в логине или пароле!", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
                _loading.Close();
                LoginTextBox.Focus();
            }
            else
            {
                _whetherToCreate = true;
                _ai = accountInf;
                Close();
            }
        }
Esempio n. 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //registrationButton.IsEnabled = false;
            if (NameTextBox.Text == "" || NameTextBox.Text == "" || emailTextBox.Text == "" || dateDatePicker.SelectedDate.Value == DateTime.Now || passwordPasswordBox.Password == "" || repeatPasswordPasswordBox.Password == "")
            {
                MessageBox.Show("Заполните все поля!", "Недочёт", MessageBoxButton.OK, MessageBoxImage.Warning);
                //registrationButton.IsEnabled = true;
                return;
            }
            if (String.CompareOrdinal(passwordPasswordBox.Password, repeatPasswordPasswordBox.Password) != 0)
            {
                passwordPasswordBox.Password = repeatPasswordPasswordBox.Password = string.Empty;
                MessageBox.Show("Введенные Вами пароли не совпадают!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                passwordPasswordBox.Focus();
                //registrationButton.IsEnabled = true;
                return;
            }
            if (manRadioButton.IsChecked == womanRadioButton.IsChecked == true)
            {
                MessageBox.Show("Выберите свой пол!", "Недочёт", MessageBoxButton.OK, MessageBoxImage.Warning);
                //registrationButton.IsEnabled = true;
                return;
            }
            loading.Show();
            try
            {
                socket = Functions.ReturnNewSocket(socket);
                Functions.SerializeAndSend(new UniquenessEmail(emailTextBox.Text), socket);
                {
                    byte[] bytefuffer = new byte[400];
                    if (socket.Receive(bytefuffer) == 0)
                    {
                        return;
                    }
                    else
                    {
                        object obj = Functions.Deserialize(bytefuffer);
                        if (obj is UniquenessEmail)
                        {
                            if ((obj as UniquenessEmail).YesNo)
                            {
                                emailTextBox.Text = string.Empty;
                                MessageBox.Show("Введенный Вами email уже зарегистрирован!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                                emailTextBox.Focus();
                                loading.Close();
                                //registrationButton.IsEnabled = true;
                                return;
                            }
                        }
                    }
                }
                Action sendData = () =>
                {
                    Functions.SerializeAndSend(new AccountInformation(NameTextBox.Text, SurnameTextBox.Text, dateDatePicker.SelectedDate.Value,
                                                                      emailTextBox.Text, manRadioButton.IsChecked.Value,
                                                                      Functions.GetHash(passwordPasswordBox.Password)), socket);
                };
                Action act = () =>
                {
                    byte[] response = new byte[1024];
                    //stream=new MemoryStream();
                    //socket.Send(stream.ToArray());
                    while (true)
                    {
                        try
                        {
                            if (socket.Receive(response) == 0)
                            {
                                MessageBox.Show("Получено ноль байт!");

                                /*registrationButton.Dispatcher.Invoke(new Action(() =>
                                 * {
                                 *  registrationButton.IsEnabled = true;
                                 * }));*/
                                return;
                            }
                            if (Functions.Deserialize(response) is MessageFromServer)
                            {
                                loading.Dispatcher.Invoke(() => { loading.Close(); });
                                MessageBox.Show("Проверьте Вашу электронную почту! На Ваш адрес отправлен код подтвержденния.", "Ответ от сервера");
                                Dispatcher.Invoke(() =>
                                {
                                    Verification verifi = new Verification(this);
                                    verifi.Closing     += (a, r) =>
                                    {
                                        sendData();
                                    };
                                    verifi.ShowDialog();
                                });
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
                        }
                    }
                };
                {
                    SendEmailRegistration message = new SendEmailRegistration
                    {
                        Name    = NameTextBox.Text,
                        Surname = SurnameTextBox.Text,
                        Email   = emailTextBox.Text,
                        Subject = "Подтверждение регистрации"
                    };
                    Code         = Functions.GetRandomCode();
                    message.Body = NameTextBox.Text + ", Вы зарегестрировались в чате!" + Environment.NewLine + Environment.NewLine + "Вот код подтверждения: " + Code;
                    Functions.SerializeAndSend(message, socket);
                }
                act.BeginInvoke(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
            }
            //registrationButton.IsEnabled = true;
        }
        private void signInButton_Click(object sender, RoutedEventArgs e)
        {
            if (LoginTextBox.Text == "" || PasswordPasswordBox.Password == "") return;
            _loading = new Loading(this);
            _loading.Show();

            ConnectionSocket = Functions.ReturnNewSocket(ConnectionSocket);
            Functions.SerializeAndSend(new Authorization(LoginTextBox.Text, PasswordPasswordBox.Password), ConnectionSocket);

            object obj;
            {
                byte[] byteBuffer = new byte[1024];
                if (ConnectionSocket.Receive(byteBuffer) == 0)
                {
                    MessageBox.Show("Получено 0 байт");
                }
                obj = Functions.Deserialize(byteBuffer);
            }
            if (!(obj is AccountInformation)) return;
            AccountInformation accountInf = obj as AccountInformation;
            if(accountInf.IsNull)
            {
                MessageBox.Show("Ошибка в логине или пароле!", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
                _loading.Close();
                LoginTextBox.Focus();
            }
            else
            {
                _whetherToCreate = true;
                _ai = accountInf;
                Close();
            }
        }