コード例 #1
0
        public void UpdateSession(Sessionm session)
        {
            Sessionm sessionToUpdate = _dbContext.Sessionm.Find(session.id_session);

            if (session.token_session != sessionToUpdate.token_session)
            {
                sessionToUpdate.token_session = session.token_session;
            }

            _dbContext.Entry(sessionToUpdate).State = EntityState.Modified;
            Save();
        }
コード例 #2
0
 public IActionResult Post([FromBody] Login login)
 {
     try
     {
         var userGot = _userRepository.GetUserByEmail(login.email);
         if (userGot != null)
         {
             if (_userRepository.CheckMatch(userGot.passhash_user, login.password) && _userRepository.CheckLDAP(login.email, login.password))
             {
                 var      jwt        = new JwtService(_config);
                 var      token      = jwt.GenerateSecurityToken(userGot);
                 Sessionm newSession = new Sessionm();
                 newSession.id_session    = userGot.id_user;
                 newSession.token_session = token;
                 using (var scope = new TransactionScope())
                 {
                     var alreadySession = _sessionRepository.GetSessionById(userGot.id_user);
                     if (alreadySession != null)
                     {
                         _sessionRepository.DeleteSession(userGot.id_user);
                     }
                     _sessionRepository.InsertSession(newSession);
                     scope.Complete();
                 }
                 return(new OkObjectResult(newSession));
             }
             else
             {
                 return(new NotFoundResult());
             }
         }
         else
         {
             return(new NotFoundResult());
         }
     }
     catch (Exception)
     {
         return(new StatusCodeResult(500));
     }
 }
コード例 #3
0
 public void InsertSession(Sessionm session)
 {
     _dbContext.Add(session);
     Save();
 }