/// <summary>
        /// Checks if the Sitefinity user with id of <paramref name="userId"/> has the Gigya-Admin role.
        /// </summary>
        /// <param name="userId">The id of the user to check.</param>
        /// <returns>True if the user has the required Gigya-Admin role.</returns>
        public static bool HasRole(ClaimsIdentityProxy identity)
        {
            if (identity.IsUnrestricted)
            {
                return(true);
            }

            var roleManager = RoleManager.GetManager();

            var roles    = roleManager.GetRolesForUser(identity.UserId).ToList();
            var allRoles = roleManager.GetRoles().ToList();

            return(roleManager.IsUserInRole(identity.UserId, Constants.Roles.GigyaAdmin));
        }
Beispiel #2
0
        protected virtual GigyaLoginStatusViewModel GetViewModel(ClaimsIdentityProxy currentIdentity)
        {
            var model = new GigyaLoginStatusViewModel
            {
                SiteId       = SystemManager.CurrentContext.IsMultisiteMode ? SystemManager.CurrentContext.CurrentSite.Id : Guid.Empty,
                IsLoggedIn   = currentIdentity.IsAuthenticated,
                IsDesignMode = SystemManager.IsDesignMode
            };

            if (model.IsLoggedIn)
            {
                // check if Sitefinity is the session leader and sign in if required
                GigyaAccountHelper.ProcessRequestChecks(System.Web.HttpContext.Current);

                var userManager = UserManager.GetManager();
                var currentUser = userManager.GetUser(currentIdentity.UserId);
                if (currentUser != null)
                {
                    model.Email = currentUser.Email;

                    var profileManager = UserProfileManager.GetManager();
                    var profile        = profileManager.GetUserProfile <SitefinityProfile>(currentUser);
                    if (profile != null)
                    {
                        model.FirstName = profile.FirstName;
                        model.LastName  = profile.LastName;
                    }
                }
                else
                {
                    model.IsLoggedIn = false;
                }
            }

            return(model);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="sfContent">The sf content.</param>
        public UserModel(ClaimsIdentityProxy sfContent)
        {
            if (sfContent != null)
            {
                //SET DEFAULT PROPERTIES
                Id              = sfContent.UserId;
                Name            = sfContent.Name;
                IsAuthenticated = sfContent.IsAuthenticated;
                IsBackendUser   = sfContent.IsBackendUser;
                IsUnrestricted  = sfContent.IsUnrestricted;
                LastLoginDate   = sfContent.LastLoginDate;

                //GET ROLES
                Roles = new List <RoleModel>();
                if (sfContent.Roles != null && sfContent.Roles.Count() > 0)
                {
                    sfContent.Roles.ToList().ForEach(
                        r => Roles.Add(new RoleModel(r)));
                }

                // Store original content
                OriginalContent = sfContent;
            }
        }