Exemplo n.º 1
0
        public ActionResult About()
        {
            using (SecurityEntities securityEntities = new SecurityEntities())
            {
                ViewBag.DBName = securityEntities.DBNameObfuscate();
            }

            return View();
        }
        public override bool IsUserInRole(string username, string roleName)
        {
            if (String.IsNullOrWhiteSpace(username) || String.IsNullOrWhiteSpace(roleName))
                return false;

            string appCode;
            string groupCode;
            
            if (Group.SplitAppGroupCode(roleName, out appCode, out groupCode)) 
            {
                using (SecurityEntities securityEntities = new SecurityEntities())
                {
                    var code = (from u in securityEntities.Users
                                where u.Login == username
                                from g in u.Groups
                                where g.App.Code == appCode && g.Code == groupCode
                                select g.Code).FirstOrDefault();

                    return (code != null);
                }
            }
            return false;
        }
        public override bool ValidateUser(string username, string password)
        {
            password = password.Trim();
            username = username.Trim();

            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
                return false;

            using (SecurityEntities securityEntities = new SecurityEntities())
            {
                var usr = (from u in securityEntities.Users
                           where u.Login == username
                           select u).FirstOrDefault();
                
                if (usr != null)
                {
                    return usr.PlainPasswordMatch(password);
                }
            }

            return false;
        }
Exemplo n.º 4
0
 public AccountController(SecurityEntities securityDbContext)
     : base(securityDbContext)
 {
 }
 public SecurityController(SecurityEntities securityDbContext)
 {
     _securityDbContext = securityDbContext;
 }
        public override string[] GetRolesForUser(string username)
        {
            using (SecurityEntities securityEntities = new SecurityEntities())
            {
                string[] roles = new string[0];

                var groups = (from u in securityEntities.Users
                              where u.Login == username
                              from g in u.Groups
                              where g.ActiveFlag == DataHelper.BoolYNTue
                              where g.App.ActiveFlag == DataHelper.BoolYNTue
                              orderby g.App.Code, g.Code
                              select g).ToList();

                if (groups.IsAny())
	            {
                    var groupRoles = groups.Select(g => g.AppGroupCode);

                    var adminRoles = groups.Where(g => g.AppAdmin).Select(g => g.App.Code).ToList();
                    if (adminRoles.IsAny())
                    {
                        if (groups.Any(g => g.AppAdmin && g.App.SysAdmin))
                        {
                            adminRoles.Insert(0, CstAuthorizeAttribute.SysAdminRole);
                        }
                        adminRoles.AddRange(groupRoles);

                        roles = adminRoles.ToArray();
                    }
                    else 
                    {
                        roles = groupRoles.ToArray();
                    }
                }

                string s = String.Join(", ", roles);
                return roles;
            }
        }