コード例 #1
0
 public void Apply(Theme t)
 {
     t.Name         = Name;
     t.Banner       = Banner;
     t.Stylesheet   = Stylesheet;
     t.LoginBanners = LoginBanners.Clean();
     t.LoginInfos   = LoginInfos.Clean();
     t.CustomLogin  = CustomLogin;
     t.CustomSite   = CustomSite;
     if (null != ColorNames && null != ColorValues)
     {
         t.Colors = new Dictionary <string, string>();
         for (var i = 0; i < ColorNames.Length; i++)
         {
             t.Colors.Add(ColorNames[i], ColorValues[i]);
         }
     }
     if (null != FontNames && null != FontValues)
     {
         t.Fonts = new Dictionary <string, ThemeFont>();
         for (var i = 0; i < FontNames.Length; i++)
         {
             t.Fonts.Add(FontNames[i], FontValues[i]);
         }
     }
     if (null != BoxNames && null != BoxValues)
     {
         t.Boxes = new Dictionary <string, ThemeBox>();
         for (var i = 0; i < BoxNames.Length; i++)
         {
             t.Boxes.Add(BoxNames[i], BoxValues[i]);
         }
     }
 }
コード例 #2
0
        public async Task <IActionResult> Login([FromBody] LoginInfos content)
        {
            string login    = content.login;
            string password = content.password;

            Console.WriteLine("");
            Utilisateur res = await dbConnector.UserAuthentification(login, password);

            if (res == null)
            {
                return(NotFound());
            }
            Random reng  = new Random();
            int    token = reng.Next(0, 1234567998);

            _users.TryAdd(token + "", res);
            return(Ok(new { token }));
        }
コード例 #3
0
        async Task <HttpResponseMessage> login(User userRequest)
        {
            LoginInfos          loginInfos   = new LoginInfos();
            HttpResponseMessage response     = new HttpResponseMessage();
            HttpResponseMessage unauthorized = Request.CreateErrorResponse(HttpStatusCode.Forbidden, new UnauthorizedAccessException());

            if (loginInfos.userExists(userRequest))
            {
                User userDB = loginInfos.getUserFromRequest(userRequest);

                string passwordDB     = userDB.password;
                int    nbTentativesDB = userDB.nbTentatives;
                var    filter         = Builders <User> .Filter.Eq(u => u.login, userDB.login);


                if (nbTentativesDB == 5)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, new Exception("Nombre de tentatives > 5. Réinitialisez le mot de passe.")));
                }

                if (!loginInfos.isGoodPassword(userRequest.password, userDB.password))
                {
                    userDB.nbTentatives++;
                    await _collection.ReplaceOneAsync(filter, userDB);

                    return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, new Exception("Mot de passe erroné, Nombre de tentatives restantes : " + (4 - nbTentativesDB).ToString() + ".")));
                }

                userDB.nbTentatives = 0;
                await _collection.ReplaceOneAsync(filter, userDB);

                response.Headers.AddCookies(new CookieHeaderValue[] {
                    createCookie("timeout", DateTime.Now.AddHours(4).ToString()),
                    createCookie("login", userRequest.login)
                });

                response.Content    = new StringContent(userRequest.login + " connecté avec succès.");
                response.StatusCode = HttpStatusCode.OK;
                return(response);
            }
            return(unauthorized);
        }
コード例 #4
0
        HttpResponseMessage signin(User userRequest)
        {
            LoginInfos          loginInfos = new LoginInfos();
            HttpResponseMessage response   = new HttpResponseMessage();

            if (loginInfos.userExists(userRequest))
            {
                response.Content    = new StringContent("Le user " + userRequest.login + " est déjà connu dans la base de données.");
                response.StatusCode = HttpStatusCode.OK;
            }
            else
            {
                response.Content         = new StringContent("L'utilisateur " + userRequest.login + " a été créé.");
                response.StatusCode      = HttpStatusCode.Created;
                userRequest._id          = Guid.NewGuid().ToString();
                userRequest.nbTentatives = 0;
                userRequest.password     = loginInfos.encrypt(userRequest.password);
                _collection.InsertOne(userRequest);
            }
            return(response);
        }
コード例 #5
0
        public HttpResponseMessage CreateCentrale(Centrale centraleRequest)
        {
            LoginInfos loginInfos = new LoginInfos();

            if (!isSessionExpired())
            {
                if (ModelState.IsValid)
                {
                    _centrale = new utils.MongoDB().getCollection <Centrale>("Centrale");
                    _stock    = new utils.MongoDB().getCollection <Stock>("Stock");

                    return(create(centraleRequest));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, new Exception("Session expirée, merci de vous reconnecter.")));
            }
        }