public static async Task <Account> Login(string email, string password) { Account account; string jsondata = JsonConvert.SerializeObject(new { Email = email, Password = password }); try{ HttpResponseMessage hrm = await httpClient.PostAsync(url + "Login", new StringContent(jsondata, Encoding.UTF8, "application/json")); hrm.EnsureSuccessStatusCode(); string response = await hrm.Content.ReadAsStringAsync(); SignInResponse signinresponse = JsonConvert.DeserializeObject <SignInResponse>(response); account = new Account(email, signinresponse.Token); return(account); } catch (Exception e) { return(null); } }
public static async Task <Account> Register(string email, string password, string nativeLanguage) { Account account; try{ HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, url + "Register"); var content = JsonConvert.SerializeObject(new { Email = email, Password = password, NativeLanguage = nativeLanguage }); requestMessage.Content = new StringContent(content, Encoding.UTF8, "application/json"); HttpResponseMessage hrm = await httpClient.SendAsync(requestMessage); hrm.EnsureSuccessStatusCode(); string response = await hrm.Content.ReadAsStringAsync(); SignInResponse registerResponse = JsonConvert.DeserializeObject <SignInResponse>(response); account = new Account(email, registerResponse.Token); return(account); } catch (Exception e) { return(null); } }