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); }
public void UpdateSessionExpiration(string sessionToken, DateTime expiration) { Session session = new Session { Token = sessionToken, Expiration = expiration }; SessionRepository.UpdateExpiration(session); }
public void ExpireSession(string sessionToken) { Session session = new Session { Token = sessionToken, Expiration = new DateTime(1900, 1, 1) }; SessionRepository.UpdateExpiration(session); }
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; }); }
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; }); }
public Session CreateSession(Session session) { return SessionRepository.CreateSession(session); }
public User GetUserBySessionToken(Session session) { return _userRepository.GetUserBySessionToken(session); }