⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adminprincipal.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.Components
{
    using PowerEasy.Model.UserManage;
    using System;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.Security.Principal;
    using System.Web.Security;

    [Serializable]
    public class AdminPrincipal : IPrincipal
    {
        [NonSerialized]
        private PowerEasy.Model.UserManage.AdministratorInfo m_AdministratorInfo;
        private string m_AdminName;
        private IIdentity m_identity;
        private string m_RndPassword;
        private string[] m_roles;
        [NonSerialized]
        private string m_Roles;
        private string m_UserName;
        private const string SuperAdminRoleId = "0";

        public AdminPrincipal()
        {
        }

        public AdminPrincipal(IIdentity identity, string[] roles)
        {
            if (identity == null)
            {
                throw new ArgumentNullException("identity");
            }
            this.m_identity = identity;
            if (roles != null)
            {
                this.m_roles = new string[roles.Length];
                for (int i = 0; i < roles.Length; i++)
                {
                    this.m_roles[i] = roles[i];
                }
            }
        }

        public static AdminPrincipal CreatePrincipal(FormsAuthenticationTicket ticket)
        {
            try
            {
                BinaryFormatter formatter = new BinaryFormatter();
                MemoryStream serializationStream = new MemoryStream(Convert.FromBase64String(ticket.UserData));
                AdminPrincipal principal = (AdminPrincipal) formatter.Deserialize(serializationStream);
                serializationStream.Dispose();
                principal.Identity = new FormsIdentity(ticket);
                return principal;
            }
            catch (ArgumentNullException)
            {
                return new AdminPrincipal(new NoAuthenticateIdentity(), null);
            }
            catch (FormatException)
            {
                return new AdminPrincipal(new NoAuthenticateIdentity(), null);
            }
            catch (SerializationException)
            {
                return new AdminPrincipal(new NoAuthenticateIdentity(), null);
            }
        }

        public bool IsInRole(string role)
        {
            if ((role != null) && (this.m_roles != null))
            {
                foreach (string str in role.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    for (int i = 0; i < this.m_roles.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(this.m_roles[i]) && (string.Compare(this.m_roles[i], str, StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        public string SerializeToString()
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream serializationStream = new MemoryStream();
            formatter.Serialize(serializationStream, this);
            string str = Convert.ToBase64String(serializationStream.ToArray());
            serializationStream.Dispose();
            return str;
        }

        public PowerEasy.Model.UserManage.AdministratorInfo AdministratorInfo
        {
            get
            {
                return this.m_AdministratorInfo;
            }
            set
            {
                this.m_AdministratorInfo = value;
            }
        }

        public string AdminName
        {
            get
            {
                return this.m_AdminName;
            }
            set
            {
                this.m_AdminName = value;
            }
        }

        public IIdentity Identity
        {
            get
            {
                return this.m_identity;
            }
            set
            {
                this.m_identity = value;
            }
        }

        public bool IsSuperAdmin
        {
            get
            {
                return this.IsInRole("0");
            }
        }

        public string RndPassword
        {
            get
            {
                return this.m_RndPassword;
            }
            set
            {
                this.m_RndPassword = value;
            }
        }

        public string Roles
        {
            get
            {
                return this.m_Roles;
            }
            set
            {
                this.m_Roles = value;
                if (!string.IsNullOrEmpty(value))
                {
                    this.m_roles = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }
            }
        }

        public string UserName
        {
            get
            {
                return this.m_UserName;
            }
            set
            {
                this.m_UserName = value;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -