Ejemplo n.º 1
0
        public ResponseFront Inscription([FromBody] RequestFrontInscription request)
        {
            Bdd bdd = DataBaseConnection.databaseConnection();

            #region Critères d'acceptances
            //On test les critères d'acceptances de l'Email / Password / Pseudo

            //Test de la taille de MDP
            if (request.registerAccount.registerPassword.Length < CONST.MINIMUM_PASSWORD_LENGTH)
            {
                responseFront.hasError = false;
                responseFront.response = RegisterEnum.passwordNoMinLength;
                return(responseFront);
            }

            //Test de la taille du PSEUDO
            if (request.registerUser.registerNickname.Length > CONST.MAXIMUM_NICKNAME_LENGTH)
            {
                responseFront.hasError = false;
                responseFront.response = RegisterEnum.nicknameMaxLength;
                return(responseFront);
            }

            //Test du contenu du PSEUDO (mots interdis)
            //string[] listeMotsInterdis = CONST.MOTS_INTERDIS.Split('|');
            bool          test = false;
            List <String> listeMotsInterdits = bdd.RetrieveListOfForbiddenWord();

            for (int i = 0; i < listeMotsInterdits.Count(); i++)
            {
                string motInterditNormaliser = listeMotsInterdits[i].ToString().ToLower();
                string pseudoNormaliser      = request.registerUser.registerNickname.ToLower();
                if (pseudoNormaliser.Contains(motInterditNormaliser))
                {
                    test = true;
                }
            }

            if (test)
            {
                responseFront.hasError = false;
                responseFront.response = RegisterEnum.nicknameWordForbidden;
                return(responseFront);
            }

            //Test de la validation d'une adresse Email
            if (!request.registerAccount.registerEmail.Contains("@"))
            {
                responseFront.hasError = false;
                responseFront.response = RegisterEnum.mailInvalid;
                return(responseFront);
            }

            //Test si le PSEUDO contient plus de 2 espaces
            if (request.registerUser.registerNickname.Contains("  "))
            {
                responseFront.hasError = false;
                responseFront.response = RegisterEnum.nicknameTwoSpaces;
                return(responseFront);
            }

            //Test si le PSEUDO contient plus de 2 -
            if (request.registerUser.registerNickname.Contains("--"))
            {
                responseFront.hasError = false;
                responseFront.response = RegisterEnum.nicknameTwoDashes;
                return(responseFront);
            }
            #endregion

            #region Cryptage du MDP et de l'Email
            string mdpCrypt            = ShaHash.GetShaHash(request.registerAccount.registerPassword);
            string concatPasswordKeys  = String.Concat(CONST.KEY_CRYPTAGE, mdpCrypt, CONST.KEY_CRYPTAGE);
            string stringPasswordCrypt = ShaHash.GetShaHash(concatPasswordKeys);

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

            request.registerAccount.registerPassword = stringPasswordCrypt;
            request.registerAccount.registerEmail    = stringEmailCrypt;
            #endregion

            //Test si l'adresse Email existe ou non
            if (bdd.TestIfEmailExist(request.registerAccount.registerEmail))
            {
                responseFront.hasError = false;
                responseFront.response = RegisterEnum.mailAlreadyExist;
                return(responseFront);
            }

            try
            {
                request.registerUser.registerNickname = request.registerUser.registerNickname[0].ToString().ToUpper() + request.registerUser.registerNickname.Substring(1).ToLower();
                bool estInscrit = bdd.Registration(request);
                responseFront.response = RegisterEnum.ok;
                return(responseFront);
            }catch (Exception e)
            {
                log.Warn("Erreur durant l'inscription : " + e.Message);
                responseFront.hasError = true;
                responseFront.error    = RegisterEnum.nok;
                return(responseFront);
            }
        }
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);
            }
        }