Пример #1
0
        public static bool IsUserInRole(string roleName)
        {
            // change to claims
            var userId = Constant.GetUserID();

            if (userId != null || userId != "")
            {
                List <Roles> roles = ClaimsManager.RolesPerUserId(userId.ToString());
                //Console.WriteLine(roles);
                string[] splitrole = roleName.Split(',');
                for (int i = 0; i < splitrole.Count(); i++)
                {
                    if (splitrole[i] == "anonymous".ToUpper())
                    {
                        return(true);
                    }
                    var re = roles.Find(r => r.RoleName == splitrole[i]);
                    if (re != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #2
0
        public override bool IsUserInRole(string username, string roleName)
        {
            ClaimsPrincipal principal = HttpContext.Current.User as ClaimsPrincipal;
            List <Roles>    user      = ClaimsManager.RolesPerUserId(principal.FindFirst(ClaimTypes.Name).Value);
            var             userRoles = user.Select(r => r.RoleName);

            if (user == null)
            {
                return(false);
            }
            return(userRoles != null &&
                   userRoles.Any(r => r == roleName));
        }
Пример #3
0
        public override string[] GetRolesForUser(string username)
        {
            ClaimsPrincipal principal = HttpContext.Current.User as ClaimsPrincipal;
            // username in this case we use user id
            List <Roles> user      = ClaimsManager.RolesPerUserId(principal.FindFirst(ClaimTypes.Name).Value);
            var          userRoles = user.Select(r => r.RoleName);

            if (user == null)
            {
                return new string[] { }
            }
            ;
            return(userRoles == null ? new string[] { } :
                   userRoles.ToArray());
        }
Пример #4
0
        public static bool HasRole(string RoleName)
        {
            var userId = Constant.GetUserID();

            if (userId != "" || userId != null)
            {
                List <Roles> roles = ClaimsManager.RolesPerUserId(userId.ToString());
                var          re    = roles.Find(r => r.RoleName == RoleName);
                if (re != null)
                {
                    return(true);
                }
            }

            return(false);
        }