コード例 #1
0
        /// <summary>
        /// 切换用户
        /// </summary>
        /// <returns></returns>
        public ActionResult ChangeUser()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            if (_Response == null)
            {
                _Response = Response;
            }
            if (_Session == null)
            {
                _Session = Session;
            }
            SetRequest(_Request);
            UserInfo currUser = GetCurrentUser(_Request);

            if (currUser == null)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "非法操作"
                }));
            }
            string username = _Request["username"].ObjToStr();

            if (username == "admin")
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "没有权限"
                }));
            }
            Guid     userId   = UserOperate.GetUserIdByUserName(username);
            UserInfo userInfo = UserOperate.GetUserInfo(userId);

            if (userInfo == null)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "用户不存在"
                }));
            }
            userInfo.ClientBrowserWidth  = currUser.ClientBrowserWidth;
            userInfo.ClientBrowserHeight = currUser.ClientBrowserHeight;
            CacheUserData(userInfo); //缓存cookie
            return(Json(new ReturnResult()
            {
                Success = true, Message = string.Empty
            }));
        }
コード例 #2
0
 /// <summary>
 /// 登录前
 /// </summary>
 /// <param name="filterContext">过滤上下文</param>
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     try
     {
         UserInfo admin    = UserOperate.GetSuperAdmin(); //获取管理员信息
         string   username = filterContext.ActionArguments["username"].ObjToStr();
         loginLog.UserId         = UserOperate.GetUserIdByUserName(username).ObjToStr();
         loginLog.LoginName      = username;
         loginLog.LoginTime      = DateTime.Now;
         loginLog.LoginIp        = WebHelper.GetClientIP(filterContext.HttpContext.Request);
         loginLog.CreateUserId   = admin.UserId; //添加人默认为空
         loginLog.CreateDate     = DateTime.Now;
         loginLog.CreateUserName = admin.AliasName;
         loginLog.ModifyUserId   = admin.UserId; //修改人默认为空
         loginLog.ModifyDate     = DateTime.Now;
         loginLog.ModifyUserName = admin.AliasName;
     }
     catch { }
 }
コード例 #3
0
        /// <summary>
        /// 应用程序认证请求
        /// </summary>
        /// <param name="sender">发送对象</param>
        /// <param name="e">事件参数</param>
        public void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication app      = (HttpApplication)sender;
            string          username = string.Empty;

            if (app.Context.User != null && app.Context.User.Identity != null)
            {
                username = app.Context.User.Identity.Name;
            }
            int w = 0;
            int h = 0;

            if (app.Context.Request["nfm"].ObjToInt() == 1)
            {
                username = app.Context.Request["un"].ObjToStr(); //请求中自带的用户名
                w        = app.Context.Request["w"].ObjToInt();
                h        = app.Context.Request["h"].ObjToInt();
            }
            if (!string.IsNullOrEmpty(username))
            {
                UserInfo tempUserInfo = UserInfo.GetCurretnUser(app.Context);
                if (tempUserInfo == null || tempUserInfo.UserId == Guid.Empty || tempUserInfo.UserName.ToLower() != username.ToLower())
                {
                    Guid     userId   = UserOperate.GetUserIdByUserName(username);
                    UserInfo userInfo = UserOperate.GetUserInfo(userId);
                    if (w > 0 && h > 0)
                    {
                        userInfo.ClientBrowserWidth  = w;
                        userInfo.ClientBrowserHeight = h;
                    }
                    //缓存用户扩展信息
                    UserInfo.CacheUserExtendInfo(userInfo.UserName, userInfo.ExtendUserObject);
                    //保存票据
                    FormsPrincipal.Login(userInfo.UserName, userInfo, UserInfo.ACCOUNT_EXPIRATION_TIME, app.Context);
                }
                FormsPrincipal.TrySetUserInfo(app.Context);
            }
            else
            {
                FormsPrincipal.TrySetUserInfo(app.Context);
            }
        }