private async void SignIn_clicked(object sender, EventArgs e) { if (ActivityIndicator.IsRunning) { return; } List <User> register = new List <User>(); var Email = email.Text; var Password = password.Text; if (String.IsNullOrWhiteSpace(Email) || String.IsNullOrWhiteSpace(Password)) { check_inputs.Text = Lang.Resource.check_inputsSignin1; return; } if (Password.Length > 8) { check_inputs.Text = Lang.Resource.check_inputsSignin2; return; } if (Password.Contains("~") || Email.Contains("~")) { check_inputs.Text = Lang.Resource.check_inputsSignin3; return; } var emailpattern = "^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$"; if (!String.IsNullOrWhiteSpace(Email) && !(Regex.IsMatch(Email, emailpattern))) { check_inputs.Text = Lang.Resource.check_inputsSignin4; return; } if (!CheckNetwork.Check_Connectivity()) { return; } ActivityIndicator.IsVisible = true; ActivityIndicator.IsRunning = true; contentpage.Opacity = 0.5; RegistersServices R_S = new RegistersServices(); List <User> registers = await R_S.GetRegistersBykeywordAsync(Email.Substring(0, Email.IndexOf("."))); if (registers != null) { if (registers.Count > 0 && registers.ElementAt(0).Email_Property == Email) { FileAndFolderUser(registers.ElementAt(0)); await Task.Delay(500); await Navigation.PopToRootAsync(); } else { ActivityIndicator.IsVisible = false; ActivityIndicator.IsRunning = false; contentpage.Opacity = 1; check_inputs.Text = Lang.Resource.check_inputsSignin5; return; } } await Task.Delay(500); ActivityIndicator.IsVisible = false; ActivityIndicator.IsRunning = false; contentpage.Opacity = 1; }
private async void SignUp_clicked(object sender, EventArgs e) { string userName = username.Text; string Email = email.Text; string Password = password.Text; string Age = age.Text; if (String.IsNullOrWhiteSpace(Age) || String.IsNullOrWhiteSpace(Email) || String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(Password)) { check_inputs.Text = Lang.Resource.check_inputsSignin1; return; } if (Password.Length > 8) { check_inputs.Text = Lang.Resource.check_inputsSignin2; return; } string Check = userName + Email + Password + Age; if (Check.Contains("~")) { check_inputs.Text = Lang.Resource.check_inputsSignin3; return; } var emailpattern = "^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$"; if (!String.IsNullOrWhiteSpace(Email) && !(Regex.IsMatch(Email, emailpattern))) { check_inputs.Text = Lang.Resource.check_inputsSignin4; return; } var confirmpassword = verifypassword.Text; if (confirmpassword != Password) { check_inputs.Text = Lang.Resource.confirmPassword; return; } if (!CheckNetwork.Check_Connectivity()) { return; } ActivityIndicator.IsVisible = true; ActivityIndicator.IsRunning = true; contentpage.Opacity = 0.5; // Folder Accounts folder = FileSystem.Current.LocalStorage; ExistenceCheckResult Result = await folder.CheckExistsAsync("folderAccount"); if (Result != ExistenceCheckResult.FolderExists) { folder = await folder.CreateFolderAsync("folderAccount", CreationCollisionOption.ReplaceExisting); } else { folder = await folder.CreateFolderAsync("folderAccount", CreationCollisionOption.OpenIfExists); } //file = await folder.GetFileAsync("fileAccount"); //await file.DeleteAsync(); //return; //string serialize; Register r; //Result = await folder.CheckExistsAsync("fileAccount"); //if (Result != ExistenceCheckResult.FileExists) //{ // // File Accounts // file = await folder.CreateFileAsync("fileAccount", CreationCollisionOption.ReplaceExisting); // r = new Register(userName, Password, "khalil", Email, DateTime.Now.ToString()); // register.Add(r); // serialize = Serializable_Account.serialize(register); // await file.WriteAllTextAsync(serialize); // // Folder And File User // FileAndFolderUser(serialize); // await Navigation.PopToRootAsync(); // return; //} //file = await folder.CreateFileAsync("fileAccount", CreationCollisionOption.OpenIfExists); //string Accounts = await file.ReadAllTextAsync(); //if (Accounts == "") //{ // r = new Register(userName, Password, "khalil", Email, DateTime.Now.ToString()); // register.Add(r); // serialize = Serializable_Account.serialize(register); // await file.WriteAllTextAsync(serialize); // // Folder And File User // FileAndFolderUser(serialize); // await Navigation.PopToRootAsync(); // return; //} //register = Serializable_Account.deserialize(Accounts); //foreach (Register R in register) //{ // if (userName.Equals(R.UserName_Property) || Email.Equals(R.Email_Property)) // { // check_inputs.Text = "there are same UserName or Email ..."; // return; // } //} //r = new Register(userName, Password, "khalil", Email, DateTime.Now.ToString()); //register.Add(r); //serialize = Serializable_Account.serialize(register); //await file.WriteAllTextAsync(serialize); //// Folder And File User //register.Clear(); //register.Add(r); //serialize = Serializable_Account.serialize(register); //FileAndFolderUser(serialize); RegistersServices R_S = new RegistersServices(); string _email = Email.Substring(0, Email.IndexOf(".")); User user = null; List <User> listregisters = new List <User>(); if (register == null) { listregisters = await R_S.GetRegistersBykeywordAsync(_email); if (listregisters.Count == 0) { user = new User(userName, Password, Email, Int32.Parse(Age), country, DateTime.Now.ToString().Substring(0, 10)); await R_S.PostRegistersAsync(user); listregisters.Add(user); string serialize = Serializable_Account.serialize(listregisters); FileAndFolderUser(serialize); await Task.Delay(500); await Navigation.PopToRootAsync(); } else { check_inputs.Text = Lang.Resource.username_same_email; ActivityIndicator.IsVisible = false; ActivityIndicator.IsRunning = false; contentpage.Opacity = 1; return; } } else { user = new User(userName, Password, Email, Int32.Parse(Age), country, register.Date); R_S.Set_UrlApi("Edit/"); await R_S.PutRegistersAsync(user); listregisters.Add(user); string serialize = Serializable_Account.serialize(listregisters); FileAndFolderUser(serialize); await Task.Delay(500); await Navigation.PopModalAsync(); } }