PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/admin/Users/Users.aspx.cs

#
C# | 71 lines | 48 code | 13 blank | 10 comment | 0 complexity | 10358701cf6616a0d51c130033fdaee7 MD5 | raw file
 1namespace Admin.Users
 2{
 3    using System;
 4    using BlogEngine.Core;
 5    using System.Collections.Generic;
 6    using System.Linq;
 7    using System.Web.Security;
 8    using System.Web.Services;
 9
10    /// <summary>
11    /// The Users.
12    /// </summary>
13    public partial class Users : System.Web.UI.Page
14    {
15        #region Public Methods
16
17        protected void Page_Load(object sender, EventArgs e)
18        {
19            CheckSecurity();
20
21            phNewUserRoles.Visible = Security.IsAuthorizedTo(BlogEngine.Core.Rights.EditOtherUsersRoles);
22        }
23
24        private static void CheckSecurity()
25        {
26            Security.DemandUserHasRight(AuthorizationCheck.HasAll, true, new[] {
27                BlogEngine.Core.Rights.AccessAdminPages,
28                BlogEngine.Core.Rights.EditOtherUsers
29            });
30            
31        }
32
33        /// <summary>
34        /// Gets the users.
35        /// </summary>
36        /// <returns>The users.</returns>
37        [WebMethod]
38        public static List<MembershipUser> GetUsers()
39        {
40            CheckSecurity();
41
42            int count;
43            var userCollection = Membership.Provider.GetAllUsers(0, 999, out count);
44            var users = userCollection.Cast<MembershipUser>().ToList();
45
46            users.Sort((u1, u2) => string.Compare(u1.UserName, u2.UserName));
47
48            return users;
49        }
50
51        #endregion
52
53        #region Properties
54
55        /// <summary>
56        /// Gets RolesList.
57        /// </summary>
58        protected string RolesList
59        {
60            get
61            {
62                var ret = string.Empty;
63                const string Ptrn = "<input type=\"checkbox\" id=\"{0}\" class=\"chkRole\" /><span class=\"lbl\">{0}</span>";
64                var allRoles = System.Web.Security.Roles.GetAllRoles().Where(r => !r.Equals(BlogConfig.AnonymousRole, StringComparison.OrdinalIgnoreCase));
65                return allRoles.Aggregate(ret, (current, r) => current + string.Format(Ptrn, r, string.Empty));
66            }
67        }
68
69        #endregion
70    }
71}