コード例 #1
0
        public UserResult GetCurrentUser()
        {
            UserResult result = null;

            Core.Server.ISessionServer sessionServer = SessionFactory.GetSessionServer();
            string sessionID = sessionServer.GetCurrentSessionID();

            if (string.IsNullOrEmpty(sessionID))
            {
                return(null);
            }
            Core.Server.SessionMode mode = sessionServer.GetSessionMode(sessionID);
            HrEmploy userInfo            = mode.HrEmployee;

            //string sessionId = string.Format("{0}.{2}", this.AppName, this.GetSessionID());
            if (SqlHelper.Exists <HrEmploy>(H => H.UserID == userInfo.UserID))
            {
                int      timeOut = sessionServer.Timeout;
                DateTime expires = DateTime.Now;
                expires = expires.AddMinutes(timeOut);
                result  = new UserResult
                {
                    id      = userInfo.UserID,
                    User    = userInfo.ToAjaxResult(),
                    Expires = expires
                };
                return(result);
            }
            return(null);
        }
コード例 #2
0
ファイル: SessionServer.cs プロジェクト: songtaojie/Project
        /// <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);
                }
            }
        }
コード例 #3
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);
        }