Ejemplo n.º 1
0
 private static RememberedSessions TryGetRememberedSession(EpidaurusDbContainer db, HttpCookieCollection requestCookies)
 {
     var cookie = requestCookies.Get(CookieName);
     if (cookie == null || string.IsNullOrEmpty(cookie.Value))
         return null;
     var match = Regex.Match(cookie.Value, @"^(.+)_([0-9a-f-]+)$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
     if (!match.Success)
         return null;
     string userName = match.Groups[1].Value;
     Guid guid;
     if (!Guid.TryParse(match.Groups[2].Value, out guid))
         return null;
     string guidStr = guid.ToString();
     return db.RememberedSessions.FirstOrDefault(el => el.User.Username == userName && el.GuidHash == guidStr);
 }
Ejemplo n.º 2
0
        private static void LoginUser(EpidaurusDbContainer db, User user)
        {
            user.LastLogin = DateTime.Now;
            db.SaveChanges();

            var roles = user.Roles.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
            var principal = new EpiPrincipal(user.Username, roles);
            SetCurrentPrincipal(principal);
            _log.Trace("Loginuser: User: {0} Roles: {1}", user.Username, user.Roles);
        }