123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common;
- using System.Security.Principal;
- using System.Web;
- namespace EMISOnline.Utility.FormValidate
- {
- public class CustomPrincipal : ICustomPrincipal
- {
- IIdentity iIdentity;
- public Guid UserID { get; set; }
- public string LoginID { get; set; }
- public string Name { get; set; }
- public Guid? StaffID { get; set; }
- public Guid? StudentID { get; set; }
- public Guid? CollegeID { get; set; }
- public Guid? CampusID { get; set; }
- public Guid? UniversityID { get; set; }
- //For teacher
- public Guid? DepartmentID { get; set; }
- public string DepartmentHierarchyID { get; set; }
- public string DepartmentName { get; set; }
- public bool IsStudent
- {
- get { return StudentID.HasValue; }
- }
- public Guid? RoleID { get; set; }
- public void ProcessData(System.Security.Principal.IIdentity id, string data)
- {
- this.iIdentity = id;
- //Pengzw Add 2012-11-26
- var set = data.Split('|');
- this.LoginID = set[0];
- this.UserID = string.IsNullOrEmpty(set[1]) ? new Guid() : new Guid(set[1]);
- this.Name = set[2];
- this.StaffID = string.IsNullOrEmpty(set[3]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[3]));
- this.StudentID = string.IsNullOrEmpty(set[4]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[4]));
- this.DepartmentID = string.IsNullOrEmpty(set[5]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[5]));
- this.DepartmentHierarchyID = set[6];
- this.DepartmentName = set[7];
- this.CollegeID = string.IsNullOrEmpty(set[8]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[8]));
- this.CampusID = string.IsNullOrEmpty(set[9]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[9]));
- this.UniversityID = string.IsNullOrEmpty(set[10]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[10]));
- if (set.Length == 12)
- {
- this.RoleID = string.IsNullOrEmpty(set[11]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[11]));
- }
- }
- public List<string> GetUserData()
- {
- List<string> userData = new List<string>();
- userData.Add(this.LoginID);
- userData.Add((this.UserID == Guid.Empty) ? "" : this.UserID.ToString());
- userData.Add(this.Name);
- userData.Add((this.StaffID.HasValue) ? this.StaffID.ToString() : "");
- userData.Add((this.StudentID.HasValue) ? this.StudentID.ToString() : "");
- userData.Add((this.DepartmentID.HasValue) ? this.DepartmentID.ToString() : "");
- userData.Add(DepartmentHierarchyID);
- userData.Add(DepartmentName);
- userData.Add((this.CollegeID.HasValue) ? this.CollegeID.ToString() : "");
- userData.Add((this.CampusID.HasValue) ? this.CampusID.ToString() : "");
- userData.Add((this.UniversityID.HasValue) ? this.UniversityID.ToString() : "");
- userData.Add((this.RoleID.HasValue) ? this.RoleID.ToString() : "");
- return userData;
- }
- public System.Security.Principal.IIdentity Identity
- {
- get { return iIdentity; }
- }
- public bool IsInRole(string role)
- {
- if (!string.IsNullOrEmpty(Name))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static CustomPrincipal Current
- {
- get
- {
- try
- {
- return ((CustomPrincipal)HttpContext.Current.User);
- }
- catch
- {
- return null;
- }
- }
- }
- }
- }
|