コード例 #1
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);
        }