Exemple #1
0
 /// <summary>
 /// This checks the current identity is a UmbracoBackOfficeIdentity, if so, it updates its roles and re-sets the cookie
 /// if we are in an HttpContext.
 /// </summary>
 /// <param name="roleNames">The role names.</param>
 /// <param name="userNames">The user names.</param>
 private static void AddRolesToCurrentIdentity(IEnumerable <string> roleNames, IEnumerable <string> userNames = null)
 {
     //remove the current role from the user data
     if (Thread.CurrentPrincipal.Identity is UmbracoBackOfficeIdentity)
     {
         var identity = (UmbracoBackOfficeIdentity)Thread.CurrentPrincipal.Identity;
         if (userNames == null || userNames.Contains(identity.Name))
         {
             identity.Roles = identity.Roles.Union(roleNames).ToArray();
             //now we need to reset the cookie))
             if (HttpContext.Current != null)
             {
                 var wrapper = new HttpContextWrapper(HttpContext.Current);
                 wrapper.CreateUmbracoAuthTicket(new UserData
                 {
                     AllowedApplications = identity.AllowedApplications,
                     Username            = identity.Name,
                     RealName            = identity.RealName,
                     Roles            = identity.Roles,
                     SessionTimeout   = identity.SessionTimeout,
                     StartContentNode = identity.StartContentNode.ToString(),
                     StartMediaNode   = identity.StartMediaNode.ToString()
                 });
             }
         }
     }
 }
Exemple #2
0
        public static void doLogin(User u)
        {
            var httpContextBase = new HttpContextWrapper(HttpContext.Current);

            //This is legacy code but might still be used by some old webforms things (hopefully not though!), in any case we still need to generate a valid sessionid for
            //the user so it's stored in the db and the cookie.
            var sessionId = ApplicationContext.Current.Services.UserService.CreateLoginSession(u.Id, httpContextBase.GetCurrentRequestIpAddress());

            httpContextBase.CreateUmbracoAuthTicket(new UserData(sessionId.ToString("N"))
            {
                Id                  = u.Id,
                SecurityStamp       = u.SecurityStamp,
                AllowedApplications = u.GetApplications().Select(x => x.alias).ToArray(),
                RealName            = u.Name,
                Roles               = u.GetGroups(),
                StartContentNodes   = u.UserEntity.CalculateContentStartNodeIds(ApplicationContext.Current.Services.EntityService),
                StartMediaNodes     = u.UserEntity.CalculateMediaStartNodeIds(ApplicationContext.Current.Services.EntityService),
                Username            = u.LoginName,
                Culture             = ui.Culture(u)
            });
            LogHelper.Info <BasePage>("User {0} (Id: {1}) logged in", () => u.Name, () => u.Id);
        }