Example #1
0
        /// <summary>
        /// Enables the user DA uth.
        /// </summary>
        /// <returns>The user DA uth.</returns>
        /// <param name="plfUser">Plf user.</param>
        /// <param name="privateKey">Private key.</param>
        public static ServerPacketConfirmation EnableUserDAuth(PLFUser plfUser, byte[] privateKey)
        {
            ClientPacketEnableDAuth clientPacketEnableDAuth = new ClientPacketEnableDAuth(plfUser, privateKey);

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

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

            return(serverPacketConfirmation);
        }
Example #2
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);
        }