Esempio n. 1
0
        /// <summary>
        /// 从活动目录搜索用户
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public static SearchResult GetUser(string account)
        {
            Domain domain = Domain.GetCurrentDomain();

            if (domain == null)
            {
                throw new Exception("当前用户没有登录域!");
            }

            IList <SearchResult> result      = DomainLdapTools.SearchObjects(domain.Name, "objectClass=user", true);
            SearchResult         currentUser = DomainLdapTools.LocateUser(result, Environment.UserName);

            return(currentUser);
        }
        public bool Login(LoginUser loginUser)
        {
            string userPrincipalName = DomainLdapTools.GetCurrentUserPrincipalName();

            if (string.IsNullOrEmpty(userPrincipalName))
            {
                throw new CustomException("获取本地域用户资料失败!");
            }

            _User.Text = userPrincipalName; //显示当前Domain帐号
            _User.Update();

            loginUser.Account = userPrincipalName;

            IBridge_User bridge = BridgeFactory.CreateUserBridge();

            //调用数据访问层的接口检查用户登录
            DataTable dt = bridge.Login(loginUser, Char.Parse(LoginUserType.W.ToString()));

            if (dt.Rows.Count == 0)
            {
                throw new CustomException("域用户'" + userPrincipalName + "'没有建立权限关联!");
            }
            DataRow row = dt.Rows[0];

            Loginer user = new Loginer();

            user.Account        = ConvertEx.ToString(row[TUser.Account]);
            user.AccountName    = ConvertEx.ToString(row[TUser.UserName]);
            user.FlagAdmin      = ConvertEx.ToString(row[TUser.FlagAdmin]);
            user.Email          = ConvertEx.ToString(row[TUser.Email]);
            user.LoginTime      = DateTime.Now;
            Loginer.CurrentUser = user;//保存当前用户

            //下载用户权限
            SystemAuthentication.UserAuthorities = bridge.GetUserAuthorities(user);

            return(true);
        }