public RespondWebViewData <RespondSigninUserViewModel> FindSininUserDataModelByUserID(RequestOnlineSigninUserViewModel request)
        {
            var parameter = new OnlineSigninUserParameter
            {
                UserID = request.UserID
            };
            var dataModel = this.mSiginUserDataAccess.FindSininUserDataModelByUserID(parameter);

            if (dataModel == null)
            {
                return(new RespondWebViewData <RespondSigninUserViewModel>(WebViewErrorCode.NotExistUserInfo));
            }
            var companyInfoRequest = new RequestCompanyInfoViewModel
            {
                CompanyID = dataModel.comid
            };
            var companyInfo      = this.mCompanyInfoViewService.GetCompanyInfoViewModel(companyInfoRequest);
            var connectionConfig = new DbConnectionConfig
            {
                ConnectTimeout = companyInfo.ConnectTimeout,
                Database       = companyInfo.Database,
                Password       = companyInfo.Password,
                Server         = companyInfo.Server,
                UserID         = companyInfo.UserID
            };

            FormsAuthenticationTicketManage.RenewTicketIfOld(request.SGuid);
            var respond = new RespondWebViewData <RespondSigninUserViewModel>
            {
                rows = new RespondSigninUserViewModel
                {
                    CurrentUser = new SigninUser
                    {
                        CompanySerialNum = dataModel.comid,
                        UserID_g         = request.SGuid,
                        UserID           = dataModel.userid,
                        UserName         = dataModel.username,
                        AddressIP        = UserIPAddressTool.GetRealUserIPAddress(),
                        ConnectionConfig = connectionConfig,
                        IsManager        = dataModel.ismanager,
                        IsSystem         = dataModel.issystem
                    }
                }
            };

            HttpContext.Current.Items.Add(BeforeCompileConstDefined.HttpContext_Login_User, respond.rows.CurrentUser);
            return(respond);
        }
        /// <summary>
        /// 将登陆用户保存至在线列表内
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool SaveLoginUserToOnline(RequestSigninUserViewModel request)
        {
            var context    = HttpContext.Current;
            var now        = DateTime.Now;
            var expTime    = now.ToShortDateString().ToDateTime().AddDays(1).AddSeconds(-1);//当日23:59:59
            var _parameter = new OnlineSigninUserParameter
            {
                UserID    = request.UserID,
                Browser   = context.Request.Browser.Browser,
                ExpTime   = expTime,
                LoginName = request.UserName,
                LoginTime = now,
                OverTime  = expTime,
                SGuid     = request.UserID_g,
                UserIP    = UserIPAddressTool.GetRealUserIPAddress()
            };

            return(this.mSiginUserDataAccess.SaveLoginUserToOnline(_parameter));
        }
예제 #3
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            var httpApplication = sender as HttpApplication;

            if (httpApplication == null)
            {
                return;
            }

            #region 跳过不需要恢复身份的页面的身份恢复操作

            var _notAuthenticatePageList = new List <string> {
                "/verifycodeimage/index", "/signin/login", "/commonpartial/unauthorizedvisit"
            };
            var _request_file_path = httpApplication.Context.Request.FilePath.ToLower();
            if (_notAuthenticatePageList.Any(item => item == _request_file_path))
            {
                return;
            }

            #endregion

            #region 身份未丢失的不需要执行恢复身份操作

            var context = httpApplication.Context;
            var user    = context.Items[BeforeCompileConstDefined.HttpContext_Login_User] as SigninUser;
            if (user != null)
            {
                return;
            }

            #endregion

            #region 设置需要使用主库连接字符串的页面

            var _useMainConnectionPageList = new List <string> {
                "/signin/login"
            };
            if (_useMainConnectionPageList.Any(item => item == _request_file_path))
            {
                context.Items[BeforeCompileConstDefined.HttpContext_Not_Use_Main_Connection] = false;
            }

            #endregion

            #region 身份恢复操作

            var autofac    = AutofacServiceContainer.CurrentServiceContainer.BeginLifetimeScope(new object());
            var service    = autofac.Resolve <ISigninUserViewService>();
            var userCookie = context.Request.Cookies[FormsAuthentication.FormsCookieName];
            if (userCookie == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(userCookie.Value))
            {
                return;
            }
            try
            {
                var authenticationTicket = FormsAuthentication.Decrypt(userCookie.Value);
                if (authenticationTicket == null || authenticationTicket.Expired)
                {
                    return;
                }
                var userID_g = authenticationTicket.UserData;
                //if (!user.AddressIP.Equals(UserIPAddressTool.GetRealUserIPAddress())) return;
                var request = new RequestOnlineSigninUserViewModel
                {
                    SGuid     = userID_g.ToGuid(),
                    AddressIP = UserIPAddressTool.GetRealUserIPAddress()
                };
                var online = service.GetOnlineSigninUserByUserID_g(request);
                if (online == null)
                {
                    return;
                }
                service.FindSininUserDataModelByUserID(new RequestOnlineSigninUserViewModel
                {
                    SGuid  = online.rows.SGuid,
                    UserID = online.rows.UserID
                });
            }
            catch
            {
            }

            #endregion
        }