Exemple #1
0
        /// <summary>
        /// 注册Session
        /// </summary>
        /// <param name="userID">用户名</param>
        /// <param name="password">密码</param>
        public void RegSession(string userID, string password)
        {
            string pwd       = SafeHelper.EncryptDES(password, userID);
            string sessionId = string.Format("{0}.{1}", this.AppName, this.GetSessionID());

            if (!SqlHelper.Exists <HrEmploy>(H => H.UserID == userID && H.PassWord == pwd))
            {
                throw new Exception(string.Format("注册SessionID[{0}]失败", sessionId));
            }
            if (!this.sessions.ContainsKey(sessionId))
            {
                lock (lockObject)
                {
                    HrEmploy    info = DbFactory.DbSession.DbContext.Set <HrEmploy>().FirstOrDefault(H => H.UserID == userID && H.PassWord == pwd);
                    SessionMode mode = new SessionMode
                    {
                        SessionID  = sessionId,
                        HrEmployee = info
                    };
                    if (HttpContext.Current != null && HttpContext.Current.Session != null)
                    {
                        HttpContext.Current.Session[sessionId] = mode;
                    }
                    this.sessions.Add(sessionId, mode);
                }
            }
        }
Exemple #2
0
        public UserResult Login(string userID, string password)
        {
            UserResult result  = null;
            string     pwd     = SafeHelper.EncryptDES(password, userID);
            bool       isExist = SqlHelper.Exists <HrEmploy>(H => H.UserID == userID && H.PassWord == pwd);

            if (!isExist)
            {
                throw AjaxException.ToException(ErrorCode.VErrorCode, "用户名或密码错误!");
            }
            Core.Server.ISessionServer sessionServer = SessionFactory.GetSessionServer();
            sessionServer.RegSession(userID, password);
            HrEmploy userInfo = (DbFactory.DbSession.DbContext as CrmEntities).HrEmploy.FirstOrDefault(H => H.UserID == userID && H.PassWord == pwd);
            int      timeOut  = sessionServer.Timeout;
            DateTime expires  = DateTime.Now;

            expires = expires.AddMinutes(timeOut);
            if (userInfo != null)
            {
                result = new UserResult
                {
                    id      = userInfo.UserID,
                    User    = userInfo.ToAjaxResult(),
                    Expires = expires
                };
            }

            return(result);
        }