Beispiel #1
0
        // use: tylko po przycisku zaloguj
        public static async Task Login(String username, String password)
        {
            try
            {
                ClientBackend.StroreCredentials(username, password);
                String json = await ClientBackend.GetResponse("/user");

                ServerAnswerRecievedUser userData = JsonConvert.DeserializeObject <ServerAnswerRecievedUser>(await ClientBackend.GetResponse("/user"));

                if (userData.Status.Equals("success", StringComparison.OrdinalIgnoreCase))
                {
                    //ClientBackend.StroreCredentials(username, password);
                    //zapisz dane do pliku jesli sie udalo zalogowac
                    //jesli nie exception  throw new LoginException()
                }
                else
                {
                    throw new LoginException();
                }
            }
            catch (LoginException)
            {
                throw new LoginException();
            }
            catch (System.Exception)
            {
                throw new UnknownException();
            }
        }
Beispiel #2
0
        public static async Task RegisterUser(UserPersonalInfo userPersonalInfo)
        {
            try
            {
                string json = JsonConvert.SerializeObject(userPersonalInfo);

                var response = await ClientBackend.client.PostAsync((ClientBackend.api_domain + "/user"),
                                                                    new StringContent(json, Encoding.UTF8, "application/json"));

                string responseContent = await response.Content.ReadAsStringAsync();

                ServerFeedback serverFeedback = JsonConvert.DeserializeObject <ServerFeedback>(responseContent);
                if (serverFeedback.Status.Equals("success", StringComparison.OrdinalIgnoreCase))
                {
                    ClientBackend.StroreCredentials(userPersonalInfo.Login, userPersonalInfo.Password);
                }
                else
                {
                    throw new DataFormatException();
                }
            }
            catch (DataFormatException)
            {
                throw;
            }
            catch (ArgumentNullException)
            {
                throw;
            }
            catch (HttpRequestException)
            {
                throw;
            }
            catch (System.Exception)
            {
                throw new UnknownException();
            }
        }