Пример #1
0
        /// <summary>
        /// 用户登录验证
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public LoginStatus Login(string userCode, string password)
        {
            LoginStatus result = LoginStatus.Failed;

            try
            {
                if (string.IsNullOrWhiteSpace(userCode))
                {
                    return(LoginStatus.UserIsNull);
                }

                if (string.IsNullOrWhiteSpace(password))
                {
                    return(LoginStatus.PasswordIsNull);
                }

                List <UserInfo> itemList = BaseEntityFac.GetEntityByField <UserInfo>("EmployeeNum", userCode);

                if (itemList != null && itemList.Count > 0)
                {
                    UserInfo item = itemList.FirstOrDefault();

                    //检查用户是否锁定
                    if (item.LockStatus == (int)LockStatus.Lock)
                    {
                        return(LoginStatus.Failed);
                    }

                    if (item.UserPasswd.CompareTo(password) == 0)
                    {
                        result = LoginStatus.Sucess;

                        #region 记录实时用户登录信息


                        List <RealLoginUserInfo> rlList = BaseEntityFac.GetEntityByField <RealLoginUserInfo>("UserInfoId", item.UserInfoId);
                        if (rlList == null || rlList.Count == 0)
                        {
                            List <RealLoginUserInfo> insertList = new List <RealLoginUserInfo>();
                            RealLoginUserInfo        rl         = new RealLoginUserInfo();
                            rl.UserInfoId          = item.UserInfoId;
                            rl.RealLoginUserInfoId = BusinessHelper.CreateGUID();
                            rl.LastTime            = BusinessHelper.GetServerTime();

                            insertList.Add(rl);

                            BaseEntityFac.NoTransactionOPEntitys(insertList, EOPType.Insert);
                        }
                        #endregion
                    }
                    else
                    {
                        result = LoginStatus.PasswordError;
                    }
                }
                else
                {
                    result = LoginStatus.UserNotExist;
                }
            }
            catch (Exception ex)
            {
                BusinessHelper.DebugLog(ex.Message);
            }


            return(result);
        }