Exemplo n.º 1
0
        /// <summary>
        /// 获取已经登录的用户,
        /// 该值可能为null
        /// </summary>
        public static UserBasicInfo GetLoginUser()
        {
            string cookieString = Utility.WebUtility.GetCookie(COOKIE_USER_KEY);

            if (string.IsNullOrEmpty(cookieString))
            {
                return(null);
            }

            var info = new UserBasicInfo();

            if (info.Deserialize(cookieString))
            {
                string session = Utility.WebUtility.GetCookie(COOKIE_SESSION);
                if (string.IsNullOrEmpty(session))
                {
                    try {
                        // 更新最后登录时间
                        // new UserTable().UpdateLoginState(info.UserID);
                    }
                    catch { }
                    Utility.WebUtility.WriteCookie(COOKIE_SESSION, Guid.NewGuid().ToString("N"));
                }
                return(info);
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 使用一个系统帐号检索活动目录并返回一个值
        /// 该值指示指定的域用户名是否是域用户
        /// </summary>
        /// <param name="adAccount"></param>
        /// <param name="domainUser"></param>
        /// <returns></returns>
        public bool IsDomainUser(string adAccount, string username, string password, out UserBasicInfo domainUser)
        {
            string msg;
            var    adUser = GetDomainUserByAD(adAccount, username, password, out msg);

            domainUser = new UserBasicInfo {
                UserName = adUser.ADAccount, NickName = adUser.FirstName + " " + adUser.LastName, Email = adUser.Email
            };
            return(domainUser != null);
        }
Exemplo n.º 3
0
        public static void Login(UserBasicInfo user, bool autoLogin)
        {
            string cookieValue = user.Serialize();

            if (autoLogin)
            {
                Utility.WebUtility.WriteCookie(COOKIE_USER_KEY, cookieValue, DateTime.MaxValue);
            }
            else
            {
                Utility.WebUtility.WriteCookie(COOKIE_USER_KEY, cookieValue);
            }
            WriteBroswerUnique(autoLogin);
        }
Exemplo n.º 4
0
        public UserBasicInfo GetDomainUser(string adAccount, string validatePwd, out string errorMessage)
        {
            DirectoryEntry entry = new DirectoryEntry(LDAPPath, adAccount, validatePwd);

            try {
                Object            obj    = entry.NativeObject;
                DirectorySearcher search = new DirectorySearcher(entry);
                search.Filter = "(SAMAccountName=" + adAccount + ")";
                search.PropertiesToLoad.Add("cn");
                SearchResult result = search.FindOne();
                if (result != null)
                {
                    DirectoryEntry de = result.GetDirectoryEntry();
                    UserBasicInfo  ui = new UserBasicInfo();
                    ui.UserName = adAccount;
                    if (de.Properties["GivenName"].Value != null)
                    {
                        ui.NickName = de.Properties["GivenName"].Value.ToString();
                    }
                    if (de.Properties["sn"].Value != null)
                    {
                        ui.NickName += " " + de.Properties["sn"].Value.ToString();
                    }
                    if (de.Properties["mail"].Value != null)
                    {
                        ui.Email = de.Properties["mail"].Value.ToString();
                    }
                    errorMessage = null;
                    return(ui);
                }
            }
            catch (Exception ex) {
                errorMessage = ex.Message;
                return(null);
            }

            errorMessage = null;
            return(null);
        }
Exemplo n.º 5
0
 public static void Login(UserBasicInfo user)
 {
     Login(user, false);
 }