public Session Login(LoginCredentials credentials) { if (auth.ValidateCredentials(credentials.Email, credentials.Pwd)) { var user = userDA.GetOneByEmail(credentials.Email); var userSession = sessionDA.GetAll().Where(s => s.UserID == user.Id).FirstOrDefault(); Session session = null; if (userSession != null && auth.ValidateToken(userSession.Token)) { session = userSession; } else { session = new Session(user); } sessionDA.Insert(session); sessionDA.SaveChanges(); return session; } else { throw new WebFaultException(System.Net.HttpStatusCode.Unauthorized); } }
/// <summary> /// Gets the current session from the database /// </summary> /// <returns>The current session from the database, or null if sessionGUID is not specified</returns> public Core.Data.Model.Session GetSessionFromDatabase() { if (_session == null) { if (Parameters == null) return null; if (!Parameters.ContainsKey(SessionguidParameterName)) return null; _session = PortalRepository.SessionGet(new Guid(Parameters[SessionguidParameterName]), null).FirstOrDefault(); if (_session == null) return null; } return _session; }
public void ClearCache() { _session = null; }