Exemple #1
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);
            }
        }
Exemple #2
0
 public TestAccessor(ClientDirectory instance) => _instance = instance;