public SystemUserRoleRelation GetUserRoleRelation(SystemUser user, SystemRole role)
 {
     DetachedCriteria criterions = DetachedCriteria.For(typeof(SystemUserRoleRelation));
     criterions.Add(PROPERTY_USERID.Eq(user));
     criterions.Add(PROPERTY_ROLEID.Eq(role));
     return criterions.GetExecutableCriteria(this.DoGetSession(false)).SetMaxResults(1).UniqueResult<SystemUserRoleRelation>();
 }
        /// <summary>
        /// 获取用户分配的角色
        /// </summary>
        /// <param name="user">用户</param>
        /// <returns>分配的角色</returns>
        public List<SystemRole> GetUserAssignRole(SystemUser user)
        {
            DetachedCriteria userAssignedRoleRelation = DetachedCriteria.For(typeof(SystemUserRoleRelation));
            userAssignedRoleRelation.Add(SystemUserRoleRelationBaseDao.PROPERTY_USERID.Eq(user));

            DetachedCriteria userAssignedRole = DetachedCriteria.For(typeof(SystemRole));
            userAssignedRole.Add(
                Subqueries.PropertyIn(SystemUserRoleRelationBase.PROPERTY_NAME_ROLEID, userAssignedRoleRelation));
            return ConvertToTypedList(userAssignedRole.GetExecutableCriteria(this.DoGetSession(false)).List<SystemRole>());
        }
 public List<SystemRole> GetUserAssignRole(SystemUser user)
 {
     var criterions = new List<ICriterion> { PROPERTY_USERID.Eq(user) };
     List<SystemUserRoleRelation> listSystemUserRoleRelation = FindAll(criterions.ToArray());
     var assignRoles = new List<SystemRole>();
     foreach (SystemUserRoleRelation relation in listSystemUserRoleRelation)
     {
         this.InitializeLazyProperties(relation);
         assignRoles.Add(relation.RoleID);
     }
     return assignRoles;
 }
 public void LogOperationAddOKInfo(SystemUser systemUser, SystemMoudle systemMoudle, string recordName, int relateID,string source,string requestInfo)
 {
     SystemLog log = new SystemLog();
     log.LogDate = System.DateTime.Now;
     log.LogDescrption = GenerateOperationAddOKInfo(systemUser, systemMoudle.MoudleNameCn, recordName, relateID);
     log.LogLevel = LogLevel.Info.ToString();
     log.LogType = LogType.BussnessOperation.ToString();
     log.LogRelateDateTime = null;
     log.LogRelateMoudleDataID = relateID;
     log.LogRelateMoudleDataID = systemMoudle.MoudleID;
     log.LogRelateUserID = systemUser.UserID;
     log.LogUser = systemUser.UserName;
     log.LogSource = source;
     log.LogRequestInfo = requestInfo;
     this.Create(log);
 }
        //public void AuthenticateRequestUser()
        //{
        //    FormsAuthenticationTicket authTicket = this.GetTicket(HttpContext.Current);
        //    if (null != authTicket)
        //    {
        //        FormsIdentity id = new FormsIdentity(authTicket);
        //        Pair userData = this.GetUserData(HttpContext.Current);
        //        List<SystemRole> roles = null;
        //        SystemUser systemUser = null;
        //        if (userData != null)
        //        {
        //            roles = (List<SystemRole>)userData.Second;
        //            systemUser = (SystemUser)userData.First;
        //        }
        //        else
        //        {
        //            roles = new List<SystemRole>();
        //            systemUser = null;
        //        }
        //        HttpContext.Current.Items["Context_Key_LoginUser"] = systemUser;
        //        HttpContext.Current.Items["Context_Key_LoginUserAssignRole"] = roles;
        //        List<string> listRoleName = new List<string>();
        //        foreach (SystemRole role in roles)
        //        {
        //            listRoleName.Add(role.RoleName);
        //        }
        //        HttpContext.Current.User = new LoginPermissionPrincipal(id, listRoleName);
        //    }
        //}

        public override void Create(SystemUser obj)
        {
            if (obj.UserLoginID.Equals("DeveloperAdministrator"))
            {
                throw new DataValidationException(" Login ID ¡±DeveloperAdministrator¡° has exist¡£");
            }
            if (obj.UserLoginID.Equals("SystemAdministrator"))
            {
                throw new DataValidationException(" Login ID ¡±SystemAdministrator¡° has exist¡£");
            }
            if (base.SelfDao.GetUserByLoginID(obj.UserLoginID) != null)
            {
                throw new DataValidationException(" Login ID ¡±" + obj.UserLoginID + "¡° has exist¡£");
            }
            base.Create(obj);
        }
		/// <summary>
		/// 默认构造函数
		/// </summary>
		public SystemUserRoleRelationBase()
		{
			_userrole_id = 0; 
			_user_id =  null; 
			_role_id =  null; 
		}
        public override MembershipUser CreateUser(string username, string password, string email,
                                                  string passwordQuestion, string passwordAnswer, bool isApproved,
                                                  object providerUserKey, out MembershipCreateStatus status)
        {
            var e = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(e);
            if (e.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }
            if (RequiresUniqueEmail && !string.IsNullOrEmpty(GetUserNameByEmail(email)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }
            if (this.ServicesContainerInstance.SystemUserServiceInstance.GetUserByLoginID(username) != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return null;
            }

            var user = new SystemUser
            {
                UserName = username,
                UserLoginID = username,
                UserPassword = EncodePassword(password, machineKey.ValidationKey),
                PasswordFormat = ((int)PasswordFormat),
                PasswordSalt = machineKey.ValidationKey,
                UserEmail = email,
                PasswordQuestion = passwordQuestion,
                PasswordAnswer = passwordAnswer,
                IsApproved = isApproved
            };
            user.Applications.Add(application);
            try
            {
                this.ServicesContainerInstance.SystemUserServiceInstance.Create(user);
                status = MembershipCreateStatus.Success;
            }
            catch (Exception exception)
            {
                throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this, SR.User_UnableToCreate,
                                                                                     exception);
            }
            return GetUser(username, false);
        }
 public SystemUserRoleRelation GetUserRoleRelation(SystemUser user, SystemRole role)
 {
     return SelfDao.GetUserRoleRelation(user, role);
 }
 public string GenerateOperationAddFailedInfo(SystemUser systemUser, string moudleName, string recordName,string errorMessage)
 {
     return string.Format("用户{0}于{1}时间添加了一个名为“{2}”的{3}失败。错误原因:{4}(userID:{5})。", systemUser.UserName, System.DateTime.Now, recordName, moudleName, errorMessage, systemUser.UserID);
 }
        //public string GenerateOperationOKInfo(string userName, string operationInfo)
        //{
        //    return string.Format("用户{0}于{1}时间进行{2}操作成功。", userName, System.DateTime.Now, operationInfo);
        //}
        //public string GenerateOperationFailedInfo(string userName, string operationInfo, string errorInfo)
        //{
        //    return string.Format("用户{0}于{1}时间进行{2}操作失败,错误信息:{3}。", userName, System.DateTime.Now, operationInfo, errorInfo);
        //}

        public string GenerateOperationAddOKInfo(SystemUser systemUser,string moudleName,string recordName,int relateID)
        {
            return string.Format("用户{0}于{1}时间添加了一个名为“{2}”的{3}成功。(id:{4},userID:{5})", systemUser.UserName, System.DateTime.Now, recordName, moudleName, relateID, systemUser.UserID);
        }
 public List<SystemPrivilege> GetUserPrivilegeByUserLoginID(SystemUser user, SystemMoudle moudle)
 {
     throw new NotImplementedException();
 }
 public bool CheckUserRoleRelationIsExist(SystemUser user, SystemRole role)
 {
     SystemUserRoleRelation systemUserRoleRelation = this.DaosContainerIocID.SystemUserRoleRelationDaoInstance.GetUserRoleRelation(user, role);
     return (systemUserRoleRelation != null);
 }
 public string WebUserLoginIn(SystemUser systemUser, bool persistentUser, HttpContext context)
 {
     List<SystemRole> listRole = this.DaosContainerIocID.SystemUserRoleRelationDaoInstance.GetUserAssignRole(systemUser);
     Pair pair = new Pair(systemUser, listRole);
     string userInfo = SerializableUtil.ConvertObjectToZipedBase64String<Pair>(pair);
     HttpCookie userC = new HttpCookie(FormsAuthentication.FormsCookieName + "UserInfo", userInfo);
     context.Response.Cookies.Add(userC);
     FormsAuthenticationTicket tk = new FormsAuthenticationTicket(1, systemUser.UserLoginID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(30.0), persistentUser, "", FormsAuthentication.FormsCookiePath);
     string key = FormsAuthentication.Encrypt(tk);
     HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, key);
     context.Response.Cookies.Add(ck);
     return FormsAuthentication.GetRedirectUrl(systemUser.UserLoginID.ToString(), persistentUser);
 }
		/// <summary>
		/// 默认构造函数
		/// </summary>
		public SystemUserGroupUserRelationBase()
		{
			_usergroupuserid = 0; 
			_userid =  null; 
			_usergroupid =  null; 
		}