Пример #1
0
        public User GetUserBySessionToken(Session session)
        {
            if (session == null)
                throw new ArgumentNullException("session");

            return GetUserBySessionToken(session.Token);
        }
        public void SignIn(string email, bool createPersistentCookie)
        {
            string sessionToken = Guid.NewGuid().ToString("N",CultureInfo.InvariantCulture);
            string sessionAntiforgeryToken = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);

            User user = _userService.GetUserByEmail(email);
            if (user ==null)
                throw new MonsterSecurityException(String.Format(CultureInfo.InvariantCulture, "User {0} not found", email));

            Session session = new Session
                {
                    UserId = user.Id,
                    Token = sessionToken
                };

            DateTime expiration;
            var cookie = CreateAuthCookie(email, sessionToken, createPersistentCookie, out expiration);

            session.Expiration = expiration;

            if (!_webConfiguration.AllowMultipleLogons)
                _sessionService.ClearUserSessions(user.Id);

            _sessionService.CreateSession(session);

            HttpContext.Current.Response.Cookies.Add(cookie);
        }
Пример #3
0
 public void UpdateSessionExpiration(string sessionToken, DateTime expiration)
 {
     Session session = new Session
     {
         Token = sessionToken,
         Expiration = expiration
     };
     SessionRepository.UpdateExpiration(session);
 }
Пример #4
0
 public void ExpireSession(string sessionToken)
 {
     Session session = new Session
     {
         Token = sessionToken,
         Expiration = new DateTime(1900, 1, 1)
     };
     SessionRepository.UpdateExpiration(session);
 }
Пример #5
0
        public Session UpdateExpiration(Session session)
        {
            if (session == null)
                throw new ArgumentNullException("session");

            return SqlQueryExecutor.Execute(() =>
            {
                String query = string.Format(CultureInfo.InvariantCulture, "UPDATE {0} SET expiration_date=@Expiration WHERE Id=@Id OR session_token=@Token", TableName);
                _connectionProvider.CurrentConnection.Execute(query, new { session.Id, session.Token, session.Expiration });

                return session;
            });
        }
Пример #6
0
        public Session CreateSession(Session session)
        {
            return SqlQueryExecutor.Execute(() =>
            {
                String query = string.Format(CultureInfo.InvariantCulture, "INSERT INTO {1} {0} RETURNING id;", InsertFieldList, TableName);
                int insertedId = _connectionProvider.CurrentConnection.Query<int>(query, new { session.UserId, session.Token, session.Expiration }).FirstOrDefault();
                if (insertedId <= 0)
                    throw new MonsterDbException("Session insertion failed");

                session.Id = insertedId;
                return session;
            });
        }
Пример #7
0
 public Session CreateSession(Session session)
 {
     return SessionRepository.CreateSession(session);
 }
Пример #8
0
 public User GetUserBySessionToken(Session session)
 {
     return _userRepository.GetUserBySessionToken(session);
 }