Example #1
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);
        }
Example #2
0
        private static void SetCurrentPrincipal(EpiPrincipal principal)
        {
            FormsAuthentication.SetAuthCookie(principal.Identity.Name, true);

            var ticket = new FormsAuthenticationTicket(1,
              principal.Identity.Name,
              DateTime.Now,
              DateTime.Now.AddMinutes(120),
              false,
              principal.RolesList,
              FormsAuthentication.FormsCookiePath);

            string encTicket = FormsAuthentication.Encrypt(ticket);

            HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
            HttpContext.Current.User = principal;
            Thread.CurrentPrincipal = principal;
        }
Example #3
0
 public static void TryLoadCurrentPrincipalFromCookies()
 {
     var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
     if (authCookie != null)
     {
         var authTicket = FormsAuthentication.Decrypt(authCookie.Value);
         string[] roles = authTicket.UserData.Split(new Char[] { ',' });
         EpiPrincipal userPrincipal = new EpiPrincipal(authTicket.Name, roles);
         HttpContext.Current.User = userPrincipal;
         Thread.CurrentPrincipal = userPrincipal;
     }
 }