Esempio n. 1
0
        public SysUser AutoLogin(IIdentity objWI)
        {
            var strUser = SysCommon.GetUserName(objWI);
            //数据库获取设置信息
            BaseService <SysUser> objServ = new BaseService <SysUser>();
            var obj = objServ.Entities.Where(a => a.LillyId == strUser).FirstOrDefault();

            if (obj != null)
            {
                // objLoginInfo = obj;
                //Session["UserInfo"] = objLoginInfo;

                //登录日志
                BaseService <Logs> objServLogs = new BaseService <Logs>();
                objServLogs.Insert(new Logs()
                {
                    LogCate         = "AdminLogin",
                    LogContent      = "登录成功",
                    CreatedUserID   = obj.Id.ToString(),
                    CreatedUserName = obj.LillyId
                });
            }

            return(obj);
        }
Esempio n. 2
0
        public SysUser AutoLogin(IIdentity objWI)
        {
            var strUser = objWI is WindowsIdentity?SysCommon.GetUserName(objWI) : objWI.Name;

            return(AutoLogin(strUser));
        }
        /// <summary>
        /// 重新基类在Action执行之前的事情
        /// </summary>
        /// <param name="filterContext">重写方法的参数</param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            #if !DEBUG
            if (string.IsNullOrEmpty(Request["AppID"]))
            {
                Session["AppID"] = Request["AppID"];
            }

            var objAppID = Session["AppID"];
            AppId = 0;
            if (objAppID != null)
            {
                AppId = int.Parse(objAppID.ToString());
            }
            ViewBag.AppList  = WeChatCommonService.lstSysWeChatConfig;
            ViewBag.CurAppID = AppId;



            ////得到用户登录的信息
            objLoginInfo = Session["UserInfo"] as SysUser;



            ////判断用户是否为空   应该使用 AuthorizeAttribute,临时解决一下
            if (objLoginInfo == null && (filterContext.ActionDescriptor.ActionName.ToLower() != "login" ||
                                         filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower() != "account"))
            {
                //windows登录
                if (objLoginInfo == null && (Request.IsAuthenticated && (User.Identity is WindowsIdentity)))
                {
                    var windowsIdentity = (WindowsIdentity)User.Identity;
                    //获取用户
                    var strUser = SysCommon.GetUserName(windowsIdentity);
                    //数据库获取设置信息
                    BaseService <SysUser> objServ = new BaseService <SysUser>();
                    var obj = objServ.Repository.Entities.Where(a => a.WeChatUserID == strUser).FirstOrDefault();
                    if (obj != null)
                    {
                        objLoginInfo        = obj;
                        Session["UserInfo"] = objLoginInfo;

                        //登录日志
                        BaseService <LogsModel> objServLogs = new BaseService <LogsModel>();
                        objServLogs.Repository.Insert(new LogsModel()
                        {
                            LogCate         = "AdminLogin",
                            LogContent      = "登录成功",
                            CreatedUserID   = objLoginInfo.Id.ToString(),
                            CreatedUserName = objLoginInfo.WeChatUserID
                        });
                    }
                }
                //
                // if (filterContext.

                if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                {
                    AjaxResult <int> result = new AjaxResult <int>();
                    result.Message       = new JsonMessage((int)HttpStatusCode.Unauthorized, "Please login");
                    filterContext.Result = Json(result, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    //Redirect()
                    filterContext.Result = Redirect("~/Account/Login");
                }
                // return;
            }

            if (objLoginInfo != null)
            {
                _BaseService.Repository.LoginUserID   = objLoginInfo.Id;
                _BaseService.Repository.LoginUserName = objLoginInfo.WeChatUserID;
                SetLanguage("EN");
            }

            // System.Threading.Thread.Sleep(5000);

            //Logger log = Logger.GetLogger(filterContext.ActionDescriptor.ControllerDescriptor.ControllerType.FullName, CurrentUserInfo.USERREALNAME);
            //log.Debug(WEBUI.Common.LogHelper.GetActionInfo(filterContext));

            //lstMenus=Session["UserMenus"] as List<BASE_SYSMENU>;
#endif

            base.OnActionExecuting(filterContext);
        }