protected void Page_Load(object sender, EventArgs e)
        {
            _currentUserId = QueryHelper.GetInteger("objectid", 0);
            _currentSiteId = CMS.SiteProvider.SiteContext.CurrentSiteID;

            var currentSiteUserIds = UserSiteInfoProvider.GetUserSites()
                                     .WhereEquals("SiteID", _currentSiteId)
                                     .And()
                                     .WhereNotEquals("UserID", _currentUserId);

            if (currentSiteUserIds.Count > 0)
            {
                _currentSiteUsersFilter = string.Format("UserId in ({0})", TextHelper.Join(",", DataHelper.GetStringValues(currentSiteUserIds.Tables[0], "UserID")));
            }
            else
            {
                _currentSiteUsersFilter = "UserId is null";
            }

            if (_currentUserId > 0)
            {
                SetupControls();

                LoadData();
            }
        }
        /// <summary>
        /// Sends the emails.
        /// </summary>
        protected void Send()
        {
            // Check "modify" permission
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Users", "Modify"))
            {
                RedirectToAccessDenied("CMS.Users", "Modify");
            }

            // Check template name
            var templateName = usBlankPasswords.Value.ToString();

            if (string.IsNullOrWhiteSpace(templateName))
            {
                ShowError(GetString("Kadena.Email.TemplateNotSelected"));
                return;
            }

            var emailTemplate = EmailTemplateProvider.GetEmailTemplate(templateName, _siteId);

            // Validate From field
            if (string.IsNullOrEmpty(emailTemplate.TemplateFrom))
            {
                ShowError(GetString("Kadena.Email.CorrectFromField"));
                return;
            }

            // Selecting users for emails
            var users = UserInfoProvider.GetUsers().WhereEmpty("UserPassword")
                        .And()
                        .WhereNotEmpty("Email");

            if (_siteId > 0)
            {
                users = users
                        .And()
                        .WhereIn("UserID", UserSiteInfoProvider.GetUserSites()
                                 .WhereEquals("SiteID", _siteId)
                                 .Column("UserID"))
                        .Columns("UserID", "Email", "UserGUID");
            }
            if (users.Count == 0)
            {
                ShowInformation(GetString("Kadena.Email.NoUsersToSend"));
                return;
            }

            // Creating and sending email message.
            var resolver     = MacroResolver.GetInstance();
            var emailService = new EmailService();

            foreach (var ui in users)
            {
                emailService.SendResetPasswordEmail(ui, emailTemplate, _siteId > 0 ? siteSelector.SiteName : null, resolver);
            }

            ShowConfirmation(GetString("system_email.emailsent"));
        }
    /// <summary>
    /// Returns string with site ids where user is member.
    /// </summary>
    private string GetUserSites()
    {
        DataSet ds = UserSiteInfoProvider.GetUserSites("SiteID", "UserID = " + userId, null, 0);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            return(TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], "SiteID")));
        }

        return(String.Empty);
    }
    /// <summary>
    /// Returns string with site ids where user is member.
    /// </summary>
    private string GetUserSites()
    {
        var data = UserSiteInfoProvider.GetUserSites().Where("UserID = " + userId).Columns("SiteID");

        if (data.Any())
        {
            return(TextHelper.Join(";", DataHelper.GetStringValues(data.Tables[0], "SiteID")));
        }

        return(String.Empty);
    }
Beispiel #5
0
    /// <summary>
    /// Returns <see cref="ObjectQuery"/> cointaing site user IDs.
    /// </summary>
    private ObjectQuery <UserSiteInfo> GetSiteUserIDs()
    {
        var dataQuery = UserSiteInfoProvider
                        .GetUserSites()
                        .Column(UserSiteInfo.TYPEINFO.ParentIDColumn);

        if (IsCMSDesk)
        {
            dataQuery.WhereEquals(UserSiteInfo.TYPEINFO.SiteIDColumn, SiteContext.CurrentSiteID);
        }

        return(dataQuery);
    }
Beispiel #6
0
    /// <summary>
    /// Adds user condition to given <see paramref="whereCondition"/>.
    /// </summary>
    private void AddUserCondition(WhereCondition whereCondition, int siteID)
    {
        whereCondition.WhereGreaterThan("UserID", 0);

        if (siteID > 0)
        {
            whereCondition.WhereIn("UserID", UserSiteInfoProvider.GetUserSites()
                                   .Column("UserID")
                                   .WhereEquals("SiteID", siteID));
        }

        if (chkDisplayHidden.Visible && !chkDisplayHidden.Checked)
        {
            whereCondition.WhereIn("UserID", UserInfoProvider.GetUsers()
                                   .Column("UserID")
                                   .WhereEquals("UserIsHidden", 0)
                                   .Or()
                                   .WhereNull("UserIsHidden"));
        }
    }
Beispiel #7
0
    /// <summary>
    /// Adds user condition to given <see paramref="whereCondition"/>.
    /// </summary>
    private void AddUserCondition(ref WhereCondition whereCondition, int siteID)
    {
        var userCondition = new WhereCondition().WhereGreaterThan("UserID", 0);

        if (siteID > 0 && IncludeSiteCondition())
        {
            userCondition.WhereIn("UserID", UserSiteInfoProvider.GetUserSites()
                                  .Column("UserID")
                                  .WhereEquals("SiteID", siteID));
        }

        if (chkDisplayHidden.Visible && !chkDisplayHidden.Checked)
        {
            userCondition.WhereIn("UserID", UserInfoProvider.GetUsers()
                                  .Column("UserID")
                                  .WhereEquals("UserIsHidden", 0)
                                  .Or()
                                  .WhereNull("UserIsHidden"));
        }

        whereCondition = new WhereCondition(whereCondition, userCondition);
    }
    protected void SetupControls()
    {
        // If current control context is widget or livesite hide site selector
        if (ControlsHelper.CheckControlContext(this, ControlContext.WIDGET_PROPERTIES) || ControlsHelper.CheckControlContext(this, ControlContext.LIVE_SITE))
        {
            ShowSiteFilter = false;
        }

        // Set prefix if not set
        if (ResourcePrefix == String.Empty)
        {
            // Set resource prefix based on mode
            if ((SelectionMode == SelectionModeEnum.Multiple) || (SelectionMode == SelectionModeEnum.MultipleButton) || (SelectionMode == SelectionModeEnum.MultipleTextBox))
            {
                usUsers.ResourcePrefix = "selectusers";
            }
        }

        // Add sites filter
        if (ShowSiteFilter)
        {
            usUsers.FilterControl = "~/CMSFormControls/Filters/SiteFilter.ascx";
            usUsers.SetValue("DefaultFilterValue", (SiteID > 0) ? SiteID : SiteContext.CurrentSiteID);
            usUsers.SetValue("FilterMode", "user");
        }

        // Generate WhereCondtion based on SelectUser's properties
        var usersWhereCondition = new WhereCondition();
        var userTypeInfo        = ObjectTypeManager.GetTypeInfo(UserInfo.OBJECT_TYPE);

        // Hide hidden users
        if (HideHiddenUsers)
        {
            var apparentUsersCondition = new WhereCondition().WhereEqualsOrNull("UserIsHidden", 0);
            usersWhereCondition.And(apparentUsersCondition);
        }

        // Hide disabled users
        if (HideDisabledUsers)
        {
            var enabledUsersCondition = new WhereCondition(UserInfoProvider.USER_ENABLED_WHERE_CONDITION);
            usersWhereCondition.And(enabledUsersCondition);
        }

        // Hide non-approved users
        if (HideNonApprovedUsers)
        {
            var approvedUserIDs = UserSettingsInfoProvider
                                  .GetUserSettings()
                                  .WhereEqualsOrNull("UserWaitingForApproval", 0)
                                  .Column("UserSettingsUserID");

            var approvedUsersCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, approvedUserIDs);
            usersWhereCondition.And(approvedUsersCondition);
        }

        // Select group users
        if (GroupID > 0)
        {
            var groupUserIDs = new ObjectQuery(PredefinedObjectType.GROUPMEMBER)
                               .WhereEquals("MemberGroupID", GroupID)
                               .Column("MemberUserID");

            // Hide non-approved group users
            if (HideNonApprovedUsers)
            {
                groupUserIDs.WhereNull("MemberRejectedWhen");
            }

            var usersInGroupCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, groupUserIDs);
            usersWhereCondition.And(usersInGroupCondition);
        }

        // Select users in role
        if (RoleID > 0)
        {
            var usersInRoleIDs = UserRoleInfoProvider
                                 .GetUserRoles()
                                 .WhereEquals("RoleID", RoleID)
                                 .Column("UserID");

            var usersInRoleCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, usersInRoleIDs);
            usersWhereCondition.And(usersInRoleCondition);
        }

        // Select users depending on site; if filter enabled, where condition is added from filter itself
        if (!ShowSiteFilter && (SiteID >= 0) && !DisplayUsersFromAllSites)
        {
            int siteID      = (SiteID == 0) ? SiteContext.CurrentSiteID : SiteID;
            var siteUserIDs = UserSiteInfoProvider
                              .GetUserSites()
                              .WhereEquals("SiteID", siteID)
                              .Column("UserID");

            var siteUsersCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, siteUserIDs);

            if (TreatGlobalAdminsAsSiteUsers)
            {
                siteUsersCondition.Or(GetPrivilegeLevelCondition());
            }

            usersWhereCondition.And(siteUsersCondition);
        }

        if (AlwaysShowGlobalAdministrators)
        {
            // New instance has to be created in order to produce brackets
            usersWhereCondition = new WhereCondition(usersWhereCondition).Or(GetPrivilegeLevelCondition());
        }

        // Add additional users
        if ((AdditionalUsers != null) && (AdditionalUsers.Length > 0))
        {
            var additionalUsersCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, AdditionalUsers);

            new WhereCondition(usersWhereCondition).Or(additionalUsersCondition);
        }

        // Control where condition
        if (!String.IsNullOrEmpty(WhereCondition))
        {
            usersWhereCondition = new WhereCondition(usersWhereCondition).And(new WhereCondition(WhereCondition));
        }

        // Append generated where condition
        usUsers.WhereCondition = SqlHelper.AddWhereCondition(usUsers.WhereCondition, usersWhereCondition.ToString(expand: true));

        pnlUpdate.ShowProgress = (SelectionMode == SelectionModeEnum.Multiple);
    }
    private void EnsureAuthenticatedRole()
    {
        // Handle Global First
        RoleInfo AuthenticatedUserRole    = GetOrCreateRole(_AuthenticatedRole, _AuthenticatedRoleDisplayName, _AuthenticatedRoleDescription, null);
        RoleInfo NotAuthenticatedUserRole = GetOrCreateRole(_NotAuthenticatedRole, _NotAuthenticatedRoleDisplayName, _NotAuthenticatedRoleDescription, null);
        RoleInfo EveryoneUserRole         = GetOrCreateRole(_EveryoneRole, _EveryoneRoleDisplayName, _EveryoneRoleDescription, null);

        // Public user
        UserInfoProvider.GetUsers()
        .WhereEquals("username", "public")
        .WhereNotIn("UserID", UserRoleInfoProvider.GetUserRoles().WhereEquals("RoleID", NotAuthenticatedUserRole.RoleID)
                    .TypedResult.Select(x => x.UserID).ToArray()).ForEachObject(x =>
        {
            HandleUserRole(x.UserID, NotAuthenticatedUserRole.RoleID);
        });

        // Non public users
        UserInfoProvider.GetUsers()
        .WhereNotEquals("username", "public")
        .WhereNotIn("UserID", UserRoleInfoProvider.GetUserRoles().WhereEquals("RoleID", AuthenticatedUserRole.RoleID).TypedResult.Select(x => x.UserID).ToArray()).ForEachObject(x =>
        {
            HandleUserRole(x.UserID, AuthenticatedUserRole.RoleID);
        });

        // Now everyone
        UserInfoProvider.GetUsers()
        .WhereNotIn("UserID", UserRoleInfoProvider.GetUserRoles().WhereEquals("RoleID", EveryoneUserRole.RoleID).TypedResult.Select(x => x.UserID).ToArray()).ForEachObject(x =>
        {
            HandleUserRole(x.UserID, EveryoneUserRole.RoleID);
        });

        // Now go through Site Users
        foreach (SiteInfo Site in SiteInfoProvider.GetSites())
        {
            RoleInfo SiteAuthenticatedUserRole    = GetOrCreateRole(_AuthenticatedRole, _AuthenticatedRoleDisplayName, _AuthenticatedRoleDescription, Site.SiteID);
            RoleInfo SiteNotAuthenticatedUserRole = GetOrCreateRole(_NotAuthenticatedRole, _NotAuthenticatedRoleDisplayName, _NotAuthenticatedRoleDescription, Site.SiteID);
            RoleInfo SiteEveryoneUserRole         = GetOrCreateRole(_EveryoneRole, _EveryoneRoleDisplayName, _EveryoneRoleDescription, Site.SiteID);

            // Public user
            UserInfoProvider.GetUsers()
            .WhereEquals("username", "public")
            .WhereIn("UserID", UserSiteInfoProvider.GetUserSites().WhereEquals("SiteID", Site.SiteID).TypedResult.Select(x => x.UserID).ToArray())
            .WhereNotIn("UserID", UserRoleInfoProvider.GetUserRoles().WhereEquals("RoleID", SiteAuthenticatedUserRole.RoleID)
                        .TypedResult.Select(x => x.UserID).ToArray()).ForEachObject(x =>
            {
                HandleUserRole(x.UserID, SiteAuthenticatedUserRole.RoleID);
            });

            // Non public users
            UserInfoProvider.GetUsers()
            .WhereNotEquals("username", "public")
            .WhereIn("UserID", UserSiteInfoProvider.GetUserSites().WhereEquals("SiteID", Site.SiteID).TypedResult.Select(x => x.UserID).ToArray())
            .WhereNotIn("UserID", UserRoleInfoProvider.GetUserRoles().WhereEquals("RoleID", SiteNotAuthenticatedUserRole.RoleID).TypedResult.Select(x => x.UserID).ToArray()).ForEachObject(x =>
            {
                HandleUserRole(x.UserID, SiteNotAuthenticatedUserRole.RoleID);
            });

            // Now everyone
            UserInfoProvider.GetUsers()
            .WhereIn("UserID", UserSiteInfoProvider.GetUserSites().WhereEquals("SiteID", Site.SiteID).TypedResult.Select(x => x.UserID).ToArray())
            .WhereNotIn("UserID", UserRoleInfoProvider.GetUserRoles().WhereEquals("RoleID", SiteEveryoneUserRole.RoleID).TypedResult.Select(x => x.UserID).ToArray()).ForEachObject(x =>
            {
                HandleUserRole(x.UserID, SiteEveryoneUserRole.RoleID);
            });
        }
    }