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

📄 user.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

// 修改说明:增加若干用户属性 
// 修改人:宝玉
// 修改日期:2005-02-26

using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;


using CommunityServer.Configuration;

using Microsoft.ScalableHosting.Profile;
using Microsoft.ScalableHosting.Security;

namespace CommunityServer.Components {

	// *********************************************************************
	//	User
	//
	///	<summary>
	///	This class contains	the	properties for a User.
	///	</summary>
	///	
	// ********************************************************************/

	[Serializable]
	public class User : ExtendedAttributes
	{
		#region .cnstr

        public User(MembershipUser mu, ProfileBase pb):this(mu,new Profile(pb))
        {

        }

        public User(MembershipUser mu, ProfileData pd):this(mu,new Profile(pd))
        {

        }

        public User(MembershipUser mu, Profile p)
        {
            RefreshMembershipUser(mu);
            RefreshUserProfile(p);
            
        }

		public User()
		{
			RefreshUserProfile(new Profile());
		}

		public void RefreshMembershipUser(MembershipUser mu)
		{
			if(mu == null)
			{
				throw new Exception("A null MembershipUser is not valid to instantiate a new User");
			}
            

			this.memberUser = mu;
			this.username = mu.UserName;
		}

        public void RefreshUserProfile(Profile p)
        {
            if(p == null)
                throw new Exception("A null profile is not valid");

            memberProfile = p;

        }

        public Profile Profile
        {
            get{return memberProfile;}
        }

        public bool HasProfile
        {
            get{return Profile != null;}
        }
			
		#endregion

		#region Private Properties

		// Primary attributes
		//
        static RolesConfiguration roles = CSConfiguration.GetConfig().RolesConfiguration;
		int	userID;
		string username;
		string password;
		string privateEmail;
		MembershipPasswordFormat passwordFormat =	MembershipPasswordFormat.Hashed;
        
		DateTime dateLastActive;
		string lastAction;
		UserAccountStatus accountStatus	= UserAccountStatus.Approved;
		bool isAnonymous = true;
		bool enableEmail = true;
		bool forceLogin	= false;
       

		private MembershipUser memberUser = null;
        private Profile memberProfile = null;

		// Extended	attributes
		//
		NameValueCollection	extendedAttributes = new NameValueCollection();
		int	totalPosts;
		byte[] postRank;
		//int[] groups;
		bool enableAvatar = true; // 默认True
		ModerationLevel	moderationLevel	= ModerationLevel.Moderated;
		bool isAvatarApproved =	true;
		bool enableThreadTracking;
		SortOrder postSortOrder	= SortOrder.Ascending;
		bool enableOnlineStatus;
		bool enableDisplayInMemberList	= true;
		bool enablePrivateMessages;
		bool enableHtmlEmail;
		string salt	= string.Empty;
		string appUserToken	= string.Empty;
        AuditSummary auditCounters = null;
		
		#region 新增内容
		private string nickname = "";
		private string ipCreated;
		private string ipLastActivity;
		private DateTime birthday = DateTime.MinValue;
		private int databaseQuota = 10240;
		private int databaseQuotaUsed = 0;

		#endregion

		#endregion

        #region IsRoles

		protected bool IsInRoles( string[] roleNames ) 
		{
			string [] userRoles = Roles.GetUserRoleNames( this.Username );
			foreach( string userRole in userRoles ) {
				foreach( string roleName in roleNames ) {
					if( roleName == userRole )
						return true;
				}
			}
			return false;
		}

        ///	<summary>
        ///	Specifies if a user	in a System Administator administrator or not.
        ///	</summary>
        public bool	IsAdministrator	
        {
            get	
            { 
                try	
                {
					return IsInRoles( new string[] { roles.SystemAdministrator } );
                }
                catch	{}

                return false;
            }					 
        }

        ///	<summary>
        ///	Specifies if a user	in an administrator	or not.
        ///	</summary>
        public bool	IsBlogAdministrator	
        {
            get	
            { 
                try	
                {
					return IsInRoles( new string[] { roles.SystemAdministrator, roles.BlogAdministrator } );
                }
                catch	{}

                return false;
            }					 
        }

        ///	<summary>
        ///	Specifies if a user	in an administrator	or not.
        ///	</summary>
        public bool	IsGalleryAdministrator	
        {
            get	
            { 
                try	
                {
					return IsInRoles( new string[] { roles.SystemAdministrator, roles.GalleryAdministrator } );
                }
                catch	{}

                return false;
            }					 
        }

        ///	<summary>
        ///	Specifies if a user	in an administrator	or not.
        ///	</summary>
        public bool	IsForumAdministrator	
        {
            get	
            { 
                try	
                {
					return IsInRoles( new string[] { roles.SystemAdministrator, roles.ForumsAdministrator } );
                }
                catch	{}

                return false;
            }					 
        }

        ///	<summary>
        ///	Specifies if a user	in an administrator	or not.
        ///	</summary>
        public bool	IsModerator	
        {
            get	
            { 
                try	
                {
					return IsInRoles( new string[] { roles.SystemAdministrator, roles.Moderator } );
                } 
                catch	{}

                return false;
            }
        }



        /// <summary>
        /// Lookup to determine if this user belongs to the editor role.
        /// </summary>
        public bool IsEditor 
        {
            get 
            {
                try 
                {
					return IsInRoles( new string[] {roles.SystemAdministrator, roles.Editor } );
                }
                catch {}

                return false;
            }
        }

//        public static bool IsInRole(string rolename) 
//        {
//            return HttpContext.Current.User.IsInRole(rolename);
//        }

        #endregion

		#region Public Properties

		public MembershipUser Member
		{
			get{return memberUser;}
		}

		public UserCookie GetUserCookie() 
		{
		    return new UserCookie( this	);
		}

		public string LastAction 
		{
			get	
			{
				return lastAction;
			}
			set	
			{
				lastAction = value;
			}
		}

		public string Username 
		{
			get { return this.username; }
			set 
			{
                if(this.Member != null)
                {
                    #if DEBUG
                    throw new Exception("WSHA Provider can not update usernames");
                    #endif
                }
                else
                {
                    this.username = value;
                }

			}
		}

		public string DisplayName {
			get { 
				string cn = this.Profile.CommonName;

				if (cn == string.Empty)
					return this.username; 

				return cn;
			}
		}

		public string Password 
		{
			get { return this.password; }
			set 
			{
				//We sometimes use this a temporarty container. Need a cleaner way of allowing this
//				if(this.Member != null)
//				{
//					throw new Exception("SHS can not be changed directly");
//				}
				this.password = value;

			}
		}

		#region 新增内容

		/// <summary>
		/// 昵称
		/// </summary>
		public string Nickname
		{
			get 
			{
				if (nickname == "")
					nickname = username;
				return nickname;
			}
			set 
			{
				nickname = value;
			}
		}

		/// <summary>
		/// 注册IP
		/// </summary>
		public string IPCreated
		{
			get 
			{
				return ipCreated;
			}
			set 
			{
				ipCreated = value;
			}
		}

		/// <summary>
		/// 最后活动IP
		/// </summary>
		public string IPLastActivity
		{
			get 
			{
				return ipLastActivity;
			}
			set 
			{
				ipLastActivity = value;
			}
		}

		/// <summary>
		/// 生日
		/// </summary>
		public DateTime Birthday
		{
			get 
			{
				return birthday;
			}
			set 
			{
				birthday = value;
			}
		}

		/// <summary>
		/// 磁盘配额
		/// </summary>
		/// <remarks>默认10mb</remarks>
		public int DatabaseQuota
		{
			get 
			{
				return databaseQuota;
			}
			set 
			{
				databaseQuota = value;
			}
		}

		/// <summary>
		/// 已使用的磁盘空间
		/// </summary>
		public int DatabaseQuotaUsed
		{
			get 
			{
				return databaseQuotaUsed;
			}
			set 
			{
				databaseQuotaUsed = value;
			}
		}

		#endregion

		public string PasswordQuestion 
		{
		    get
		    {
				if(this.Member != null)
					return Member.PasswordQuestion;
				else
					return null; 
		    }
		}

		string passwordAnswer = null;
		public string PasswordAnswer {
			get { return passwordAnswer; }
			set { passwordAnswer = value; }
		}

		///	<summary>
		///	Unique identifier for the user.
		///	</summary>
		public int UserID 
		{
			get	{ return userID; }
			set	{ userID = value; }			
		}

		///	<summary>
		///	Determins if the user's	online status can be displayed.
		///	</summary>
		public bool	EnableOnlineStatus 
		{
			get	{ return enableOnlineStatus; }
			set	{ enableOnlineStatus = value; }
		}

		///	<summary>
		///	Determines if the user is displayed	in the member list.
		///	</summary>
		public bool	EnableDisplayInMemberList 
		{
			get	{ return enableDisplayInMemberList;	}
			set	{ enableDisplayInMemberList	= value; }
		}
		
		///	<summary>
		///	Can	the	user send/recieve private messages.
		///	</summary>
		public bool	EnablePrivateMessages 
		{
			get	{ return enablePrivateMessages;	}
			set	{ enablePrivateMessages	= value; }
		}

		///	<summary>
		///	Does the user want to recieve Html Email.
		///	</summary>
		public bool	EnableHtmlEmail	
		{
			get	{ return enableHtmlEmail; }
			set	{ enableHtmlEmail =	value; }
		}

		///	<summary>
		///	Does the user want to recieve Email.
		///	</summary>
		public bool	EnableEmail	
		{
			get	{ return enableEmail; }
			set	{ enableEmail =	value; }
		}
		
		///	<summary>
		///	Used to	determine the user's post rank.
		///	</summary>
		public byte[] PostRank 
		{
			get	{ return postRank; }
			set	{ postRank = value;	}
		}


		public MembershipPasswordFormat PasswordFormat 
		{
			get	{ return passwordFormat; }
			set	{ passwordFormat = value; }
		}

		public string AppUserToken 
		{
			get	{ return appUserToken; }
			set	{ appUserToken = value;	}			
		}

		///	<summary>
		///	Controls views in posts
		///	</summary>
		public SortOrder PostSortOrder 
		{
			get	{ return postSortOrder;	}
			set	{ postSortOrder	= value; }
		}
		

⌨️ 快捷键说明

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