private void ButtonLogin_OnClick(object sender, RoutedEventArgs e) { ResetMessage(); MemberLogin memberLogin = new MemberLogin { email = this.Email.Text, password = this.Password.Password }; Dictionary <string, string> errors = Validate.ValidateLogin(memberLogin); if (errors.Count > 0) { if (errors.ContainsKey("Email")) { EmailMessage.Text = errors["Email"]; EmailMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Password")) { PasswordMessage.Text = errors["Password"]; PasswordMessage.Visibility = Visibility.Visible; } return; } MemberServiceImp memberServiceImp = new MemberServiceImp(); memberServiceImp.Login(Email.Text, Password.Password); var token = memberServiceImp.GetTokenFromApi(memberLogin); var member = memberServiceImp.GetInformation(token); ResetLoginForm(); GoToInfo(null, null); }
private void BtnSubmit_Click(object sender, RoutedEventArgs e) { var member = new Member { firstName = txtFirstName.Text, lastName = txtLastName.Text, password = txtPassword.Password.ToString(), address = txtAddress.Text, avatar = txtAvatar.Text, birthday = txtBirthday.Text, email = txtEmail.Text, gender = Int32.Parse(txtGender.Text), introduction = txtIntroduction.Text, phone = txtPhone.Text }; ////Debug.WriteLine(JsonConvert.SerializeObject(member)); //Debug.WriteLine(JsonConvert.SerializeObject(member)); //var httpClient = new HttpClient(); ////httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + token); //HttpContent content = new StringContent(JsonConvert.SerializeObject(member), Encoding.UTF8, // "application/json"); //Task<HttpResponseMessage> httpRequestMessage = httpClient.PostAsync(ApiUrl, content); //String responseContent = httpClient.PostAsync(ApiUrl, content).Result.Content.ReadAsStringAsync().Result; //Debug.WriteLine("Response: " + responseContent); //Member resMember = JsonConvert.DeserializeObject<Member>(responseContent); //JObject resJObject = JObject.Parse(responseContent); //Debug.WriteLine(resMember.email); //Debug.WriteLine(resJObject["email"]); MemberServiceImp memberServiceImp = new MemberServiceImp(); memberServiceImp.FormRegister(member, ApiUrl); }
public MySong() { this.InitializeComponent(); memberService = new MemberServiceImp(); this.listMusic = new ObservableCollection <Music>(); var token = memberService.ReadTokenFromLocalStorage(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + token); String responseContent = httpClient.GetAsync(ApiUrl.GET_MY_SONG_URL).Result.Content.ReadAsStringAsync().Result; List <Music> listSong = JsonConvert.DeserializeObject <List <Music> >(responseContent); foreach (Music item in listSong) { this.listMusic.Add(new Music() { name = item.name, singer = item.singer, thumbnail = item.thumbnail, link = item.link, }); } }
public Login() { this.InitializeComponent(); memberService = new MemberServiceImp(); //Lay token da luu file trong lan dang nhap trc: var token = memberService.ReadTokenFromLocalStorage(); }
public MyInfo() { this.InitializeComponent(); MemberServiceImp memberServiceImp = new MemberServiceImp(); MyTextInfo.Text = memberServiceImp.FormGetInfo(getApi); }
private async void ButtonBase_LoginOnClick(object sender, RoutedEventArgs e) { var member = new Member { email = Username.Text, password = Password.Password, }; MemberServiceImp memberServiceImp = new MemberServiceImp(); memberServiceImp.FormLogin(member, api); }
public ListSong() { this.memberService = new MemberServiceImp(); loginToken = memberService.ReadTokenFromLocalStorage(); if (loginToken == null) { } else { this.InitializeComponent(); this.songService = new SongServiceImp(); LoadSongs(); } }
public Upload() { this.memberService = new MemberServiceImp(); loginToken = memberService.ReadTokenFromLocalStorage(); if (loginToken == null) { //Not login: } else { this.InitializeComponent(); this.songService = new SongServiceImp(); } }
private void PassportSignInButton_Click(object sender, RoutedEventArgs e) { MemberLogin memberLogin = new MemberLogin { email = this.emailLogin.Text, password = this.passwordLogin.Password }; Dictionary <string, string> errors = memberLogin.ValidateData(); //validate if (errors != null) { if (memberSerice.Login(memberLogin) != null) { this.login_er.Visibility = Visibility.Collapsed; Naview.isUser = true; MemberServiceImp.isUSer(); } else { this.login_er.Text = "Wrong login information!"; this.login_er.Visibility = Visibility.Visible; } } else { if (errors.ContainsKey("introduction")) { this.emailLogin_er.Text = errors["introduction"]; this.emailLogin_er.Visibility = Visibility.Visible; } else { this.emailLogin_er.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("introduction")) { this.passwordLogin_er.Text = errors["introduction"]; this.emailLogin_er.Visibility = Visibility.Visible; } else { this.passwordLogin_er.Text = ""; this.emailLogin_er.Visibility = Visibility.Collapsed; } } }
public Naview() { this.InitializeComponent(); MainFrame = this.ContentFrame; loginNaviewItem = this.Login; registerNaviewItem = this.Regsiter; uploadNaviewItem = this.UploadSong; myinfoNaviewItem = this.MyInfor; logoutNaviewItem = this.LogoutUser; mysongNaviewItem = this.MySong; memberService = new MemberServiceImp(); }
public Login() { this.InitializeComponent(); this.memberService = new MemberServiceImp(); //// read file. //Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; //Windows.Storage.StorageFile sampleFile = storageFolder.GetFileAsync("sample.txt").GetAwaiter().GetResult(); //var token = Windows.Storage.FileIO.ReadTextAsync(sampleFile).GetAwaiter().GetResult(); //Debug.WriteLine(token); //HttpClient client = new HttpClient(); //client.DefaultRequestHeaders.Add("Authorization", "Basic " + token); //var responseContent = client.GetAsync(ApiUrl.INFORMATION_URL).Result.Content.ReadAsStringAsync().Result; //JObject jsonJObject = JObject.Parse(responseContent); //Debug.WriteLine(jsonJObject["email"]); }
public NaView() { this.InitializeComponent(); uploadNav = this.upload; mysongNav = this.mysong; listsongNav = this.listsong; profileNav = this.profile; memberService = new MemberServiceImp(); tokenLogin = memberService.ReadTokenFromLocalStorage(); if (tokenLogin == null) { } else { Member memberLogin = memberService.GetInformation(tokenLogin); } }
public MySong() { this.memberService = new MemberServiceImp(); loginToken = memberService.ReadTokenFromLocalStorage(); if (loginToken == null) { } else { this.InitializeComponent(); this.songService = new SongServiceImp(); LoadSongs(); if (_songs.Count == 0) { this.empty.Visibility = Visibility.Visible; this.media.Visibility = Visibility.Collapsed; } } }
private void ButtonBase_LoginOnClick(object sender, RoutedEventArgs e) { var memberLogin = new User { email = Email.Text, password = Password.Password, }; MemberServiceImp memberServiceImp = new MemberServiceImp(); memberServiceImp.FormLogin(memberLogin, ApiUrl.URL_LOGIN); //var httpClient = new HttpClient(); //HttpContent authenticateContent = new StringContent(JsonConvert.SerializeObject(member), Encoding.UTF8, "application/json"); //Task<HttpResponseMessage> httpRequestMessage = httpClient.PostAsync(api, authenticateContent); //var jsonResult = httpRequestMessage.Result.Content.ReadAsStringAsync().Result; //var response = JsonConvert.DeserializeObject<Member>(jsonResult); //var token = response.token; //httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + token); ////Lay gia tri get ve //Frame.Navigate(typeof(MyInfo), httpClient); ////Frame.Navigate(typeof(NavigationView), httpClient); //======= //var dataContent = new StringContent(JsonConvert.SerializeObject(memberLogin), // Encoding.UTF8, "application/json"); //HttpClient client = new HttpClient(); //var responseContent = client.PostAsync(LOGIN_URL, dataContent).Result.Content.ReadAsStringAsync().Result; //JObject jsonJObject = JObject.Parse(responseContent); //Debug.WriteLine(jsonJObject["token"]); //Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; //Windows.Storage.StorageFile sampleFile = storageFolder.CreateFileAsync("token1.txt", // Windows.Storage.CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult(); ////Windows.Storage.StorageFile sampleFile = await storageFolder.GetFileAsync("token1.txt"); //Windows.Storage.FileIO.WriteTextAsync(sampleFile, jsonJObject["token"].ToString()).GetAwaiter().GetResult(); //Debug.WriteLine(sampleFile.Path); }
private void ButtonBase_JsonOnClick(object sender, RoutedEventArgs e) { var user = new User { firstName = FirstName.Text, lastName = LastName.Text, avatar = AvatarUrl.Text, phone = Phone.Text, address = Address.Text, introduction = Introduction.Text, gender = Int32.Parse(Gender.Text), birthday = Birthday.Text, email = Email.Text, password = Password.Password }; MemberServiceImp memberServiceImp = new MemberServiceImp(); memberServiceImp.FormRegister(user, api); }
protected override void OnNavigatedTo(NavigationEventArgs e) { try { CreateReadFile createReadFile = new CreateReadFile(); var token = createReadFile.GetToken(); MemberServiceImp memberServiceImp = new MemberServiceImp(); var member = memberServiceImp.GetInformation(token); this.FirstName.Text = member.firstName; this.LastName.Text = member.lastName; this.Phone.Text = member.phone; this.Address.Text = member.address; this.Introduction.Text = member.introduction; this.Email.Text = member.email; if (member.gender == 0) { Male.IsChecked = true; } else { Female.IsChecked = true; } var datetime = member.birthday.Split("T"); this.Birthday.Date = DateTime.ParseExact(datetime[0], "yyyy-MM-dd", CultureInfo.InvariantCulture); try { this.Avatar.ImageSource = new BitmapImage(new Uri(member.avatar)); } catch (Exception exception) { } } catch (Exception exception) { Console.WriteLine("Chưa đăng nhập"); } }
public Profile() { memberService = new MemberServiceImp(); loginToken = memberService.ReadTokenFromLocalStorage(); if (loginToken == null) { } else { this.InitializeComponent(); memLogged = memberService.GetInformation(loginToken); if (memLogged.gender == 0) { this.gender.Text = "Female"; } else if (memLogged.gender == 1) { this.gender.Text = "Male"; } DateTime dt = DateTime.Parse(memLogged.birthday); this.birthday.Text = String.Format("{0:ddd, MMM d, yyyy}", dt); } }
public MyInfo() { HttpClient httpClient = new HttpClient(); this.InitializeComponent(); MemberServiceImp memberServiceImp = new MemberServiceImp(); content.Text = memberServiceImp.FormGetInfo(getApi); //Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; //Windows.Storage.StorageFile sampleFile = storageFolder.GetFileAsync("token1.txt").GetAwaiter().GetResult(); //string text = Windows.Storage.FileIO.ReadTextAsync(sampleFile).GetAwaiter().GetResult(); //httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + text); //var httpRequestMessage = httpClient.GetAsync(getApi); //var getResult = httpRequestMessage.Result.Content.ReadAsStringAsync().Result; //Member user = JsonConvert.DeserializeObject<Member>(getResult); //content.Text = getResult; }
public Register() { this.InitializeComponent(); memberServiceImp = new MemberServiceImp(); }
public Upload() { this.InitializeComponent(); memberService = new MemberServiceImp(); }
private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { var newMember = new Member() { firstName = this.firstname.Text, lastName = this.lastname.Text, avatar = this.imgUrl, phone = this.phone.Text, password = this.password.Password, address = this.address.Text, introduction = this.introduction.Text, birthday = this.Birthday.Date.ToString("yyyy-MM-dd"), email = this.email.Text, gender = this.gender, }; //validate Dictionary<string, string> errors = newMember.ValidateData(); if(errors.Count == 0) { memberService.logout(); var member = memberService.Register(newMember); if (member != null) { MemberServiceImp.isUSer(); } else { } } else { Debug.WriteLine("erroi register"); if (errors.ContainsKey("firstname")) { this.firstname_er.Text = errors["firstname"]; } else { this.firstname_er.Text = ""; } if (errors.ContainsKey("lastname")) { this.lastname_er.Text = errors["lastname"]; } else { this.lastname_er.Text = ""; } if (errors.ContainsKey("address")) { this.address_er.Text = errors["address"]; } else { this.address_er.Text = ""; } if (errors.ContainsKey("password")) { this.password_er.Text = errors["password"]; } else { this.password_er.Text = ""; } if (errors.ContainsKey("introduction")) { this.introduction_er.Text = errors["introduction"]; } else { this.introduction_er.Text = ""; } if (errors.ContainsKey("phone")) { this.phone_er.Text = errors["phone"]; } else { this.phone_er.Text = ""; } if (errors.ContainsKey("email")) { this.email_er.Text = errors["email"]; } else { this.email_er.Text = ""; } //this.birthday_er.Text = errors["birthday"]; //this.gender_er.Text = errors["gender"]; } }
private void RegisterButton_OnClick(object sender, RoutedEventArgs e) { ResetMessage(); if (this.Password.Password != this.ConfirmPassword.Password) { ConfirmPasswordMessage.Text = "Password is not matched!"; return; } else { ConfirmPasswordMessage.Text = string.Empty; } var member = new Member { firstName = this.FirstName.Text, lastName = this.LastName.Text, phone = this.Phone.Text, address = this.Address.Text, introduction = this.Introduction.Text, email = this.Email.Text, gender = this.gender, birthday = this.Birthday.Date.ToString("yyyy-MM-dd"), avatar = this.AvatarUrl.Text, password = this.Password.Password }; //validate phía client Dictionary <string, string> errors = Validate.ValidateMember(member); if (errors.Count > 0) { if (errors.ContainsKey("FirstName")) { FirstNameMessage.Text = errors["FirstName"]; FirstNameMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("LastName")) { LastNameMessage.Text = errors["LastName"]; LastNameMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Phone")) { PhoneMessage.Text = errors["Phone"]; PhoneMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Gender")) { GenderMessage.Text = errors["Gender"]; GenderMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Birthday")) { BirthdayMessage.Text = errors["Birthday"]; BirthdayMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Email")) { EmailMessage.Text = errors["Email"]; EmailMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Introduction")) { IntroductionMessage.Text = errors["Introduction"]; IntroductionMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Address")) { AddressMessage.Text = errors["Address"]; AddressMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Password")) { PasswordMessage.Text = errors["Password"]; PasswordMessage.Visibility = Visibility.Visible; } if (errors.ContainsKey("Avatar")) { AvatarMessage.Text = errors["Avatar"]; AvatarMessage.Visibility = Visibility.Visible; } return; } Debug.WriteLine(JsonConvert.SerializeObject(member)); MemberServiceImp memberServiceImp = new MemberServiceImp(); member = memberServiceImp.Register(member); Debug.WriteLine(Birthday); GoToLogin(null, null); }