Example #1
0
        public async Task <string> Login(LoginForm loginForm)
        {
            var user     = JsonSerializer.Serialize(loginForm);
            var response = await _http.PostAsync(_baseUrl + "login",
                                                 new StringContent(user,
                                                                   Encoding.UTF8,
                                                                   "application/json"));

            var content = response.Content.ReadAsStringAsync();

            if (content.Result.StartsWith("{\"token\""))
            {
                var authResponse = JsonSerializer.Deserialize <AuthResponse>(content.Result,
                                                                             new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                });

                await SetCurrentUser(authResponse.User);

                return("OK " + authResponse.Token);
            }

            string errorMessage = ErrorInterceptor.InterceptError(content.Result);

            return(errorMessage);
        }
Example #2
0
        public async Task <string> Register(RegisterForm registerForm)
        {
            var user     = JsonSerializer.Serialize(registerForm);
            var response = await _http.PostAsync(_baseUrl + "register",
                                                 new StringContent(user,
                                                                   Encoding.UTF8,
                                                                   "application/json"));

            var content = response.Content.ReadAsStringAsync();

            string errorMessage = ErrorInterceptor.InterceptError(content.Result);

            return(errorMessage);
        }