private async void signIn_Click(object sender, RoutedEventArgs e) { bool isSuccess = false; string email = createEmail.Text; string password = ""; if (createPassword.Password == verifyPassword.Password) { password = createPassword.Password; } if (email != "" && password != "") { UserVM user = new UserVM(email, password, email.Split(new[] { '@' })[0]); UserRP res = await ApiCall.MakeCall("subscribe", user); isSuccess = res.success; } if (isSuccess) { dial = new MessageDialog("Created account successfully !"); } else { dial = new MessageDialog("Sorry, account could not be created ! Use another email."); } await dial.ShowAsync(); }
private async void edit_Click(object sender, RoutedEventArgs e) { bool isSuccess = false; MessageDialog result; if (username.Text != "" && email.Text != "" && password.Password != "") { UserVM user = new UserVM(email.Text, password.Password, username.Text); user.userID = GlobalData.id; UserRP res = await ApiCall.MakeCall("editProfil", user); isSuccess = res.success; } if (isSuccess) { result = new MessageDialog("Your account has been modified successfully !"); } else { result = new MessageDialog("Error: Your information couldn't be modified."); } await result.ShowAsync(); }
private async void connect_Click(object sender, RoutedEventArgs e) { bool isSuccess = false; string email = this.email.Text; string password = this.password.Password; UserRP res = null; if (email != "" && password != "") { UserVM user = new UserVM(email, password, email.Split(new[] { '@' })[0]); res = await ApiCall.MakeCall("connect", user); isSuccess = res.success; } if (isSuccess) { GlobalData.email = email; GlobalData.token = (res == null) ? ("") : (res.token); dial = new MessageDialog("Connection success !"); await dial.ShowAsync(); Frame.Navigate(typeof(MainMenu)); } else { dial = new MessageDialog("Error: Wrong email/Password. Please try again !"); await dial.ShowAsync(); } }
static public async Task <UserRP> MakeCall(string method, UserVM obj) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:3000/"); if (method.Equals("editProfil")) { client.DefaultRequestHeaders.Add("Authorization", GlobalData.token); } client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.PostAsJsonAsync(method, obj); if (response.IsSuccessStatusCode) { string res = await response.Content.ReadAsStringAsync(); UserRP f = JsonConvert.DeserializeObject <UserRP>(res); return(f); } } return(null); }