Esempio n. 1
0
 private void Login_Click(object sender, RoutedEventArgs e)
 {
     if (user.Text == "" || pass.Password == "")
     {
         MessageBox.Show("id or password can't be empty");
     }
     else
     {
         //SocketClientOut.accountEstablish();
         SocketClientOut.connectionEstablish();
         SocketClientOut.privatePort();
         SocketClientOut.sendActionRequest(Encoding.ASCII.GetBytes("login"));
         SocketClientOut.sendIdAndPassword(Encoding.ASCII.GetBytes(user.Text), Encoding.ASCII.GetBytes(pass.Password));
         var access = SocketClientOut.receiveAccess();
         if (Encoding.ASCII.GetString(access) == "granted")
         {
             var  st = Encoding.ASCII.GetString(SocketClientOut.receiveAccess());
             User x  = JsonConvert.DeserializeObject <User>(st);
             st       = Encoding.ASCII.GetString(SocketClientOut.receiveAccess());
             allSongs = JsonConvert.DeserializeObject <Playlist>(st);
             AfterLogin b = new AfterLogin(x);
             Reset();
             this.Hide();
             b.Show();
         }
         else if (Encoding.ASCII.GetString(access) == "denied")
         {
             InvalidLogin.Visibility = Visibility.Visible;
         }
     }
 }
Esempio n. 2
0
        private void Login_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (user.Text == "" || pass.Password == "")
                {
                    MessageBox.Show("id or password can't be empty");
                }
                else
                {
                    //SocketClientOut.accountEstablish();
                    SocketClientOut.connectionEstablish();
                    SocketClientOut.privatePort();
                    SocketClientOut.sendActionRequest(Encoding.ASCII.GetBytes("login"));
                    SocketClientOut.sendIdAndPassword(Encoding.ASCII.GetBytes(user.Text), Encoding.ASCII.GetBytes(pass.Password));
                    var access = SocketClientOut.receiveAccess();
                    if (Encoding.ASCII.GetString(access) == "granted")
                    {
                        var  st = Encoding.ASCII.GetString(SocketClientOut.receiveAccess());
                        User x  = JsonConvert.DeserializeObject <User>(st);
                        st       = Encoding.ASCII.GetString(SocketClientOut.receiveAccess());
                        allSongs = JsonConvert.DeserializeObject <Playlist>(st);
                        AfterLogin b = new AfterLogin(x);
                        Reset();
                        this.Hide();
                        b.Show();
                    }
                    else if (Encoding.ASCII.GetString(access) == "denied")
                    {
                        InvalidLogin.Visibility = Visibility.Visible;
                    }
                }

                /*
                 * var msg = "Incorrect Username or Password!";
                 * int counter = 0;
                 * foreach (var x in everyUser.Users)
                 * {
                 *
                 *  if (user.Text == x.mUsername && pass.Password == x.mPassword)
                 *  {
                 *      AfterLogin b = new AfterLogin(x);
                 *      counter++;
                 *      Reset();
                 *      this.Hide();
                 *      b.Show();
                 *      break;
                 *  }
                 *
                 * }
                 *
                 * if (counter == 0)
                 * {
                 *  InvalidLogin.Visibility = Visibility.Visible;
                 *  //MessageBox.Show(msg);
                 * }
                 */
            }
        }