Esempio n. 1
0
        public bool LoginByCard(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.LoginByCard(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[tb_sys_User.FAccount]);
            user.AccountName = ConvertEx.ToString(row[tb_sys_User.FUserName]);
            user.FlagAdmin   = ConvertEx.ToString(row[tb_sys_User.FFlagAdmin]);
            user.Email       = ConvertEx.ToString(row[tb_sys_User.FMail]);
            user.Fid         = ConvertEx.ToString(row[tb_sys_User.FID]);
            user.LoginTime   = DateTime.Now;
            user.MachineName = GetComputerinfo.GetHostName();
            user.IPAddress   = GetComputerinfo.GetIP();
            user.CardNo      = ConvertEx.ToString(row[tb_sys_User.FCardNo]);

            user.DbType         = loginUser.DbType;
            user.DataSetName    = loginUser.DataSetDBName;
            Loginer.CurrentUser = user;//保存当前用户

            //登录日志
            IBridge_CommonService comBridge = BridgeFactory.CreateCommonServiceBridge();

            comBridge.WriteLogOP("0", "0", "登录系统", "");

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

            return(true);
        }
Esempio n. 2
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);
        }