Example #1
0
        private void RegistrationButton_Click(object sender, EventArgs e)
        {
            if (UsernameBox.Text == string.Empty)
            {
                MessageBox.Show("Поле з нік нейм не може залишатися порожнім.");
                return;
            }
            else if (EmailBox.Text == string.Empty)
            {
                MessageBox.Show("Поле з електронним поштою повинно бути заповнене.");
                return;
            }
            else if (PasswordBox.Text == string.Empty)
            {
                MessageBox.Show("Поле з паролем повинно бути заповнене. Вигадайте важкий пароль, адже це захист Вашого аккаунта.");
                return;
            }
            else if (PasswordBox.Text.Length < 8)
            {
                MessageBox.Show("Ваш пароль занадто маленький. Він повинен містити більше 8 символів. Це заради Вашої безпеки.");
                return;
            }
            else
            {
                try
                {
                    var toAddress = new MailAddress(EmailBox.Text, "");
                }
                catch (Exception)
                {
                    MessageBox.Show("Ви ввели не адреси електронним пошти.");
                    return;
                }
            }

            if (CreateRequests.Registration(UsernameBox.Text, EmailBox.Text, PasswordBox.Text))
            {
                MessageBox.Show($"На вашу пошту {EmailBox.Text} був відправлений код для підтвердження.");
                EmailForm emailForm = new EmailForm();
                emailForm.ShowDialog();
                if (ClientLogic.Registered)
                {
                    ClientLogic.Username = UsernameBox.Text;
                    ClientLogic.Email    = EmailBox.Text;
                    ClientLogic.Password = PasswordBox.Text;
                    ClientDirectory.SaveAuthorization();
                    MessengerForm.Show();
                    this.Close();
                }
            }
        }
Example #2
0
 private void FriendButton_Click(object sender, EventArgs e)
 {
     if (ClientLogic.Connected)
     {
         string FriendUsername = (sender as Button).Tag.ToString();
         ChatMessageBox.Text         = CreateRequests.GetChat(FriendUsername);
         StatusFriend.Visible        = true;
         FriendUsernameLable.Visible = true;
         FriendUsernameLable.Text    = FriendUsername;
         SendButton.Enabled          = true;
         SendMessageBox.Enabled      = true;
         RefreshUsersStatus(ClientLogic.UsersOnline);
     }
 }
Example #3
0
        async public void AsyncTryConnectToServer()
        {
            await Task.Run(() =>
            {
                try
                {
                    ClientLogic.Connected   = false;
                    ConnectForm connectForm = new ConnectForm();
                    connectForm.ShowDialog();
                    if (ClientLogic.Registered)
                    {
                        if (!CreateRequests.Authorization(ClientLogic.Email, ClientLogic.Password))
                        {
                            RegistrationForm registrationForm = new RegistrationForm(this);
                            Invoke((MethodInvoker)(() =>
                            {
                                this.Hide();
                                registrationForm.ShowDialog();
                            }));
                        }
                    }
                    else
                    {
                        RegistrationForm registrationForm = new RegistrationForm(this);
                        Invoke((MethodInvoker)(() =>
                        {
                            this.Hide();
                            registrationForm.ShowDialog();
                        }));
                    }

                    ClientLogic.messengerForm = this;

                    Task receive = new Task(() => { ClientLogic.GetServerAnswer(); });
                    receive.Start();
                    Invoke((MethodInvoker)(() =>
                    {
                        UsernameLable.Text = ClientLogic.Username;
                    }));
                    ClientLogic.Connected = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("AsyncTryConnectToServer() Error.");
                }
            });
        }
Example #4
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            if (ClientLogic.Connected)
            {
                if (SendMessageBox.Text != string.Empty)
                {
                    DateTime date    = DateTime.Now;
                    string   message = $"[{date.ToShortTimeString()}] {ClientLogic.Username}: {SendMessageBox.Text}";

                    CreateRequests.SendMessage(FriendUsernameLable.Text, message);
                    ChatMessageBox.Text += message;
                    ChatMessageBox.Text += "\r";
                    ChatMessageBox.Text += "\n";
                    SendMessageBox.Clear();
                }
            }
        }
Example #5
0
 private void AddFriendButton_Click(object sender, EventArgs e)
 {
     if (ClientLogic.Connected)
     {
         if (FriendUsernameBox.Text == string.Empty)
         {
             MessageBox.Show("Введіть ім'я друга в сотвественую форму.");
             return;
         }
         if (CreateRequests.AddFriend(FriendUsernameBox.Text))
         {
             RefreshFriendsToList(CreateRequests.GetFriendList());
             RefreshUsersStatus(CreateRequests.RefreshUsersOnline());
             FriendUsernameBox.Clear();
         }
     }
 }
Example #6
0
        private void SendEmail_button_Click(object sender, EventArgs e)
        {
            int code;

            if (!int.TryParse(EmailCodeBox.Text, out code))
            {
                MessageBox.Show("Некоректне введення! Спробуйте ще раз.");
                EmailCodeBox.Clear();
            }
            else
            {
                if (CreateRequests.EmailConfirmation(code))
                {
                    ClientLogic.Registered = true;
                    this.Close();
                }
            }
        }
Example #7
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (UsernameOrEmailBox.Text == string.Empty)
            {
                MessageBox.Show("Поле з нік нейм і електронною поштою не може залишатися порожнім.");
                return;
            }
            else if (PasswordBox.Text == string.Empty)
            {
                MessageBox.Show("Поле з паролем повинно бути заповнене. Вигадайте важкий пароль, адже це захист Вашого аккаунта.");
                return;
            }

            if (CreateRequests.Authorization(UsernameOrEmailBox.Text, PasswordBox.Text))
            {
                ClientLogic.Registered = true;
                Close();
            }
        }
Example #8
0
 private void FriendButtonRemove_Click(object sender, EventArgs e)
 {
     if (ClientLogic.Connected)
     {
         string FriendUsername = (sender as Button).Tag.ToString();
         if (CreateRequests.RemoveFriend(FriendUsername))
         {
             MessageBox.Show($"Ваш приятель {FriendUsername} був видалений.");
             if (FriendUsername == FriendUsernameLable.Text)
             {
                 FriendUsernameLable.Text = "Ім'я вашого приятеля:";
                 ChatMessageBox.Clear();
                 ChatMessageBox.Enabled = false;
                 SendMessageBox.Clear();
                 SendMessageBox.Enabled      = false;
                 SendButton.Enabled          = false;
                 StatusFriend.Visible        = false;
                 FriendUsernameLable.Visible = false;
             }
         }
         RefreshFriendsToList(CreateRequests.GetFriendList());
     }
 }
Example #9
0
 private void StartRefreshUsersOnline(StatusOnlineJSON statusOnlineJSON)
 {
     MessengerForm.RefreshFriendsToList(CreateRequests.GetFriendList());
     MessengerForm.RefreshUsersStatus(statusOnlineJSON.UserList);
 }