Example #1
0
        public async Task <CustomAuthResponse> Register(string fullname, string email, string password)
        {
            var _response = new CustomAuthResponse
            {
                Data = null,
                Meta = new Meta {
                    Messages = new List <string>(), Success = false
                }
            };

            try
            {
                var payload  = JsonConvert.SerializeObject(new { fullname, email, password });
                var _content = new StringContent(payload, Encoding.UTF8, "application/json");

                var response = await _client.PostAsync("api/auth/register/", _content);

                var content = await response.Content.ReadAsStringAsync();

                _response.Meta = JsonConvert.DeserializeObject <RegisterAuthResponse>(content).Meta;
                return(_response);
            }
            catch (HttpRequestException)
            {
                _response.Meta.Messages.Add("NO_INTERNET");
            }
            catch (Exception)
            {
                _response.Meta.Messages.Add("GENERAL");
            }
            return(_response);
        }
Example #2
0
        public async Task <CustomAuthResponse> Login(string email, string password)
        {
            var _response = new CustomAuthResponse
            {
                Data = null,
                Meta = new Meta {
                    Messages = new List <string>(), Success = false
                }
            };

            try
            {
                var payload  = new { email, password };
                var _content = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json");
                var response = await _client.PostAsync("api/auth/login/", _content);

                var content = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <CustomAuthResponse>(content));
                }
                _response.Meta = JsonConvert.DeserializeObject <CustomErrorResponse>(content).Meta;
            }
            catch (HttpRequestException)
            {
                _response.Meta.Messages.Add("NO_INTERNET");
            }
            catch (Exception)
            {
                _response.Meta.Messages.Add("GENERAL");
            }
            return(_response);
        }