private async void Log_in(object sender, RoutedEventArgs e) { if (this.Username.Text == null || this.Username.Text == "" || this.Password_login.Password == null || this.Password_login.Password == "") { Login_Error.Text = "Email & Password can not be null!"; } else { var httpResponseMessage = ApiHandle.Sign_In(Username.Text, Password_login.Password); var responseContent = await httpResponseMessage.Content.ReadAsStringAsync(); if (httpResponseMessage.StatusCode == HttpStatusCode.Created) { // save file... Debug.WriteLine(responseContent); // Doc token TokenResponse token = JsonConvert.DeserializeObject <TokenResponse>(responseContent); // Luu token StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.CreateFileAsync("token.txt", CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, responseContent); Debug.WriteLine("login success!"); } else { // Xu ly loi. //errorresponse errorobject = jsonconvert.deserializeobject<errorresponse>(responsecontent); //if (errorobject != null && errorobject.error.count > 0) //{ // foreach (var key in errorobject.error.keys) // { // var textmessage = findname(key); // if (textmessage == null) // { // continue; // } // textblock textblock = textmessage as textblock; // textblock.text = errorobject.error[key]; // textblock.visibility = visibility.visible; // } //} //Debug.WriteLine(errorObject); } } }
private async void Login_Button(object sender, RoutedEventArgs e) { var username = Username.Text; var password = Password.Password; if (username == "") { Username_Message.Text = "Username is empty."; } else { Username_Message.Text = ""; this.account.username = username; }; if (password == "") { Password_Message.Text = "Password is empty."; } else { Password_Message.Text = ""; this.account.password = password; }; if (Username_Message.Text == "" && Password_Message.Text == "") { Response_Login.Text = ""; ResultAPI response = await ApiHandle.Sign_In(this.account); JObject data = JObject.Parse(response.Data); var errorCode = response.Status; if (errorCode == "Unauthorized") { Response_Login.Text = data.SelectToken("error").ToString(); } else { this.Frame.Navigate(typeof(Frames.MainSiinMusic)); StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.CreateFileAsync("config_login.json", CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, data.ToString()); } } }