コード例 #1
0
        private void BindRoles()
        {
            if (userId == -1)
            {
                return;
            }
            if (siteSettings == null)
            {
                return;
            }

            using (IDataReader reader = SiteUser.GetRolesByUser(siteSettings.SiteId, userId))
            {
                userRoles.DataSource = reader;
                userRoles.DataBind();
            }

            if (!useSeparatePagesForRoles)
            {
                using (IDataReader reader = Role.GetRolesUserIsNotIn(siteSettings.SiteId, userId))
                {
                    if (WebUser.IsAdmin)
                    {
                        allRoles.DataSource = reader;
                        allRoles.DataBind();
                    }
                    else
                    {
                        while (reader.Read())
                        {
                            string roleName = reader["RoleName"].ToString();
                            // only admins can add users to Admins role or Role Admins role
                            if ((roleName != "Admins") && (roleName != "Role Admins"))
                            {
                                if ((roleName != "Content Administrators") || (WebConfigSettings.AllowRoleAdminsToCreateContentManagers))
                                {
                                    ListItem item = new ListItem(reader["DisplayName"].ToString(), reader["RoleID"].ToString());
                                    allRoles.Items.Add(item);
                                }
                            }
                        }
                    }
                }

                if (allRoles.Items.Count == 0)
                {
                    allRoles.Enabled    = false;
                    addExisting.Enabled = false;
                    addExisting.Text    = Resource.ManageUsersUserIsInAllRolesMessage;
                }
            }
        }
コード例 #2
0
ファイル: SuggestSearch.ashx.cs プロジェクト: sang-nm/mphc
        private List <string> GetUserRoles(HttpContext context, int siteId)
        {
            List <string> userRoles = new List <string>();

            userRoles.Add("All Users");
            if (context.User.Identity.IsAuthenticated)
            {
                SiteUser currentUser = SiteUtils.GetCurrentSiteUser();
                if (currentUser != null)
                {
                    using (IDataReader reader = SiteUser.GetRolesByUser(siteId, currentUser.UserId))
                    {
                        while (reader.Read())
                        {
                            userRoles.Add(reader["RoleName"].ToString());
                        }
                    }
                }
            }

            return(userRoles);
        }
コード例 #3
0
        private List <string> GetUserRoles()
        {
            List <string> userRoles = new List <string>();

            userRoles.Add("All Users");
            if (Request.IsAuthenticated)
            {
                SiteUser currentUser = SiteUtils.GetCurrentSiteUser();
                if (currentUser != null)
                {
                    using (IDataReader reader = SiteUser.GetRolesByUser(siteSettings.SiteId, currentUser.UserId))
                    {
                        while (reader.Read())
                        {
                            userRoles.Add(reader["RoleName"].ToString());
                        }
                    }
                }
            }

            return(userRoles);
        }
コード例 #4
0
        private void PopulateControls()
        {
            if (!siteSettings.RequiresQuestionAndAnswer)
            {
                divSecurityQuestion.Visible = false;
                divSecurityAnswer.Visible   = false;
            }

            if ((siteUser != null) && (siteUser.UserId > -1))
            {
                spnTitle.InnerText = Resource.ManageUsersTitleLabel + " " + siteUser.Name;

                txtName.Text           = siteUser.Name;
                this.txtLoginName.Text = siteUser.LoginName;

                lnkAvatarUpload.ClientClick = "return GB_showPage('" + Page.Server.HtmlEncode(string.Format(CultureInfo.InvariantCulture, Resource.UploadAvatarForUserFormat, siteUser.Name)) + "', this.href, GBCallback)";
                txtEmail.Text            = siteUser.Email;
                txtOpenIDURI.Text        = siteUser.OpenIdUri;
                txtWindowsLiveID.Text    = siteUser.WindowsLiveId;
                txtLiveMessengerCID.Text = siteUser.LiveMessengerId;
                chkEnableLiveMessengerOnProfile.Checked = siteUser.EnableLiveMessengerOnProfile;
                gravatar1.Email            = siteUser.Email;
                gravatar1.MaxAllowedRating = MaxAllowedGravatarRating;

                if (siteUser.LastActivityDate > DateTime.MinValue)
                {
                    this.lblLastActivityDate.Text = siteUser.LastActivityDate.AddHours(TimeOffset).ToString();
                }

                if (siteUser.LastLoginDate > DateTime.MinValue)
                {
                    this.lblLastLoginDate.Text = siteUser.LastLoginDate.AddHours(TimeOffset).ToString();
                }

                if (siteUser.LastPasswordChangedDate > DateTime.MinValue)
                {
                    this.lblLastPasswordChangeDate.Text = siteUser.LastPasswordChangedDate.AddHours(TimeOffset).ToString();
                }

                if (siteUser.LastLockoutDate > DateTime.MinValue)
                {
                    this.lblLastLockoutDate.Text = siteUser.LastLockoutDate.AddHours(TimeOffset).ToString();
                }
                this.lblFailedPasswordAttemptCount.Text       = siteUser.FailedPasswordAttemptCount.ToString();
                this.lblFailedPasswordAnswerAttemptCount.Text = siteUser.FailedPasswordAnswerAttemptCount.ToString();
                this.chkIsLockedOut.Checked = siteUser.IsLockedOut;
                btnLockUser.Visible         = !siteUser.IsLockedOut;
                btnUnlockUser.Visible       = siteUser.IsLockedOut;

                if (siteSettings.UseSecureRegistration)
                {
                    if (siteUser.RegisterConfirmGuid == Guid.Empty)
                    {
                        chkEmailIsConfirmed.Checked = true;
                        btnConfirmEmail.Enabled     = false;
                    }
                }
                else
                {
                    divEmailConfirm.Visible = false;
                }

                this.txtComment.Text          = siteUser.Comment;
                this.txtPasswordQuestion.Text = siteUser.PasswordQuestion;
                this.txtPasswordAnswer.Text   = siteUser.PasswordAnswer;


                if (!siteSettings.UseLdapAuth)
                {
                    if (siteSettings.PasswordFormat == 0)
                    { //Clear
                        this.txtPassword.Text = siteUser.Password;
                    }
                    else if (siteSettings.PasswordFormat == 2)
                    {
                        try
                        {
                            CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider;
                            this.txtPassword.Text = CMembership.UnencodePassword(siteUser.Password, MembershipPasswordFormat.Encrypted);
                        }
                        catch (FormatException ex)
                        {
                            log.Error("Error decoding password for user " + siteUser.Email + " on manage users page.", ex);
                            // TODO: should we generate a random password and fix it here?
                        }
                    }
                }



                lblCreatedDate.Text     = siteUser.DateCreated.AddHours(TimeOffset).ToString();
                lblUserGuid.Text        = siteUser.UserGuid.ToString();
                lblTotalPosts.Text      = siteUser.TotalPosts.ToString();
                lnkUserPosts.UserId     = siteUser.UserId;
                lnkUserPosts.TotalPosts = siteUser.TotalPosts;
                lnkUnsubscribeFromGroups.NavigateUrl = SiteRoot + "/Groups/UnsubscribeGroup.aspx?ue=" + Page.Server.UrlEncode(siteUser.Email);

                chkProfileApproved.Checked     = siteUser.ProfileApproved;
                chkApprovedForGroups.Checked   = siteUser.ApprovedForGroups;
                chkTrusted.Checked             = siteUser.Trusted;
                chkDisplayInMemberList.Checked = siteUser.DisplayInMemberList;

                //ListItem listItem;

                if ((!allowGravatars) && (!disableAvatars))
                {
                    if (siteUser.AvatarUrl.Length > 0)
                    {
                        //listItem = ddAvatars.Items.FindByValue(siteUser.AvatarUrl);
                        //if (listItem != null)
                        //{
                        //    ddAvatars.ClearSelection();
                        //    listItem.Selected = true;

                        //}

                        imgAvatar.Src = ImageSiteRoot + "/Data/Sites/"
                                        + siteSettings.SiteId.ToInvariantString() + "/useravatars/" + siteUser.AvatarUrl;
                    }
                    else
                    {
                        imgAvatar.Src = ImageSiteRoot + "/Data/SiteImages/1x1.gif";
                    }
                }

                using (IDataReader reader = SiteUser.GetRolesByUser(siteSettings.SiteId, siteUser.UserId))
                {
                    userRoles.DataSource = reader;
                    userRoles.DataBind();
                }

                using (IDataReader reader = Role.GetRolesUserIsNotIn(siteSettings.SiteId, siteUser.UserId))
                {
                    allRoles.DataSource = reader;
                    allRoles.DataBind();
                }

                if (allRoles.Items.Count == 0)
                {
                    allRoles.Enabled    = false;
                    addExisting.Enabled = false;
                    addExisting.Text    = Resource.ManageUsersUserIsInAllRolesMessage;
                }

                List <UserLocation> userLocations = UserLocation.GetByUser(siteUser.UserGuid);
                grdUserLocation.DataSource = userLocations;
                grdUserLocation.DataBind();
            }
            else
            {
                spnTitle.InnerText = Resource.ManageUsersAddUserLabel;
                HideExtendedProfileControls();
            }
        }