CustomPrincipal.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common;
  6. using System.Security.Principal;
  7. using System.Web;
  8. namespace EMISOnline.Utility.FormValidate
  9. {
  10. public class CustomPrincipal : ICustomPrincipal
  11. {
  12. IIdentity iIdentity;
  13. public Guid UserID { get; set; }
  14. public string LoginID { get; set; }
  15. public string Name { get; set; }
  16. public Guid? StaffID { get; set; }
  17. public Guid? StudentID { get; set; }
  18. public Guid? CollegeID { get; set; }
  19. public Guid? CampusID { get; set; }
  20. public Guid? UniversityID { get; set; }
  21. //For teacher
  22. public Guid? DepartmentID { get; set; }
  23. public string DepartmentHierarchyID { get; set; }
  24. public string DepartmentName { get; set; }
  25. public bool IsStudent
  26. {
  27. get { return StudentID.HasValue; }
  28. }
  29. public Guid? RoleID { get; set; }
  30. public void ProcessData(System.Security.Principal.IIdentity id, string data)
  31. {
  32. this.iIdentity = id;
  33. //Pengzw Add 2012-11-26
  34. var set = data.Split('|');
  35. this.LoginID = set[0];
  36. this.UserID = string.IsNullOrEmpty(set[1]) ? new Guid() : new Guid(set[1]);
  37. this.Name = set[2];
  38. this.StaffID = string.IsNullOrEmpty(set[3]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[3]));
  39. this.StudentID = string.IsNullOrEmpty(set[4]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[4]));
  40. this.DepartmentID = string.IsNullOrEmpty(set[5]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[5]));
  41. this.DepartmentHierarchyID = set[6];
  42. this.DepartmentName = set[7];
  43. this.CollegeID = string.IsNullOrEmpty(set[8]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[8]));
  44. this.CampusID = string.IsNullOrEmpty(set[9]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[9]));
  45. this.UniversityID = string.IsNullOrEmpty(set[10]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[10]));
  46. if (set.Length == 12)
  47. {
  48. this.RoleID = string.IsNullOrEmpty(set[11]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[11]));
  49. }
  50. }
  51. public List<string> GetUserData()
  52. {
  53. List<string> userData = new List<string>();
  54. userData.Add(this.LoginID);
  55. userData.Add((this.UserID == Guid.Empty) ? "" : this.UserID.ToString());
  56. userData.Add(this.Name);
  57. userData.Add((this.StaffID.HasValue) ? this.StaffID.ToString() : "");
  58. userData.Add((this.StudentID.HasValue) ? this.StudentID.ToString() : "");
  59. userData.Add((this.DepartmentID.HasValue) ? this.DepartmentID.ToString() : "");
  60. userData.Add(DepartmentHierarchyID);
  61. userData.Add(DepartmentName);
  62. userData.Add((this.CollegeID.HasValue) ? this.CollegeID.ToString() : "");
  63. userData.Add((this.CampusID.HasValue) ? this.CampusID.ToString() : "");
  64. userData.Add((this.UniversityID.HasValue) ? this.UniversityID.ToString() : "");
  65. userData.Add((this.RoleID.HasValue) ? this.RoleID.ToString() : "");
  66. return userData;
  67. }
  68. public System.Security.Principal.IIdentity Identity
  69. {
  70. get { return iIdentity; }
  71. }
  72. public bool IsInRole(string role)
  73. {
  74. if (!string.IsNullOrEmpty(Name))
  75. {
  76. return true;
  77. }
  78. else
  79. {
  80. return false;
  81. }
  82. }
  83. public static CustomPrincipal Current
  84. {
  85. get
  86. {
  87. try
  88. {
  89. return ((CustomPrincipal)HttpContext.Current.User);
  90. }
  91. catch
  92. {
  93. return null;
  94. }
  95. }
  96. }
  97. }
  98. }