Esempio n. 1
0
 public static bool Registration(string username, string email, string password)
 {
     try
     {
         RegistrationJSON registrationJSON = new RegistrationJSON {
             Username = username, Email = email, Password = password
         };
         string requestJSON = JsonSerializer.Serialize <RegistrationJSON>(registrationJSON);
         ClientLogic.SendMessage(requestJSON);
         return(AllowServer(ClientLogic.GetAnswer()));
     }
     catch (Exception)
     {
         if (!ClientLogic.ConnectToServer())
         {
             MessageBox.Show("Сервер не відповідає.");
             return(false);
         }
         else
         {
             RegistrationJSON registrationJSON = new RegistrationJSON {
                 Username = username, Email = email, Password = password
             };
             string requestJSON = JsonSerializer.Serialize <RegistrationJSON>(registrationJSON);
             ClientLogic.SendMessage(requestJSON);
             return(AllowServer(ClientLogic.GetAnswer()));
         }
     }
 }
    public static void Main(string[] args)
    {
        Logger.SetLogger(false);
        ClientLogic client = new ClientLogic();

        client.Init();
        client.ConnectToServer("127.0.0.1", 8181);
        client.Run();
    }
Esempio n. 3
0
        public static bool Authorization(string usernameOrEmail, string password)
        {
            try
            {
                AuthorizationJSON authorizationJSON = new AuthorizationJSON {
                    UsernameOrEmail = usernameOrEmail, Password = password
                };
                string requestJSON = JsonSerializer.Serialize <AuthorizationJSON>(authorizationJSON);
                ClientLogic.SendMessage(requestJSON);
            }
            catch (Exception)
            {
                if (!ClientLogic.ConnectToServer())
                {
                    MessageBox.Show("Сервер не відповідає.");
                    return(false);
                }
                else
                {
                    AuthorizationJSON authorizationJSON = new AuthorizationJSON {
                        UsernameOrEmail = usernameOrEmail, Password = password
                    };
                    string requestJSON = JsonSerializer.Serialize <AuthorizationJSON>(authorizationJSON);
                    ClientLogic.SendMessage(requestJSON);
                }
            }
            string answer = ClientLogic.GetAnswer();

            if (string.IsNullOrEmpty(answer))
            {
                MessageBox.Show("Сервер не відповідає.");
                return(false);
            }
            AllowAuthorizationJSON allowAuthorizationJSON = JsonSerializer.Deserialize <AllowAuthorizationJSON>(answer);

            if (allowAuthorizationJSON.Allow)
            {
                ClientLogic.Username = allowAuthorizationJSON.Username;
                ClientLogic.Email    = allowAuthorizationJSON.Email;
                ClientLogic.Password = allowAuthorizationJSON.Password;
                ClientDirectory.SaveAuthorization();
                return(true);
            }
            else
            {
                MessageBox.Show(allowAuthorizationJSON.Reason);
                return(false);
            }
        }