public ServerPacketUserLogin(NetworkError.NetworkError networkError, PLFUser userProfile, Boolean userAccountActivate, byte[] userDAuthPrivateKey) : base(PacketType.SERVERPACKETUSERLOGIN)
 {
     this.networkError        = networkError;
     this.userProfile         = userProfile;
     this.userAccountActivate = userAccountActivate;
     this.userDAuthPrivateKey = userDAuthPrivateKey;
 }
Exemple #2
0
        static void Main(string[] args)
        {
            while (true)
            {
                String typed = Console.ReadLine();
                //if ping query
                if (typed == "ping")
                {
                    long             actualTime = DateTime.UtcNow.Ticks;
                    ClientPacketPing clientPing = new ClientPacketPing(actualTime);

                    Packet answer = SendPacket(NetworkHelper.SerializePacket(clientPing));

                    Console.WriteLine("Answer:" + answer);

                    ServerPacketPing serverPing = answer as ServerPacketPing;

                    if (serverPing == null)
                    {
                        break;
                    }

                    Console.WriteLine("Packet infos: " + serverPing.PacketSendTime);
                    long answerTime = serverPing.PacketSendTime;
                    Console.WriteLine("Ping : " + ((answerTime - actualTime) / 1000) + " ticks");
                }

                if (typed == "user")
                {
                    PLFUser newUser = new PLFUser();
                    newUser.UserNickName = "UserTest";
                    newUser.UserName     = "******";
                    newUser.UserSurname  = "UserTest Surname";
                    newUser.UserEMail    = "*****@*****.**";

                    ClientPacketUserRegister clientPacketUserRegister = new ClientPacketUserRegister(newUser, "mdp");

                    Packet answer = SendPacket(NetworkHelper.SerializePacket(clientPacketUserRegister));

                    Console.WriteLine("Answer:" + answer);

                    ServerPacketUserRegister serverPacketUserRegister = answer as ServerPacketUserRegister;

                    if (serverPacketUserRegister == null)
                    {
                        break;
                    }


                    int userID = serverPacketUserRegister.UserID;
                    Console.WriteLine(
                        $"Register: {serverPacketUserRegister.RegisterSuccess} - {userID} - {serverPacketUserRegister.ErrorMessage}");
                }

                System.Threading.Thread.Sleep(1000);
                Console.ReadKey();
                Console.Clear();
            }
        }
Exemple #3
0
            public override void Selected(UIPickerView pickerView, nint row, nint component)
            {
                //Change selected user
                selectedUser = plfUsers[(int)row];

                //trigger event
                userChangeEvent?.Invoke(null, null);
            }
Exemple #4
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketUserUpdateProfile clientPacketUserUpdateProfile = receivedPacket as ClientPacketUserUpdateProfile;

            ConsoleHelper.Write("Receive - ClientPacketUserUpdateProfile");

            PLFUser user         = clientPacketUserUpdateProfile.User;
            String  userPassword = clientPacketUserUpdateProfile.UserPassword.ToSQL();

            //insert new profile into DB
            MySqlCommand updateUserProfileCommand = new MySqlCommand();

            updateUserProfileCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            updateUserProfileCommand.CommandText =
                $"UPDATE `T_User` SET `userPassword`='{userPassword}',`userName`='{user.UserName.ToSQL()}'," +
                $"`userSurname`='{user.UserSurname.ToSQL()}',`userEmail`='{user.UserEMail.ToSQL()}' WHERE `userID`='{user.ID}'";


            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                updateUserProfileCommand.ExecuteNonQuery();

                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
            }
            catch (MySqlException e)
            {
                Console.WriteLine(e.Number + " - " + e.Message);
                NetworkError networkError;
                switch (e.Number)
                {
                case 1062:
                    networkError = NetworkError.SQL_USER_EXIST;
                    break;

                case 1064:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;

                default:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;
                }
                serverPacketConfirmation = new ServerPacketConfirmation(false, networkError);
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
Exemple #5
0
 public static void SendRegisterConfirmationMail(PLFUser user, String userSecretKey)
 {
     new Thread(() =>
     {
         //send mail
         Program.mailManager.SendMail(user.UserEMail, "PET LA FORME - Inscription",
                                      $"Bonjour {user.UserName}! Merci de vous être inscrit sur la plateforme PetLaForme. Voici votre code d'activation de votre compte: "
                                      + $"{userSecretKey}. Merci de la rentrer dans votre application pour pouvoir activer votre compte ! Bonne journée !");
     }).Start();
 }
        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);
            }
        }
Exemple #7
0
        /// <summary>
        /// Disables the user DA uth.
        /// </summary>
        /// <returns>The user DA uth.</returns>
        /// <param name="plfUser">Plf user.</param>
        public static ServerPacketConfirmation DisableUserDAuth(PLFUser plfUser)
        {
            ClientPacketDisableDAuth clientPacketDisableDAuth = new ClientPacketDisableDAuth(plfUser);

            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketDisableDAuth) as ServerPacketConfirmation;

            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Exemple #8
0
        /// <summary>
        /// Asks the confirm user account.
        /// </summary>
        /// <returns>The confirm user account.</returns>
        /// <param name="user">User.</param>
        /// <param name="userPassword">User password.</param>
        public static ServerPacketConfirmation AskConfirmUserAccount(PLFUser user, String userPassword)
        {
            ClientPacketAskUserActivateAccout clientPacketAskUserActivateAccout = new ClientPacketAskUserActivateAccout(user, userPassword.HashSHA256());

            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketAskUserActivateAccout) as ServerPacketConfirmation;

            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Exemple #9
0
        /// <summary>
        /// Confirms the user account.
        /// </summary>
        /// <returns>The user account.</returns>
        /// <param name="user">User.</param>
        /// <param name="code">Code.</param>
        public static ServerPacketConfirmation ConfirmUserAccount(PLFUser user, String code)
        {
            ClientPacketUserActivateAccount clientPacketUserActivateAccount = new ClientPacketUserActivateAccount(user, code);

            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketUserActivateAccount) as ServerPacketConfirmation;

            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Exemple #10
0
        /// <summary>
        /// Inits the user picker.
        /// </summary>
        /// <param name="users">Users.</param>
        public void InitUserPicker(List <PLFUser> users)
        {
            //new picket model
            var userPickerModel = new PetTypePickerModel(users);

            //set picker view model
            pvUserPicker.Model = userPickerModel;

            //add event handler
            userPickerModel.userChangeEvent += (sender, e) =>
            {
                selectedUser = userPickerModel.selectedUser;
            };
        }
        public override void ViewDidLoad()
        {
            //populate fields with selected user properties
            PLFUser selectedUser = Application.ActualUser;

            //populate fields
            tfUserNickNameField.Text = selectedUser.UserNickName;
            tfUserSurnameField.Text  = selectedUser.UserSurname;
            tfUserNameField.Text     = selectedUser.UserName;
            tfUserEmailField.Text    = selectedUser.UserEMail;

            tfUserPasswordField.Text        = Application.UserPassword;
            tfUserPasswordConfirmField.Text = Application.UserPassword;

            //add event handlers
            tfUserNickNameField.ShouldReturn += (textField) =>
            {
                ((UITextField)textField).ResignFirstResponder();
                return(true);
            };
            tfUserSurnameField.ShouldReturn += (textField) =>
            {
                ((UITextField)textField).ResignFirstResponder();
                return(true);
            };
            tfUserNameField.ShouldReturn += (textField) =>
            {
                ((UITextField)textField).ResignFirstResponder();
                return(true);
            };
            tfUserEmailField.ShouldReturn += (textField) =>
            {
                ((UITextField)textField).ResignFirstResponder();
                return(true);
            };
            tfUserPasswordField.ShouldReturn += (textField) =>
            {
                ((UITextField)textField).ResignFirstResponder();
                tfUserPasswordConfirmField.BecomeFirstResponder();
                return(true);
            };
            tfUserPasswordConfirmField.ShouldReturn += (textField) =>
            {
                ((UITextField)textField).ResignFirstResponder();
                return(true);
            };
        }
Exemple #12
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            //get received packet
            ClientPacketEnableDAuth clientPacketEnableDAuth = receivedPacket as ClientPacketEnableDAuth;

            ConsoleHelper.Write("Receive - ClientPacketEnableDAuth");

            //read packet infos
            PLFUser user = clientPacketEnableDAuth.PlfUser;

            byte[] userPrivateKey = clientPacketEnableDAuth.UserPrivateKey;
            String userKey        = JsonConvert.SerializeObject(userPrivateKey);

            //insert key in db command
            MySqlCommand enableDAuthCommand = new MySqlCommand();

            enableDAuthCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            enableDAuthCommand.CommandText =
                $"INSERT INTO `T_DoubleAuth`(`daUserID`, `daUserKey`) VALUES ('{user.ID}','{userKey}')";

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                //execute command
                enableDAuthCommand.ExecuteNonQuery();

                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);

                //run on extern thread
                new Thread(() =>
                {
                    Program.mailManager.SendMail(user.UserEMail, "PET LA FORME - Double Authentification",
                                                 $"Bonjour {user.UserName}! La double authentification a bien été activée sur votre compte. ");
                }
                           ).Start();
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
Exemple #13
0
        /// <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);
        }
Exemple #14
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            //get received packet
            ClientPacketDisableDAuth clientPacketDisableDAuth = receivedPacket as ClientPacketDisableDAuth;

            ConsoleHelper.Write("Receive - ClientPacketDisableDAuth");

            //read packet infos
            PLFUser user = clientPacketDisableDAuth.PlfUser;

            //insert key in db command
            MySqlCommand disableDAuthCommand = new MySqlCommand();

            disableDAuthCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            disableDAuthCommand.CommandText =
                $"DELETE FROM `T_DoubleAuth` WHERE `daUserID`='{user.ID}'";

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                //execute command
                disableDAuthCommand.ExecuteNonQuery();

                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);

                //run on extern thread
                new Thread(() =>
                {
                    Program.mailManager.SendMail(user.UserEMail, "PET LA FORME - Double Authentification",
                                                 $"Bonjour {user.UserName}! La double authentification a bien été désactivée sur votre compte. ");
                }
                           ).Start();
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
Exemple #15
0
        /// <summary>
        /// Registers the user.
        /// </summary>
        /// <returns>The user.</returns>
        /// <param name="user">User.</param>
        /// <param name="userPassword">User password.</param>
        public static ServerPacketUserRegister RegisterUser(PLFUser user, String userPassword)
        {
            //hash user password
            String hashPassword = userPassword.HashSHA256();

            //new user register packet
            ClientPacketUserRegister clientPacketUserRegister = new ClientPacketUserRegister(user, hashPassword);

            //send packet to server
            ServerPacketUserRegister serverPacketUserRegister = TCPClient.SendPacket(clientPacketUserRegister) as ServerPacketUserRegister;

            //if no answer
            if (serverPacketUserRegister == null)
            {
                return(new ServerPacketUserRegister(false, -1, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketUserRegister);
        }
Exemple #16
0
        /// <summary>
        /// Adds the pet.
        /// </summary>
        /// <returns>The pet.</returns>
        /// <param name="user">User.</param>
        /// <param name="pet">Pet.</param>
        public static ServerPacketAddPet AddPet(PLFUser user, PLFPet pet)
        {
            //get user ID
            int userID = user.ID;

            //create new client add pet packet
            ClientPacketAddPet clientPacketAddPet = new ClientPacketAddPet(userID, pet);

            //send packet to server
            ServerPacketAddPet serverPacketAddPet = TCPClient.SendPacket(clientPacketAddPet) as ServerPacketAddPet;

            //if no answer
            if (serverPacketAddPet == null)
            {
                return(new ServerPacketAddPet(false, -1, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketAddPet);
        }
Exemple #17
0
        /// <summary>
        /// Shares the pet.
        /// </summary>
        /// <returns>The pet.</returns>
        /// <param name="user">User.</param>
        /// <param name="pet">Pet.</param>
        /// <param name="receiverUserName">Receiver user name.</param>
        /// <param name="sharePower">Share power.</param>
        public static ServerPacketConfirmation SharePet(PLFUser user, PLFPet pet, String receiverUserName, int sharePower)
        {
            //get user id
            int userID = user.ID;

            //create new packet share pet
            ClientPacketSharePet clientPacketSharePet = new ClientPacketSharePet(userID, pet.PetID, receiverUserName, sharePower);

            //send packet to the server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketSharePet) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Exemple #18
0
        /// <summary>
        /// Downloads the pets.
        /// </summary>
        /// <returns>The pets.</returns>
        /// <param name="user">User.</param>
        public static ServerPacketDownloadPets DownloadPets(PLFUser user)
        {
            //get user id
            int userID = user.ID;

            //create new packet download pets
            ClientPacketDownloadPets clientPacketDownloadPets = new ClientPacketDownloadPets(userID);

            //send packet to server
            ServerPacketDownloadPets serverPacketDownloadPets = TCPClient.SendPacket(clientPacketDownloadPets) as ServerPacketDownloadPets;

            //if no answer
            if (serverPacketDownloadPets == null)
            {
                return(new ServerPacketDownloadPets(new List <PLFPet>()));
            }

            return(serverPacketDownloadPets);
        }
Exemple #19
0
        /// <summary>
        /// Updates the user profile.
        /// </summary>
        /// <returns>The user profile.</returns>
        /// <param name="user">User.</param>
        /// <param name="userPassword">User password.</param>
        public static ServerPacketConfirmation UpdateUserProfile(PLFUser user, String userPassword)
        {
            //hash user profile
            String hashPassword = userPassword.HashSHA256();

            //create new user update profile packet
            ClientPacketUserUpdateProfile clientPacketUserUpdateProfile = new ClientPacketUserUpdateProfile(user, hashPassword);

            //send update packet to server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketUserUpdateProfile) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Exemple #20
0
        /// <summary>
        /// Deletes the pet.
        /// </summary>
        /// <returns>The pet.</returns>
        /// <param name="user">User.</param>
        /// <param name="pet">Pet.</param>
        public static ServerPacketConfirmation DeletePet(PLFUser user, PLFPet pet)
        {
            //get user and pet id
            int userID = user.ID;
            int petID  = pet.PetID;

            //new client delete pet
            ClientPacketDeletePet clientPacketDeletePet = new ClientPacketDeletePet(userID, petID);

            //send delete packet to the server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketDeletePet) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Exemple #21
0
        /// <summary>
        /// Downloads the pets identifier.
        /// </summary>
        /// <returns>The pets identifier.</returns>
        /// <param name="user">User.</param>
        public static ServerPacketDownloadPetsID DownloadPetsID(PLFUser user)
        {
            //get user id
            int userID = user.ID;

            //create new client packet download pets id
            ClientPacketDownloadPetsID clientPacketDownloadPetsID = new ClientPacketDownloadPetsID(userID);

            //send packet to the server
            ServerPacketDownloadPetsID serverPacketDownloadPetsID = TCPClient.SendPacket(clientPacketDownloadPetsID) as ServerPacketDownloadPetsID;

            //if null answer, return vanilla packet
            if (serverPacketDownloadPetsID == null)
            {
                return(new ServerPacketDownloadPetsID(new int[0], new int[0]));
            }

            //return packet
            return(serverPacketDownloadPetsID);
        }
Exemple #22
0
        /// <summary>
        /// Loads the user pet list.
        /// </summary>
        /// <param name="user">User.</param>
        public void LoadUserPetList(PLFUser user)
        {
            //clear actual petlist
            userPets.Clear();

            //send download pets id packet
            ServerPacketDownloadPetsID serverPacketDownloadPetsID = ServerHelper.DownloadPetsID(user);

            userPetsID = serverPacketDownloadPetsID.IdList;

            //foreach user own pets id
            foreach (var id in userPetsID)
            {
                //download pet infos from server
                PLFPet pet = ServerHelper.DownloadPet(id).Pet;

                //if pet isn't null
                if (pet != null)
                {
                    userPets.Add(pet);
                }
            }

            //get shared pets id
            int[] sharePetsId = serverPacketDownloadPetsID.SharedIdList;

            //foreach user share pets id
            foreach (var id in sharePetsId)
            {
                //download shared pet infos from server
                PLFPet pet = ServerHelper.DownloadPet(id, true).Pet;

                //if pet isn't null
                if (pet != null)
                {
                    userPets.Add(pet);
                }
            }
        }
Exemple #23
0
        public static PLFUser GetUserProfile(String userNick)
        {
            //get user profile command
            MySqlCommand downloadUserProfileCommand = new MySqlCommand();

            downloadUserProfileCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            downloadUserProfileCommand.CommandText = $"SELECT * FROM `T_User` WHERE userNick='{userNick}'";

            MySqlDataReader mysqlDataReader = null;

            PLFUser user = null;

            try
            {
                //execute reader
                mysqlDataReader = downloadUserProfileCommand.ExecuteReader();

                //open reader
                while (mysqlDataReader.Read())
                {
                    user = new PLFUser(mysqlDataReader.GetInt32(0), mysqlDataReader.GetString(2), mysqlDataReader.GetString(3), mysqlDataReader.GetString(4), mysqlDataReader.GetString(5));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //Close reader
            if (mysqlDataReader != null && !mysqlDataReader.IsClosed)
            {
                mysqlDataReader.Close();
            }

            return(user);
        }
Exemple #24
0
        String userPassword;        //user password

        public ClientPacketUserUpdateProfile(PLFUser user, String userPassword) : base(PacketType.CLIENTPACKETUSERUPDATEPROFILE)
        {
            this.user         = user;
            this.userPassword = userPassword;
        }
Exemple #25
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketUserActivateAccount clientPacketUserActivateAccount = receivedPacket as ClientPacketUserActivateAccount;

            ConsoleHelper.Write("Receive - ClientPacketUserActivateAccount");

            PLFUser user    = clientPacketUserActivateAccount.User;
            String  userKey = clientPacketUserActivateAccount.UserCode.ToSQL();

            //insert new profile into DB
            MySqlCommand checkActivationCodeCommabd = new MySqlCommand();

            checkActivationCodeCommabd.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            checkActivationCodeCommabd.CommandText =
                $"SELECT * FROM `T_RegisterKey` WHERE `regUserMail`='{user.UserEMail}' AND `regKey`='{userKey}'";

            MySqlDataReader mysqlDataReader = null;

            ServerPacketConfirmation serverPacketConfirmation;

            Boolean confirmationAllow = false;

            try
            {
                mysqlDataReader = checkActivationCodeCommabd.ExecuteReader();

                //open reader
                while (mysqlDataReader.Read())
                {
                    confirmationAllow = true;
                }

                if (confirmationAllow)
                {
                    serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
                    new Thread(() =>
                    {
                        Program.mailManager.SendMail(user.UserEMail, "PET LA FORME - Inscription",
                                                     $"Bonjour {user.UserName}! Votre compte a été confirmé avec succés ! Bonne journée !");
                    }
                               ).Start();
                }
                else
                {
                    serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.SQL_USER_WRONG_ACCODE);
                }
            }
            catch (MySqlException e)
            {
                Console.WriteLine(e.Number + " - " + e.Message);
                NetworkError networkError;
                switch (e.Number)
                {
                case 1062:
                    networkError = NetworkError.SQL_USER_WRONG_ACCODE;
                    break;

                case 1064:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;

                default:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;
                }
                serverPacketConfirmation = new ServerPacketConfirmation(false, networkError);
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            if (mysqlDataReader != null && !mysqlDataReader.IsClosed)
            {
                mysqlDataReader.Close();
            }

            if (confirmationAllow)
            {
                MySqlCommand activeAccountCommand = new MySqlCommand();
                activeAccountCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
                activeAccountCommand.CommandText =
                    $"UPDATE `T_User` SET `userAccountActive`='1' WHERE `userID`='{user.ID}'";
                activeAccountCommand.ExecuteNonQuery();
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketAskUserActivateAccout clientPacketAskUserActivateAccout = receivedPacket as ClientPacketAskUserActivateAccout;

            ConsoleHelper.Write("Receive - ClientPacketAskUserActivateAccout");

            PLFUser user          = clientPacketAskUserActivateAccout.User;
            String  userPassword  = clientPacketAskUserActivateAccout.UserPassword.ToSQL();
            String  userSecretKey = KeyHelper.CreateRandomKey();

            //insert new profile into DB
            MySqlCommand checkUserIdentityCommand = new MySqlCommand();

            checkUserIdentityCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            checkUserIdentityCommand.CommandText =
                $"SELECT * FROM `T_User` WHERE userNick='{user.UserNickName}' AND userPassword='******'";

            PLFUser downloadedUser = null;

            MySqlDataReader mysqlDataReader = null;

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                mysqlDataReader = checkUserIdentityCommand.ExecuteReader();

                //open reader
                while (mysqlDataReader.Read())
                {
                    downloadedUser = new PLFUser(mysqlDataReader.GetInt32(0), mysqlDataReader.GetString(2), mysqlDataReader.GetString(3), mysqlDataReader.GetString(4), mysqlDataReader.GetString(5));
                }

                if (mysqlDataReader != null && !mysqlDataReader.IsClosed)
                {
                    mysqlDataReader.Close();
                }

                if (downloadedUser != null)
                {
                    //insert new profile into DB
                    MySqlCommand registerNewConfirmKey = new MySqlCommand();
                    registerNewConfirmKey.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
                    registerNewConfirmKey.CommandText =
                        $"DELETE FROM `T_RegisterKey` WHERE `regUserMail`='{downloadedUser.UserEMail}';" +
                        $"INSERT INTO `T_RegisterKey`(`regUserMail`, `regKey`, `regKeyDeliver`) VALUES ('{downloadedUser.UserEMail}','{userSecretKey}','{DateTime.Now.Ticks}');";

                    registerNewConfirmKey.ExecuteNonQuery();
                    new Thread(() =>
                    {
                        Program.mailManager.SendMail(downloadedUser.UserEMail, "PET LA FORME - Confirmation",
                                                     $"Bonjour {downloadedUser.UserName}! Voici votre code d'activation de votre compte: "
                                                     + $"{userSecretKey}. Merci de la rentrer dans votre application pour pouvoir activer votre compte ! Bonne journée !");
                    }
                               ).Start();

                    serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
                }
                else
                {
                    serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.SQL_USER_UNKNOWN);
                }
            }
            catch (MySqlException e)
            {
                Console.WriteLine(e.Number + " - " + e.Message);
                NetworkError networkError;
                switch (e.Number)
                {
                case 1062:
                    networkError = NetworkError.SQL_USER_EXIST;
                    break;

                case 1064:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;

                default:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;
                }
                serverPacketConfirmation = new ServerPacketConfirmation(false, networkError);
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
Exemple #27
0
 public ClientPacketAskUserActivateAccout(PLFUser user, String userPassword) : base(PacketType.CLIENTPACKETASKACTIVEACCOUNT)
 {
     this.user         = user;
     this.userPassword = userPassword;
 }
        String userPassword;            //user password

        public ClientPacketUserRegister(PLFUser user, String userPassword) : base(PacketType.CLIENTPACKETUSERREGISTER)
        {
            this.user         = user;
            this.userPassword = userPassword;
        }
 public ClientPacketEnableDAuth(PLFUser plfUser, byte[] userPrivateKey) : base(PacketType.CLIENTPACKETENABLEDAUTH)
 {
     this.plfUser        = plfUser;
     this.userPrivateKey = userPrivateKey;
 }
Exemple #30
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);
        }