Ejemplo n.º 1
0
        public Banishment TestIfUserBan(int idAccount)
        {
            stopwatch.Start();


            try
            {
                Banishment banishment = new Banishment();

                string queryIfBanned = nameBdd.testIfUserBan(idAccount);

                if (this.OpenConnection() == true)
                {
                    MySqlCommand    cmd        = new MySqlCommand(queryIfBanned, connection);
                    MySqlDataReader dataReader = cmd.ExecuteReader();

                    while (dataReader.Read())
                    {
                        banishment.hasBanned = true;
                        banishment.start     = nameBdd.banishmentStart(dataReader);
                        banishment.during    = nameBdd.banishmentDuring(dataReader);
                        banishment.end       = nameBdd.banishmentEnd(dataReader);
                        banishment.reason    = nameBdd.banishmentReason(dataReader);
                    }

                    dataReader.Close();

                    this.CloseConnection();

                    stopwatch.Stop();
                    log.Info("api.CONNECTION.TestIfUserBan ... (" + stopwatch.Elapsed.TotalSeconds + " ms)");
                    return(banishment);
                }
                else
                {
                    return(banishment);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(null);
            }
        }
Ejemplo n.º 2
0
        public ResponseFront Connection([FromBody] RequestFrontConnexion request)
        {
            log.Info("api.Connection ...");

            Bdd        bdd        = DataBaseConnection.databaseConnection();
            Banishment banishment = new Banishment();

            string mdpCrypt            = ShaHash.GetShaHash(request.password);
            string concatPasswordKeys  = String.Concat(CONST.KEY_CRYPTAGE, mdpCrypt, CONST.KEY_CRYPTAGE);
            string stringPasswordCrypt = ShaHash.GetShaHash(concatPasswordKeys);

            string emailCrypt       = ShaHash.GetShaHash(request.email);
            string concatEmailKeys  = String.Concat(CONST.KEY_CRYPTAGE, emailCrypt, CONST.KEY_CRYPTAGE);
            string stringEmailCrypt = ShaHash.GetShaHash(concatEmailKeys);

            request.password = stringPasswordCrypt;
            request.email    = stringEmailCrypt;

            try
            {
                int exist = bdd.Connection(request);

                if (exist == 0)
                {
                    log.Info("Compte introuvable en BDD");
                    responseFront.hasError = true;
                    responseFront.error    = MSG.COMPTE_INTROUVABLE;
                    return(responseFront);
                }

                int idAccount = bdd.RetrieveIdAccount(request);

                banishment = bdd.TestIfUserBan(idAccount);

                banishment.endFormalize = banishment.end.ToString("dd.MM.yyyy-HH:mm:ss");

                if (banishment.hasBanned)
                {
                    log.Info(MSG.COMPTE_BANNI);
                    responseFront.hasError = true;
                    responseFront.error    = banishment;
                    return(responseFront);
                }

                string tokenClient = GenerateToken.generationToken(CONST.TOKEN_SIZE);
                string tokenServer = GenerateToken.generationToken(CONST.TOKEN_SIZE);

                bdd.InsertToken(idAccount, tokenServer, tokenClient);
                bdd.NowOnline(idAccount);

                log.Info("Utilisateur #" + idAccount + " vient de connecter");

                responseFront.response = tokenClient;
                return(responseFront);
            }
            catch (Exception e)
            {
                log.Error("Erreur durant la connexion", e);
                responseFront.hasError = true;
                responseFront.error    = MSG.CONNEXION_IMPOSSIBLE;
                return(responseFront);
            }
        }