示例#1
0
        /// <summary>
        /// 返回错误结果的静态方法
        /// </summary>
        /// <param name="message">错误消息</param>
        /// <returns></returns>
        public static OperatorResult Error(string message = "")
        {
            var result = new OperatorResult(false, message);

            result.Code = ErrorCodes.Error;
            return(result);
        }
        /// <summary>
        /// 前置拦截器
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        private Response BeforeRequest(NancyContext ctx)
        {
            string path = ctx.ResolvedRoute.Description.Path;
            //验证登录状态
            ReqParameter req = this.Bind <ReqParameter>();

            loginMark = req.loginMark;
            token     = req.token;
            if (path == "/learun/adms/user/login" || path == "/" || path == "/bgimg")
            {// 登录接口,默认页面接口不做权限验证处理
                return(null);
            }

            OperatorResult res = OperatorHelper.Instance.IsOnLine(req.token, req.loginMark);

            if (res.stateCode == -1)
            {
                return(this.Fail("未找到登录信息"));
            }
            if (res.stateCode == 0)
            {
                return(this.Fail("登录信息已过期"));
            }
            else
            {
                // 获取登录者信息
                userInfo = res.userInfo;
            }
            return(null);
        }
示例#3
0
        /// <summary>
        /// 判断登录状态
        /// </summary>
        /// <param name="token">登录票据</param>
        /// <param name="loginMark">登录设备标识</param>
        /// <returns>-1未登录,1登录成功,0登录过期</returns>
        public OperatorResult IsOnLine()
        {
            //string token = WebHelper.GetCookie(ReadonlyKey.LoginUserToken).ToString();
            string loginMark = WebHelper.GetCookie(ReadonlyKey.LoginUserMarkKey).ToString();


            OperatorResult operatorResult = new OperatorResult();

            operatorResult.stateCode = -1; // -1未登录,1登录成功,0登录过期
            try
            {
                if (string.IsNullOrEmpty(loginMark))
                {
                    return(operatorResult);
                }
                Operator operatorInfo = CacheHelper.Get <Operator>(ReadonlyKey.cacheKeyOperator + loginMark);
                if (operatorInfo != null)
                {
                    TimeSpan span = (TimeSpan)(DateTime.Now - operatorInfo.logTime);
                    if (span.TotalHours >= 2)// 登录操作过12小时移除
                    {
                        EmptyCurrent();
                    }
                    else
                    {
                        Game.Entity.SysManage.Sys_LoginLog userInfo = new Entity.SysManage.Sys_LoginLog();

                        if (!string.IsNullOrWhiteSpace(operatorInfo.account))
                        {
                            userInfo.CreateDate  = operatorInfo.logTime;
                            userInfo.IPAddress   = operatorInfo.iPAddress;
                            userInfo.BrowserType = operatorInfo.browser;

                            if (HttpContext.Current != null)
                            {
                                HttpContext.Current.Items.Add("LoginUserInfo", userInfo);
                            }
                            operatorResult.userInfo  = userInfo;
                            operatorResult.stateCode = 1;

                            operatorInfo.logTime = DateTime.Now;
                            CacheHelper.Set <Operator>(ReadonlyKey.cacheKeyOperator + operatorInfo.account, operatorInfo); //写入缓存信息:当前连接用户
                        }
                        else
                        {
                            operatorResult.stateCode = 0;
                        }
                    }
                }
                return(operatorResult);
            }
            catch (Exception)
            {
                return(operatorResult);
            }
        }
        public void DefaultConstructor_TypeAndValueAttributes_AreEmpty()
        {
            OperatorResult result = new OperatorResult();

            string type = result.Element.Attribute("Type").Value;
            string value = result.Element.Attribute("Value").Value;

            Assert.AreEqual("", type);
            Assert.AreEqual("", value);
        }
        public void GetOperator_TypeElementIsPresent_ReturnsLateBoundOperator()
        {
            XElement element = CreateOperatorResultXElement(null);

            OperatorResult result = new OperatorResult(element);

            Operator op = result.GetOperator(null);

            Assert.IsNotNull(op);
        }
示例#6
0
        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="_"></param>
        /// <returns></returns>
        private Response Login(dynamic _)
        {
            LoginModel loginModel = this.GetReqData <LoginModel>();

            #region 内部账户验证
            UserEntity userEntity = userIBLL.CheckLogin(loginModel.username, loginModel.password);

            #region 写入日志
            LogEntity logEntity = new LogEntity();
            logEntity.F_CategoryId     = 1;
            logEntity.F_OperateTypeId  = ((int)OperationType.Login).ToString();
            logEntity.F_OperateType    = EnumAttribute.GetDescription(OperationType.Login);
            logEntity.F_OperateAccount = loginModel.username + "(" + userEntity.F_RealName + ")";
            logEntity.F_OperateUserId  = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username;
            logEntity.F_Module         = Config.GetValue("SoftName");
            #endregion

            if (!userEntity.LoginOk)//登录失败
            {
                //写入日志
                logEntity.F_ExecuteResult     = 0;
                logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg;
                logEntity.WriteLog();
                return(Fail(userEntity.LoginMsg));
            }
            else
            {
                string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息
                //写入日志
                logEntity.F_ExecuteResult     = 1;
                logEntity.F_ExecuteResultJson = "登录成功";
                logEntity.WriteLog();

                OperatorResult res = OperatorHelper.Instance.IsOnLine(token, this.loginMark);
                res.userInfo.password  = null;
                res.userInfo.secretkey = null;

                var jsonData = new
                {
                    baseinfo = res.userInfo,
                    post     = postIBLL.GetListByPostIds(res.userInfo.postIds),
                    role     = roleIBLL.GetListByRoleIds(res.userInfo.roleIds)
                };
                return(Success(jsonData));
            }
            #endregion
        }
 private bool AuthorizeCheck(ActionExecutingContext filterContext)
 {
     try
     {
         OperatorResult result = OperatorProvider.Provider.IsOnLine("pc_").GetAwaiter().GetResult();
         if (result.stateCode <= 0)
         {
             return(false);
         }
         var roleId = result.userInfo.RoleId;
         return(_service.ActionValidate(roleId, _authorize, true).GetAwaiter().GetResult());
     }
     catch (System.Exception)
     {
         return(false);
     }
 }
 private bool ActionAuthorize(ActionExecutingContext filterContext)
 {
     try
     {
         OperatorResult result = OperatorProvider.Provider.IsOnLine("pc_").GetAwaiter().GetResult();
         if (result.stateCode <= 0)
         {
             return(false);
         }
         var roleId = result.userInfo.RoleId;
         var action = GlobalContext.ServiceProvider?.GetService <IHttpContextAccessor>().HttpContext.Request.Path;
         return(_service.ActionValidate(roleId, action).GetAwaiter().GetResult());
     }
     catch (System.Exception)
     {
         return(false);
     }
 }
 public OperatorResult GetOperator(string Badge)
 {
     try
     {
         InitEmployeeContext();
         var searchBadge = SearchBadge(Badge);
         return(new OperatorResult
         {
             Operator = employeeEntities.Employees.FirstOrDefault(b => b.Badge == searchBadge).ToOperator(),
         });
     }
     catch (Exception e)
     {
         var result = new OperatorResult();
         result.SetFail(e);
         return(result);
     }
 }
示例#10
0
        /// <summary>
        /// 验证登录票据
        /// </summary>
        /// <param name="ctx">上下文数据</param>
        /// <returns></returns>
        private Response BeforeRequest(NancyContext ctx)
        {
            //验证登录状态
            ReqParameter   req = this.Bind <ReqParameter>();
            OperatorResult res = OperatorHelper.Instance.IsOnLine(req.token, req.loginMark);

            if (res.stateCode == -1)
            {
                return(this.Fail("未找到登录信息"));
            }
            if (res.stateCode == 0)
            {
                return(this.Fail("登录信息已过期"));
            }
            else
            {
                // 获取登录者信息
                userInfo = res.userInfo;
            }
            return(null);
        }
示例#11
0
        private bool LoginAuthorize(ActionExecutingContext filterContext)
        {
            try
            {
                OperatorResult result = OperatorProvider.Provider.IsOnLine("pc_").Result;
                switch (result.stateCode)
                {
                case 1:
                    return(true);

                case 0:
                    OperatorProvider.Provider.EmptyCurrent("pc_");
                    //filterContext.HttpContext.Response.WriteAsync("<script>top.location.href ='" + filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=408" + "';if(document.all) window.event.returnValue = false;</script>");
                    filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=408");
                    return(false);

                case -1:
                    OperatorProvider.Provider.EmptyCurrent("pc_");
                    //filterContext.HttpContext.Response.WriteAsync("<script>top.location.href ='" + filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=408" + "';if(document.all) window.event.returnValue = false;</script>");
                    filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=408");
                    return(false);

                case -2:
                    OperatorProvider.Provider.EmptyCurrent("pc_");
                    //filterContext.HttpContext.Response.WriteAsync("<script>top.location.href ='" + filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=401" + "';if(document.all) window.event.returnValue = false;</script>");
                    filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=401");
                    return(false);

                default:
                    return(false);
                }
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
        public void GetOperator_TypeElementIsEmpty_Throws()
        {
            OperatorResult result = new OperatorResult();

            result.GetOperator(null);
        }
        public void ToBinaryOperatorResult_OperatorType_IsSame()
        {
            Mock<IBotProcessContext> contextMock = new Mock<IBotProcessContext>();
            OperatorResult result = new OperatorResult
            {
                InnerOperation = new ConstantResult { Value = "4" }
            };
            result.SetOperator<AddOperator>("8");

            BinaryOperatorResult binary = result.ToBinaryOperatorResult();

            Operator op = binary.GetOperator(null);

            Assert.IsInstanceOfType(op, typeof(AddOperator));
        }
        public void ToBinaryOperatorResult_Elements_AreNotEqual()
        {
            Mock<IBotProcessContext> contextMock = new Mock<IBotProcessContext>();
            OperatorResult result = new OperatorResult
            {
                InnerOperation = new ConstantResult { Value = "4" }
            };
            result.SetOperator<AddOperator>("8");
            XElement parent = new XElement("Target", result.Element);

            BinaryOperatorResult binary = result.ToBinaryOperatorResult();

            bool containsOperatorResult = parent.Elements("OperatorResult").Any();
            bool containsBinaryOperatorResult = parent.Elements("BinaryOperatorResult").Any();

            Assert.AreNotEqual(result.Element, binary.Element);
        }
        public void InnerOperation_Set_ReplacesInnerElement()
        {
            XElement innerResult = CreatePatternResultXElement("some name");
            XElement element = CreateOperatorResultXElement(innerResult);
            OperatorResult result = new OperatorResult(element);

            result.InnerOperation = new ConstantResult { Value = "4" };

            ConstantResult innerOperation = result.InnerOperation as ConstantResult;

            Assert.IsNotNull(innerOperation);
            Assert.AreNotEqual(innerResult.Parent, result.Element);
            Assert.AreEqual("4", innerOperation.Value);
        }
示例#16
0
 /// <summary>
 /// 合并结果,仅限于字符串
 /// </summary>
 /// <param name="result">被合并的对象</param>
 /// <returns></returns>
 public void Merge(OperatorResult result)
 {
     Flag &= result.Flag;
     Code  = result.Code > Code ? result.Code : Code;
     Data += (string)result.Data;
 }
        public void InnerOperation_Get_ReadsInnerElement()
        {
            string expected = "Hi!";
            XElement innerResult = CreatePatternResultXElement(expected);
            XElement element = CreateOperatorResultXElement(innerResult);
            OperatorResult result = new OperatorResult(element);

            PatternResult innerOperation = result.InnerOperation as PatternResult;

            Assert.IsNotNull(innerOperation);
            Assert.AreEqual(expected, innerOperation.Name);
            Assert.AreEqual(innerResult, innerOperation.Element);
        }
        public void SetOperator_InvalidOperatorType_Throws()
        {
            OperatorResult result = new OperatorResult();

            result.SetOperator(typeof(int), "");
        }
        public void ToBinaryOperatorResult_ParentElement_ContainsOnlyBinaryResult()
        {
            Mock<IBotProcessContext> contextMock = new Mock<IBotProcessContext>();
            OperatorResult result = new OperatorResult
            {
                InnerOperation = new ConstantResult { Value = "4" }
            };
            result.SetOperator<AddOperator>("8");
            XElement parent = new XElement("Target", result.Element);

            BinaryOperatorResult binary = result.ToBinaryOperatorResult();

            bool containsOperatorResult = parent.Elements("OperatorResult").Any();
            bool containsBinaryOperatorResult = parent.Elements("BinaryOperatorResult").Any();

            Assert.IsFalse(containsOperatorResult);
            Assert.IsTrue(containsBinaryOperatorResult);
        }
        public void ToBinaryOperatorResult_Value_IsSame()
        {
            string expected = "8";
            Mock<IBotProcessContext> contextMock = new Mock<IBotProcessContext>();
            OperatorResult result = new OperatorResult
            {
                InnerOperation = new ConstantResult { Value = "4" }
            };
            result.SetOperator<AddOperator>(expected);

            BinaryOperatorResult binary = result.ToBinaryOperatorResult();

            string actual = binary.ValueOperation.Execute(contextMock.Object);

            Assert.AreEqual(expected, actual);
        }
        public void DefaultConstructor_InnerOperation_ReturnsNull()
        {
            OperatorResult result = new OperatorResult();

            Assert.IsNull(result.InnerOperation);
        }
示例#22
0
        public OperatorResult Post([FromBody] LogModel log)
        {
            OperatorResult result = _service.Add(log);

            return(result);
        }
        public void SetOperator_GenericOverload_SetTypeElement()
        {
            OperatorResult result = new OperatorResult();

            result.SetOperator<AddOperator>("4");

            string actual = result.Element.Attribute("Type").Value;

            Assert.AreEqual("Add", actual);
        }