partial void BtnConfirmDAuth_TouchUpInside(UIButton sender) { if (String.IsNullOrEmpty(tfCodeField.Text)) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS); return; } String userCode = DAuthHelper.GetUserCode(Application.ActualUserPrivateKey); if (tfCodeField.Text.ToLower() != userCode.ToLower()) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Ce code est erroné"); return; } //load user pets Application.PetManager.LoadUserPetList(Application.ActualUser); //instantiate main view controller UIStoryboard mainBoard = UIStoryboard.FromName("Main", null); MainTabBarController mainTabBarController = mainBoard.InstantiateViewController("MainTabBarController") as MainTabBarController; PresentViewController(mainTabBarController, true, null); }
partial void BtnDeleteAttribut_TouchUpInside(UIButton sender) { //if is a new attribute if (petAttributeID == -1) { this.NavigationController.PopViewController(true); return; } //remove attribute ServerPacketConfirmation serverPacketConfirmation = ServerHelper.DeleteAttribut(Application.PetManager.SelectedPet.PetID, petAttributeID); if (serverPacketConfirmation.ActionSuccess) { this.NavigationController.PopViewController(true); return; } //chose right error message String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible de modifier les attributs"; break; } //show error message BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); }
public void ConfirmAccount() { //get confirmation code String confirmationCode = tfConfirmationCodeField.Text; //send packet to server ServerPacketConfirmation serverPacketConfirmation = ServerHelper.ConfirmUserAccount(Application.ActualUser, confirmationCode); //if success if (serverPacketConfirmation.ActionSuccess) { BarHelper.DisplayInfoBar(uivMainView, "Compte", "Votre compte a été confirmé", 5, delegate { //load user pets Application.PetManager.LoadUserPetList(Application.ActualUser); //instantiate main view controller UIStoryboard mainBoard = UIStoryboard.FromName("Main", null); MainTabBarController mainTabBarController = mainBoard.InstantiateViewController("MainTabBarController") as MainTabBarController; PresentViewController(mainTabBarController, true, null); }, delegate { //load user pets Application.PetManager.LoadUserPetList(Application.ActualUser); //instantiate main view controller UIStoryboard mainBoard = UIStoryboard.FromName("Main", null); MainTabBarController mainTabBarController = mainBoard.InstantiateViewController("MainTabBarController") as MainTabBarController; PresentViewController(mainTabBarController, true, null); }); return; } //chose right error message String messageError = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.GLOBAL_UNKNOWN: goto default; case NetworkError.SQL_USER_WRONG_ACCODE: messageError = "Ce code d'activation n'existe pas."; break; case NetworkError.SERVER_UNAVAILABLE: messageError = MSGBank.ERROR_NO_SERVER; break; default: messageError = MSGBank.ERROR_UNKNOWN; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError); }
partial void BtnSaveEdit_TouchUpInside(UIButton sender) { //if some fields are empty if (String.IsNullOrEmpty(tfUserEmailField.Text) || String.IsNullOrEmpty(tfUserPasswordField.Text)) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS); return; } //if email is valid if (!tfUserEmailField.Text.IsValidEmail()) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_WRONG_EMAIL); return; } //if the two passwords are the same if (tfUserPasswordField.Text != tfUserPasswordConfirmField.Text) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_NOT_SAME_PASSWORD); return; } //change actual user infos PLFUser actualUser = Application.ActualUser; actualUser.UserName = tfUserNameField.Text; actualUser.UserSurname = tfUserSurnameField.Text; actualUser.UserEMail = tfUserEmailField.Text; //send profile update to server ServerPacketConfirmation serverPacketConfirmation = ServerHelper.UpdateUserProfile(actualUser, tfUserPasswordField.Text); //if success if (serverPacketConfirmation.ActionSuccess) { BarHelper.DisplayInfoBar(uivMainView, "Profil", "Votre profil a correctement été mis à jour."); } else { //get the good error message String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible de mettre à jour votre profil."; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); } }
partial void BtnChangePassword_TouchUpInside(UIButton sender) { //if fields are empty if (String.IsNullOrEmpty(tfNickNameField.Text) || String.IsNullOrEmpty(tfCodeField.Text) || String.IsNullOrEmpty(tfPasswordField.Text)) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS); return; } //if not same password if (tfPasswordField.Text != tfPasswordConfirmField.Text) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_NOT_SAME_PASSWORD); return; } //send packet to server ServerPacketConfirmation serverPacketConfirmation = ServerHelper.ResetUserPassword(tfNickNameField.Text, tfPasswordField.Text, tfCodeField.Text); if (serverPacketConfirmation.ActionSuccess) { MessageBox.ShowOK("Restauration de mot de passe", "Votre mot de passe a été mis à jour ! Vous pouvez désormais vous connecter avec celui-ci !", this, delegate { this.NavigationController.PopToRootViewController(true); }); return; } //chose right error message String messageError = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.GLOBAL_UNKNOWN: goto default; case NetworkError.SERVER_UNAVAILABLE: messageError = MSGBank.ERROR_NO_SERVER; break; case NetworkError.SQL_USER_UNKNOWN: messageError = MSGBank.ERROR_UNKNOWN_USER; break; case NetworkError.SQL_USER_WRONG_ACCODE: messageError = "Ce code de restauration n'existe pas ou n'est plus valide !"; break; default: messageError = MSGBank.ERROR_UNKNOWN; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError); }
private void Connect() { //if empty fields if (String.IsNullOrEmpty(tfNickField.Text) || String.IsNullOrEmpty(tfPasswordField.Text)) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS, 3); return; } ConnectionHelper.SaveConnectionProfile(tfNickField.Text, tfPasswordField.Text); Auth(new ConnectionProfile(tfNickField.Text, tfPasswordField.Text.HashSHA256())); }
/// <summary> /// Loads the page. /// </summary> public void LoadPage() { //get user share list online List <PLFUser> userList = ServerHelper.SharePetList(selectedPet.PetID).UserList; //if no if (userList.Count <= 0) { InitUserPicker(new List <PLFUser>()); BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Ce familier n'est partagé avec personne !"); return; } //init user picker with downloaded list InitUserPicker(userList); selectedUser = userList[0]; pvUserPicker.SelectedRowInComponent(0); }
/// <summary> /// Buttons the save pet touch up inside. /// </summary> /// <param name="sender">Sender.</param> partial void BtnSavePet_TouchUpInside(UIButton sender) { //create new pet with selected type PLFPet pet = new PLFPet(selectedType); pet.PetName = tfPetNameField.Text; //send pet register to server ServerPacketAddPet serverPacketAddPet = ServerHelper.AddPet(Application.ActualUser, pet); //if register success if (serverPacketAddPet.RegisterSuccess) { //set pet id pet.PetID = serverPacketAddPet.PetID; //add pet to user pet list Application.PetManager.AddPet(pet); //reset fields selectedType = PetType.OTHER; tfPetNameField.Text = ""; //pop actual controller this.NavigationController.PopViewController(true); return; } //get the good error message String errorMessage = string.Empty; switch (serverPacketAddPet.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible d'ajouter ce familier"; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); }
partial void BtnAskForNewCode_TouchUpInside(UIButton sender) { //if fields are empty if (String.IsNullOrEmpty(tfNickNameField.Text)) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Vous devez remplir le champ 'Nom d'utilisateur'"); return; } //send packet to server ServerPacketConfirmation serverPacketConfirmation = ServerHelper.AskResetUserPassword(tfNickNameField.Text); //if success if (serverPacketConfirmation.ActionSuccess) { BarHelper.DisplayInfoBar(uivMainView, "Restauration de mot de passe", "Un nouveau code de restauration de mot de passe vous a été envoyé par mail !"); btnAskForNewCode.Enabled = false; return; } //chose right error message String messageError = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.GLOBAL_UNKNOWN: goto default; case NetworkError.SERVER_UNAVAILABLE: messageError = MSGBank.ERROR_NO_SERVER; break; case NetworkError.SQL_USER_UNKNOWN: messageError = MSGBank.ERROR_UNKNOWN_USER; break; default: messageError = MSGBank.ERROR_UNKNOWN; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError); }
partial void BtnSharePet_TouchUpInside(UIButton sender) { //if try to share to himself if (tfShareUserName.Text.ToLower() == Application.ActualUser.UserNickName.ToLower()) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_SHARE_YOURSELF); return; } //send share pet packet to server ServerPacketConfirmation serverPacketConfirmation = ServerHelper.SharePet( Application.ActualUser, selectedPet, tfShareUserName.Text, swAllowModifications.On ? 1 : 0); //if success share if (serverPacketConfirmation.ActionSuccess) { this.NavigationController.PopViewController(true); MessageBox.ShowOK("Partage", $"Votre familier a bien été partagé avec {tfShareUserName.Text}", this.NavigationController.ParentViewController); return; } //chose right error message String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; case NetworkError.SQL_USER_UNKNOWN: errorMessage = MSGBank.ERROR_UNKNOWN_USER; break; default: errorMessage = $"Impossible de partager ce familier"; break; } //show error message BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); }
/// <summary> /// Buttons the delete pet touch up inside. /// </summary> /// <param name="sender">Sender.</param> partial void BtnDeletePet_TouchUpInside(UIButton sender) { //ask yes no delete MessageBox.ShowYesNo("Suppression de familier", "Etes vous sûr de vouloir supprimer ce familier ?", delegate { //yes //send delete pet to server ServerPacketConfirmation serverPacketConfirmation = ServerHelper.DeletePet(Application.ActualUser, actualPet); //if pet successfuly delete if (serverPacketConfirmation.ActionSuccess) { //delete from list Application.PetManager.DeletePet(actualPet); //pop view controller this.NavigationController.PopViewController(true); return; } //switch for the good error msg String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible de supprimer ce familier"; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); //Show error message }, delegate { //no //nothing }, this); }
partial void BtnActivateDAuth_TouchUpInside(UIButton sender) { if (String.IsNullOrEmpty(tfCodeField.Text)) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS); return; } if (googleTOTP.GeneratePin().ToLower() != tfCodeField.Text.ToLower()) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Code erroné !"); return; } ServerPacketConfirmation serverPacketConfirmation = ServerHelper.EnableUserDAuth(Application.ActualUser, googleTOTP.getPrivateKey()); //if success if (serverPacketConfirmation.ActionSuccess) { Application.ActualUserPrivateKey = googleTOTP.getPrivateKey(); MessageBox.ShowOK("Double authentification", "La double authentification a bien été activée.", this, delegate { this.NavigationController.PopToRootViewController(true); }); } else { //get the good error message String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible d'activer la double authentification."; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); } }
partial void BtnDesactivateDAuth_TouchUpInside(UIButton sender) { MessageBox.ShowYesNo("Double Authentification", "Êtes vous sûr de vouloir supprimer la double authentification?", delegate { ServerPacketConfirmation serverPacketConfirmation = ServerHelper.DisableUserDAuth(Application.ActualUser); //if success if (serverPacketConfirmation.ActionSuccess) { MessageBox.ShowOK("Double authentification", "La double authentification a bien été désactivée.", this, delegate { Application.ActualUserPrivateKey = null; this.NavigationController.PopToRootViewController(true); }); } else { //get the good error message String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible de désactiver la double authentification."; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); } }, delegate { //no action }, this); }
partial void BtnSaveChanges_TouchUpInside(UIButton sender) { //set pet attribute fields petAttribute.AttributeTitle = tfAttributName.Text; petAttribute.AttributeDescription = tvAttributDescription.Text; petAttribute.PetAttributeType = selectedType; //remove old attribute and add new one if (petAttributeID != -1) { ServerHelper.DeleteAttribut(Application.PetManager.SelectedPet.PetID, petAttributeID); } //send packet to server ServerPacketConfirmation serverPacketConfirmation = ServerHelper.AddAttribut(Application.PetManager.SelectedPet.PetID, petAttribute); if (serverPacketConfirmation.ActionSuccess) { this.NavigationController.PopViewController(true); return; } //chose right error message String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible de modifier les attributs"; break; } //show error message BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); }
partial void BtnCancelShare_TouchUpInside(UIButton sender) { //if no user selected if (selectedUser == null) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Il faut sélectionner un utilisateur !"); return; } //send kill share pet to server ServerPacketConfirmation serverPacketConfirmation = ServerHelper.KillSharePet(selectedPet.PetID, selectedUser.ID); //if success if (serverPacketConfirmation.ActionSuccess) { BarHelper.DisplayInfoBar(uivMainView, "Partage", $"Le partage a bien été cessé avec {selectedUser.UserNickName} !"); //reload page LoadPage(); return; } //chose right error message String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible de césser le partage de ce familier !"; break; } //show error message BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); }
/// <summary> /// Auth the specified connectionProfile. /// </summary> /// <param name="connectionProfile">Connection profile.</param> public void Auth(ConnectionProfile connectionProfile) { //send login packet ServerPacketUserLogin serverPacketUserLogin = ServerHelper.LoginUserHashed(connectionProfile.UserName, connectionProfile.UserPassword); //if login success if (serverPacketUserLogin.NetworkError == NetworkError.NONE) { //set actual user infos Application.ActualUser = serverPacketUserLogin.UserProfile; Application.UserPassword = tfPasswordField.Text; if (serverPacketUserLogin.UserAccountActivate) { if (serverPacketUserLogin.UserDAuthPrivateKey != null) { Application.ActualUserPrivateKey = serverPacketUserLogin.UserDAuthPrivateKey; PerformSegue("DAuthLoginSegue", this); return; } //load user pets Application.PetManager.LoadUserPetList(serverPacketUserLogin.UserProfile); //instantiate main view controller UIStoryboard mainBoard = UIStoryboard.FromName("Main", null); MainTabBarController mainTabBarController = mainBoard.InstantiateViewController("MainTabBarController") as MainTabBarController; PresentViewController(mainTabBarController, true, null); } else { PerformSegue("ConnectConfirmAccountSegue", this); } return; } //chose right error message String messageError = string.Empty; switch (serverPacketUserLogin.NetworkError) { case NetworkError.GLOBAL_UNKNOWN: goto default; case NetworkError.SQL_USER_UNKNOWN: messageError = "Utilisateur ou mot de passe incorect"; break; case NetworkError.SERVER_UNAVAILABLE: messageError = MSGBank.ERROR_NO_SERVER; break; default: messageError = MSGBank.ERROR_UNKNOWN; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError, 5); //ßMessageBox.ShowOK(MSGBank.ERROR_TITLE, messageError, this); }
/// <summary> /// Register this instance. /// </summary> void Register() { //if fields are empty if (String.IsNullOrEmpty(tfNickNameField.Text) || String.IsNullOrEmpty(tfEmailField.Text) || String.IsNullOrEmpty(tfPasswordField.Text)) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS); return; } //if invalid email if (!tfEmailField.Text.IsValidEmail()) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_WRONG_EMAIL); return; } //if not same password if (tfPasswordField.Text != tfPasswordConfirmField.Text) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_NOT_SAME_PASSWORD); return; } //init new user with register properties PLFUser user = new PLFUser(); user.UserName = tfNameField.Text; user.UserSurname = tfSurnameField.Text; user.UserEMail = tfEmailField.Text; user.UserNickName = tfNickNameField.Text; //send register packet ServerPacketUserRegister serverPacketUserRegister = ServerHelper.RegisterUser(user, tfPasswordField.Text); //if register success if (serverPacketUserRegister.RegisterSuccess) { //Set user id with received user id user.ID = serverPacketUserRegister.UserID; //set the actual user Application.ActualUser = user; Application.UserPassword = tfPasswordField.Text; //load user pet list Application.PetManager.LoadUserPetList(user); BarHelper.DisplayInfoBar(uivMainView, "Inscription", $"Super ! Vous vous êtes bien inscrit sous le nom de {user.UserNickName} !", 3, delegate { ConnectionHelper.SaveConnectionProfile(tfNickNameField.Text, tfPasswordField.Text); PerformSegue("RegisterConfirmAccountSegue", this); //reset register fields tfNameField.Text = string.Empty; tfSurnameField.Text = string.Empty; tfEmailField.Text = string.Empty; tfNickNameField.Text = string.Empty; tfPasswordField.Text = string.Empty; tfPasswordConfirmField.Text = string.Empty; }, delegate { ConnectionHelper.SaveConnectionProfile(tfNickNameField.Text, tfPasswordField.Text); PerformSegue("RegisterConfirmAccountSegue", this); //reset register fields tfNameField.Text = string.Empty; tfSurnameField.Text = string.Empty; tfEmailField.Text = string.Empty; tfNickNameField.Text = string.Empty; tfPasswordField.Text = string.Empty; tfPasswordConfirmField.Text = string.Empty; }); return; } //chose right error message String messageError = string.Empty; switch (serverPacketUserRegister.NetworkError) { case NetworkError.GLOBAL_UNKNOWN: goto default; case NetworkError.SERVER_UNAVAILABLE: messageError = MSGBank.ERROR_NO_SERVER; break; case NetworkError.SQL_USER_EXIST: messageError = "Ce nom d'utilisateur est deja pris !"; break; default: messageError = MSGBank.ERROR_UNKNOWN; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError); }