123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common;
- using System.Security.Principal;
- using System.Web;
- namespace EMIS.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 void ProcessData(string data)
- {
- 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]));
- }
- _current = this;
- }
- public List<string> GetUserData()
- {
- var userData = new List<string>();
- userData.Add(this.LoginID);
- userData.Add(this.UserID.ToString());
- userData.Add(this.Name);
- userData.Add(this.StaffID == null ? "" : this.StaffID.ToString());
- userData.Add(this.StudentID == null ? "" : this.StudentID.ToString());
- userData.Add(this.DepartmentID == null ? "" : this.DepartmentID.ToString());
- userData.Add(this.DepartmentHierarchyID);
- userData.Add(this.DepartmentName);
- userData.Add(this.CollegeID == null ? "" : this.CollegeID.ToString());
- userData.Add(this.CampusID == null ? "" : this.CampusID.ToString());
- userData.Add(this.UniversityID == null ? "" : this.UniversityID.ToString());
- userData.Add(this.RoleID == null ? "" : 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;
- }
- }
- private static CustomPrincipal _current;
- public static CustomPrincipal Current
- {
- get
- {
- try
- {
- if (HttpContext.Current == null)
- {
- return _current;
- }
- return ((CustomPrincipal)HttpContext.Current.User);
- }
- catch
- {
- return null;
- }
- }
- }
- }
- }
|