partial void BtnAskForNewCode_TouchUpInside(UIButton sender)
        {
            //send packet to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.AskConfirmUserAccount(Application.ActualUser, Application.UserPassword);

            //if success
            if (serverPacketConfirmation.ActionSuccess)
            {
                BarHelper.DisplayInfoBar(uivMainView, "Compte", $"Un nouveau code d'activation a été envoyé par mail à  {Application.ActualUser.UserEMail}.", 10,
                                         delegate { tfConfirmationCodeField.BecomeFirstResponder(); btnAskForNewCode.Enabled = false; },
                                         delegate { tfConfirmationCodeField.BecomeFirstResponder(); 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;

            default:
                messageError = MSGBank.ERROR_UNKNOWN;
                break;
            }

            MessageBox.ShowOK(MSGBank.ERROR_TITLE, messageError, this);
        }
        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 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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        /// <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);
        }