PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms 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
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. namespace 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. /// <summary>
  10. /// The Users.
  11. /// </summary>
  12. public partial class Users : System.Web.UI.Page
  13. {
  14. #region Public Methods
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. CheckSecurity();
  18. phNewUserRoles.Visible = Security.IsAuthorizedTo(BlogEngine.Core.Rights.EditOtherUsersRoles);
  19. }
  20. private static void CheckSecurity()
  21. {
  22. Security.DemandUserHasRight(AuthorizationCheck.HasAll, true, new[] {
  23. BlogEngine.Core.Rights.AccessAdminPages,
  24. BlogEngine.Core.Rights.EditOtherUsers
  25. });
  26. }
  27. /// <summary>
  28. /// Gets the users.
  29. /// </summary>
  30. /// <returns>The users.</returns>
  31. [WebMethod]
  32. public static List<MembershipUser> GetUsers()
  33. {
  34. CheckSecurity();
  35. int count;
  36. var userCollection = Membership.Provider.GetAllUsers(0, 999, out count);
  37. var users = userCollection.Cast<MembershipUser>().ToList();
  38. users.Sort((u1, u2) => string.Compare(u1.UserName, u2.UserName));
  39. return users;
  40. }
  41. #endregion
  42. #region Properties
  43. /// <summary>
  44. /// Gets RolesList.
  45. /// </summary>
  46. protected string RolesList
  47. {
  48. get
  49. {
  50. var ret = string.Empty;
  51. const string Ptrn = "<input type=\"checkbox\" id=\"{0}\" class=\"chkRole\" /><span class=\"lbl\">{0}</span>";
  52. var allRoles = System.Web.Security.Roles.GetAllRoles().Where(r => !r.Equals(BlogConfig.AnonymousRole, StringComparison.OrdinalIgnoreCase));
  53. return allRoles.Aggregate(ret, (current, r) => current + string.Format(Ptrn, r, string.Empty));
  54. }
  55. }
  56. #endregion
  57. }
  58. }