public HomeController(IUserInfoBLL userInfoBLL, IMemoryCache cache, ILoggerFactory logger) { this._userInfoBLL = userInfoBLL; this._cache = cache; this._logger = logger.CreateLogger(typeof(HomeController)); }
static void Main(string[] args) { AFactory af = AFactory.CreateBLLFactory(); IUserInfoBLL ib = af.CreateUserInfoBLLInstance(); UserInfo u = ib.Where().FirstOrDefault(); Console.Write("用户ID:{0},用户名:{1}", u.UserId, u.UserName); Console.ReadKey(); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); IApplicationContext ctx = ContextRegistry.GetContext(); //if (Session["userInfo"] == null) if (Request.Cookies["sessionId"] == null) { // filterContext.HttpContext.Response.Redirect("/Login/Index"); if (Request.Cookies["cp1"] != null) { string userName = Request.Cookies["cp1"].Value;//获取Cookie存储的用户名 //判断用户是否正确. IUserInfoBLL userInfoBLL = (IUserInfoBLL)ctx.GetObject("UserInfoBLL"); UserInfo userInfo = userInfoBLL.LoadEntity(u => u.UName == userName).FirstOrDefault(); if (!Common.WebCommon.ValidateCookieInfo(userInfo)) { UserInfo = userInfo; filterContext.Result = Redirect(Url.Action("Index", "Login")); //注意跳转. } filterContext.Result = Redirect(Url.Action("Index", "Home")); //注意跳转. } else { filterContext.Result = Redirect(Url.Action("Index", "Login"));//注意跳转. } } else { string sessionId = Request.Cookies["sessionId"].Value; Object obj = MemcacheHelper.Get(sessionId); if (obj != null) { UserInfo userInfo = SerializeHelper.DeSerializeToObj <UserInfo>(obj.ToString()); UserInfo = userInfo; Common.MemcacheHelper.Set(sessionId, SerializeHelper.SerializeToString(userInfo), DateTime.Now.AddMinutes(20)); } else { filterContext.Result = Redirect(Url.Action("Index", "Login"));//注意跳转. } } //过滤非菜单权限。 if (UserInfo != null) { //留后门,发布一定要删除 if (UserInfo.UName == "itcast") { return; } string url = Request.Url.AbsolutePath.ToString().ToLower(); //获取当前请求的URL地址。 string httpMethod = Request.HttpMethod; //获取请求的方式。 //查找url地址对应的权限信息。 IActionInfoBLL actionInfoService = (IActionInfoBLL)ctx.GetObject("ActionInfoBLL"); var actionInfo = actionInfoService.LoadEntity(a => a.Url == url && a.HttpMethod == httpMethod).FirstOrDefault(); if (actionInfo == null) { filterContext.Result = Redirect("/Error.html"); return; } //判断登录用户是否有actionInfo的访问权限。 //也是按照两条线进行过滤。 //1先按照用户-->权限这条进行过滤. IUserInfoBLL userInfoBLL = (IUserInfoBLL)ctx.GetObject("UserInfoBLL"); var userInfo = userInfoBLL.LoadEntity(u => u.ID == UserInfo.ID).FirstOrDefault();//获取登录用户信息。 var userAction = (from a in userInfo.R_UserInfo_ActionInfo where a.ActionInfoID == actionInfo.ID select a ).FirstOrDefault(); if (userAction != null) //如果成立,表示登录用户有userInfo这个权限,但是考虑是否 被禁止。 { if (userAction.IsPass) //表示允许,后面就不要校验了,直接访问用户请求的Url地址。 { return; } else { filterContext.Result = Redirect("/Error.html"); return; } } //2:按照用户-->角色--->权限进行校验. var loginUserRoles = userInfo.RoleInfo; var loginUserAction = (from r in loginUserRoles from a in r.ActionInfo where a.ID == actionInfo.ID select a).Count(); if (loginUserAction < 1) { filterContext.Result = Redirect("/Error.html"); return; } } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { if(filterContext.HttpContext.Request.Cookies[strSession]==null) { filterContext.HttpContext.Response.Redirect("/Login/Login/Index"); } else { //1.1 从传入的请求中获取SessionId的值 string sessionId = filterContext.HttpContext.Request.Cookies[strSession].Value; //1.2 从缓存中查询是否包含此Id的缓存对象 object userId_temp = Common.MemcacheHelper.Get(sessionId); bool isExt = false; if (userId_temp != null) { int userId = Common.SerializerHelper.DeSerializerToObject<int>(userId_temp.ToString()); //1.3 根据该id查询指定的用户对象 isExt = true; // IApplicationContext appContext = ContextRegistry.GetContext(); //使用spring.net创建 userInfoBLL userInfoBLL = (IUserInfoBLL)appContext.GetObject("userInfoService"); var userInfo = userInfoBLL.GetListBy(u => u.ID == userId).FirstOrDefault(); LoginUser = userInfo; if (userInfo != null) { ViewBag.UserInfo = userInfo.UName; } else { ViewBag.UserInfo = ""; } } else { ViewBag.UserInfo = null; } } base.OnActionExecuting(filterContext); }
protected override void Exceuted(IJobExecutionContext context) { if (jobInfoBLL == null) { jobInfoBLL = new J_JobInfoBLL(); } if (userInfoBLL == null) { userInfoBLL = new UserInfoBLL(); } if (qrtz_triggerBLL == null) { qrtz_triggerBLL = new QRTZ_TRIGGERSBLL(); } #region 11月8日测试修改数据库的bug,现注释 //11月8日测试修改数据库的bug,现注释 //var targetJob = jobInfoBLL.GetListBy(j => j.JID == 18).FirstOrDefault(); //if (targetJob != null) //{ // targetJob.JobState = 2; //} //jobInfoBLL.Update(targetJob); #endregion //向数据库中写入 //获取JobDataMap var data = context.JobDetail.JobDataMap; //1 需要传入一个用户id var uid = data.GetInt("UID"); if (uid != null) { //var uid_int = int.Parse(uid); var user_temp = userInfoBLL.GetListBy(u => u.ID == uid).FirstOrDefault(); //2 根据用户id查询查询该用户所拥有的作业 var list = userInfoBLL.GetJobListByUser(user_temp.ID); //3 取出对应的作业 //取出的context.JobDetail.Key.Name实际为JID //**查错,暂时注释** var targetJob = (from j in list where j.JID == Convert.ToInt32(context.JobDetail.Key.Name) /*&& j.JobGroup == context.JobDetail.Key.Group*/ select j).FirstOrDefault(); PMS.BLL.J_JobInfoBLL job_temp = new PMS.BLL.J_JobInfoBLL(); //UpdateJobState(targetJob); //4 若存在则更新作业状态 //**查错,暂时注释** if (targetJob != null) { //4 更新作业状态的思路 //4-1 获取trigger的状态 var trigger_temp =qrtz_triggerBLL.GetListBy(t => t.TRIGGER_NAME == context.JobDetail.Key.Name).FirstOrDefault(); if (trigger_temp != null) { var dic = PMS.Model.Dictionary.Quartz_TriggerStateDictionary.GetResponseCode(); //4-2获取trigger其他状态 //1)修改往数据库中写入的作业状态 targetJob.JobState = dic[trigger_temp.TRIGGER_STATE == null ? "null" : trigger_temp.TRIGGER_STATE]; //2)修改作业结束时间(世界时需+8) targetJob.EndRunTime = context.Trigger.EndTimeUtc.GetValueOrDefault().DateTime.AddHours(8); //3)修改作业下次执行时间(世界时需+8) if (context.Trigger.GetNextFireTimeUtc() != null) { targetJob.NextRunTime= context.Trigger.GetNextFireTimeUtc().GetValueOrDefault().DateTime.AddHours(8); } } UpdateJobState(targetJob); } //4 若不存在则创建新的作业 } }
public HomeController(IHlelloBLL iHlelloBll, IUsersBLL iUsersBll, IUserInfoBLL iuserInfoBll) { _iHlelloBll = iHlelloBll; _iUsersBll = iUsersBll; _iuserInfoBll = iuserInfoBll; }
public UserInfoService(IUserInfoBLL userInfoBLL) { _userInfoBLL = userInfoBLL; }