public User GetUserBySessionToken(Session session) { if (session == null) throw new ArgumentNullException("session"); return GetUserBySessionToken(session.SessionToken); }
public Session CreateSession(Session session) { return SqlQueryExecutor.Exceute(() => { String query = string.Format(CultureInfo.InvariantCulture, "INSERT INTO {1} {0}; SELECT LAST_INSERT_ID();", InsertFieldList, TableName); int insertedId = (int)Connectionprovider.CurrentConnection.Query<long>(query, new { session.UserId, session.SessionToken, session.SessionAntiforgeryToken, session.Expiration }).FirstOrDefault(); if (insertedId <= 0) throw new StorageMonsterDbException("Session insertion failed"); session.Id = insertedId; return session; }); }
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 = UserRepository.GetByEmail(email); if (user ==null) throw new StorageMonsterSecurityException(String.Format(CultureInfo.InvariantCulture, "User {0} not found", email)); Session session = new Session { UserId = user.Id, SessionToken = sessionToken, SessionAntiforgeryToken = sessionAntiforgeryToken }; var cookie = CreateAuthCookie(email, sessionToken, createPersistentCookie); if (createPersistentCookie) session.Expiration = cookie.Expires.ToUniversalTime(); ServiceRepository.CreateSession(session); HttpContext.Current.Response.Cookies.Add(cookie); }