Exemplo n.º 1
0
        public static UserInfo BuildUserInfo(User u)
        {
            var info = new UserInfo()
            {
                PartnerId = u.PartnerId.HasValue ? u.PartnerId.Value : -1,
                UserID = u.UserID,
                FullName = u.FullName,
                Roles = u.UserType.UserTypeName,
                Permissions = new List<PermissionInfo>(),
                IsSystemAdministrator = u.IsSA(),
            };

            List<Permission> permissions = new List<Permission>();
            permissions.AddRange(u.Permissions.ToList());
            if(u.Group!= null) permissions.AddRange(u.Group.Permissions);

            var grouped = permissions.GroupBy(p => p.Module);
            var distinctPermissions = new List<PermissionInfo>();
            foreach (var items in grouped)
            {

                PermissionInfo pi = new PermissionInfo()
                {
                    Module = items.Key.Name,
                    Actions = items.Key.Keys.Split(";".ToCharArray()),
                    Permissions = new  List<Permissions>()
                };
                foreach (var item in items)
                {
                    EnsurePermission(pi.Permissions, Permissions.Full, item.Full);
                    EnsurePermission(pi.Permissions, Permissions.Create, item.Create);
                    EnsurePermission(pi.Permissions, Permissions.Edit, item.Edit);
                    EnsurePermission(pi.Permissions, Permissions.Read, item.Read);
                }
                info.Permissions.Add(pi);
            }

            return info;
        }
Exemplo n.º 2
0
        private void persistUser(UserInfo user, bool rememberMe)
        {
            // Create ticket
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,
                user.FullName,
                DateTime.Now,
                DateTime.Now.AddMinutes(3),
                true,
                BuiltinRoles.Partner.ToString(),
                FormsAuthentication.FormsCookiePath);

            // Create encrypted cookie
            string hash = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
            if (ticket.IsPersistent)
            {
                cookie.Expires = ticket.Expiration;
            }

            // Set and done
            Response.Cookies.Add(cookie); //Necessary, otherwise UserData property gets lost
        }