Exemplo n.º 1
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
                String.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException(error);
            }

            HttpResponseBase response = context.HttpContext.Response;

            if (!ValidateHelper.IsNullOrEmpty(ContentType))
            {
                response.ContentType = ContentType;
            }
            else
            {
                response.ContentType = "application/json";
            }
            if (ContentEncoding != null)
            {
                response.ContentEncoding = ContentEncoding;
            }
            if (Data != null)
            {
                string jsonstring = ConverHelper.ToJson(Data);
                //JavaScriptSerializer serializer = new JavaScriptSerializer();
                //string jsonstring = serializer.Serialize(Data);


                ////string p = @"\\/Date\((\d+)\+\d+\)\\/";

                //string p = @"\\/Date\(\d+\)\\/";

                //MatchEvaluator matchEvaluator = new MatchEvaluator(ConvertJsonDateToDateString);

                //Regex reg = new Regex(p);

                //jsonstring = reg.Replace(jsonstring, matchEvaluator);
                response.Write(jsonstring);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="model">返回用户信息</param>
        /// <param name="user_id">登录名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public JsonMessage Login(ref AccountModel model, string user_id, string pwd)
        {
            JsonMessage jsonMsg = new JsonMessage(); //返回Json
            int         result  = -1;                //类型(成功 、失败)

            try
            {
                if (ValidateHelper.IsNullOrEmpty(StringHelper.Trim(user_id)))
                {
                    throw new CustomException(0, "用户名不能为空");
                }
                if (ValidateHelper.IsNullOrEmpty(pwd))
                {
                    throw new CustomException(0, "密码不能为空");
                }

                //UserID = userId;
                DataTable            dt   = _userRep.Login(user_id, MD5Cryption.MD5(pwd));
                IList <SysUserModel> list = ConverHelper.ToList <SysUserModel>(dt);
                if (list.Count < 1)
                {
                    throw new CustomException(2, "用户名或密码错误");//用户名或密码错误
                }
                if (!ConverHelper.ToBool(list[0].IS_ABLED))
                {
                    throw new CustomException(3, "账号已被禁用,请联系系统管理员");//账号是否被禁用
                }
                model.UserCode = list[0].USER_CODE;
                model.UserName = list[0].USER_NAME;
                model.LoginNo  = list[0].USER_CODE;
                model.QRCode   = list[0].QR_CODE;
                model.DeptCode = list[0].DEPT_CODE;

                jsonMsg = ServiceResult.Message(1, "登录成功");

                SessionHelper.SetSession("Account", model);

                CookieHelper.SetCookie("Account", DESCryption.Encrypt(ConverHelper.ToJson(model)));
            }
            catch (CustomException ex)
            {
                jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message);
            }
            catch (Exception ex)
            {
                jsonMsg = ServiceResult.Message(-1, ex.Message);
            }
            //写入log
            SysLogLoginModel log = new SysLogLoginModel();

            log.LOGIN_ID      = GuidHelper.GenerateComb().ToString();
            log.USER_CODE     = user_id;
            log.USER_PWD      = MD5Cryption.MD5(pwd);
            log.USER_PWD_LAWS = pwd;
            log.LOGIN_IP      = NetHelper.GetUserIp;
            log.LOGIN_RESULT  = jsonMsg.type == 1 ? "SUCCESS" : "FAIL";
            log.LOGIN_MSG     = jsonMsg.message;
            _loglRep.Insert(log);

            return(jsonMsg);
        }