コード例 #1
0
        public override void OnException(ExceptionContext filterContext)
        {
            HS_ErrRec ex = new HS_ErrRec();

            try
            {
                ContentResult contentResult = new ContentResult();
                contentResult.Content          = JsonStringResult.Error(OperateResCodeEnum.内部错误);
                filterContext.Result           = contentResult;
                filterContext.ExceptionHandled = true;

                ex.Action     = (filterContext.RouteData.Values["action"]).ToString();
                ex.AddTime    = DateTime.Now;
                ex.Controller = (filterContext.RouteData.Values["controller"]).ToString();
                ex.ErrorMsg   = filterContext.Exception.Message;
                ex.IP         = StringUtil.GetIP();
                ex.StackTrace = filterContext.Exception.StackTrace;
                ex.Arguments  = "";
                ex.DataSource = (int)DataSourceEnum.Web;
                ErrRecBll.Instance.AsyncInsert(ex);
            }
            catch (Exception ep)
            {
            }
        }
コード例 #2
0
        public override void OnException(ExceptionContext filterContext)
        {
            HS_ErrRec ex = new HS_ErrRec();

            try
            {
                ContentResult contentResult = new ContentResult();
                contentResult.Content          = JsonStringResult.Error(OperateResCodeEnum.内部错误);
                filterContext.Result           = contentResult;
                filterContext.ExceptionHandled = true;

                ex.Action     = (filterContext.RouteData.Values["action"]).ToString();
                ex.AddTime    = DateTime.Now;
                ex.Controller = (filterContext.RouteData.Values["controller"]).ToString();
                ex.ErrorMsg   = filterContext.Exception.Message;
                ex.IP         = StringUtil.GetIP();
                ex.StackTrace = filterContext.Exception.StackTrace;
                ex.Arguments  = "";
                ex.DataSource = (int)DataSourceEnum.API;
                ErrRecBll.Instance.AsyncInsert(ex);

                DataExchangeBll.Instance.AsyncInsert((filterContext.RouteData.Values["action"]).ToString(), (filterContext.RouteData.Values["controller"]).ToString(),
                                                     filterContext.Controller.TempData["fullData"].TryParseString(), contentResult.Content);
            }
            catch (Exception ep)
            {
            }
            //filterContext.HttpContext.Response.Clear();
            //filterContext.HttpContext.Response.StatusCode = 200;
            //filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
コード例 #3
0
        public ActionResult DoLogin()
        {
            string res = JsonStringResult.VerifyFail();

            try
            {
                if (GeetestValidate.Validate())
                {
                    CUsers user = UsersBll.Instance.Login(Request["LoginName"].TryParseString(), Request["Password"].TryParseString());
                    if (user != null)
                    {
                        string userJson = JsonConvert.SerializeObject(user, new JsonSerializerSettings
                        {
                            DateFormatString = "yyyy-MM-dd HH:mm:ss"
                        });
                        CookieHelper.SetCookie("User", userJson, DateTime.Now.AddDays(30));
                        res = JsonStringResult.SuccessResult();
                    }
                    else
                    {
                        res = JsonStringResult.Error(OperateResCodeEnum.用户名或密码错误);
                    }
                }
                else
                {
                    res = JsonStringResult.Error(OperateResCodeEnum.验证码错误);
                }
            }
            catch (Exception ex)
            {
                res = JsonStringResult.Error(OperateResCodeEnum.内部错误);
            }
            return(Content(res));
        }
コード例 #4
0
        public ActionResult DoRegister()
        {
            string res = JsonStringResult.VerifyFail();

            try
            {
                if (GeetestValidate.Validate())
                {
                    res = UsersBll.Instance.Register(Request["UserName"].TryParseString(), Request["Password"].TryParseString(), Request["Mobile"].TryParseString(),
                                                     Request["InvitationCode"].TryParseString(), Request["NickName"].TryParseString());
                    var objRes = JsonConvert.DeserializeObject <APIResultBase>(res);
                    if (objRes.code == (int)OperateResCodeEnum.成功)
                    {
                        string user = JsonConvert.SerializeObject(UsersBll.Instance.GetUserByUserName(Request["UserName"].TryParseString()), new JsonSerializerSettings
                        {
                            DateFormatString = "yyyy-MM-dd HH:mm:ss"
                        });
                        CookieHelper.SetCookie("User", user, DateTime.Now.AddDays(30));
                    }
                }
                else
                {
                    res = JsonStringResult.Error(OperateResCodeEnum.验证码错误);
                }
            }
            catch (Exception ex)
            {
                res = JsonStringResult.Error(OperateResCodeEnum.内部错误);
            }
            return(Content(res));
        }
コード例 #5
0
        public ActionResult ValidateUserName()
        {
            string res   = JsonStringResult.VerifyFail();
            var    param = JObject.Parse(TempData["param"].TryParseString());

            res = UsersBll.Instance.IsRepeat(param["UserName"].TryParseString()) ? JsonStringResult.Error(OperateResCodeEnum.用户名重复) : JsonStringResult.SuccessResult();
            return(Content(res));
        }
コード例 #6
0
        public ActionResult ValidateCode()
        {
            string res = JsonStringResult.Error(OperateResCodeEnum.验证码错误);

            if (GeetestValidate.Validate())
            {
                res = JsonStringResult.SuccessResult();
            }
            return(Content(res));
        }
コード例 #7
0
        /// <summary>
        /// 签名认证
        /// </summary>
        /// <param name="eventArgs"></param>
        public override void OnEntry(MethodExecutionArgs eventArgs)
        {
            Arguments arguments = eventArgs.Arguments;

            if (!UsersBll.Instance.AuthenticationSign(arguments[0].ToString()))
            {
                throw new Exception(JsonStringResult.Error(OperateResCodeEnum.签名验证失败));
            }

            base.OnEntry(eventArgs);
        }
コード例 #8
0
        public ActionResult DoLogOut()
        {
            string res = JsonStringResult.VerifyFail();

            try
            {
                CookieHelper.RemoveCookie("User");
                res = JsonStringResult.SuccessResult();
            }
            catch (Exception ex)
            {
                res = JsonStringResult.Error(OperateResCodeEnum.内部错误);
            }
            return(Content(res));
        }
コード例 #9
0
ファイル: UsersBll.cs プロジェクト: drawde/FriendshipFirst
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <param name="mobile"></param>
        /// <param name="email"></param>
        /// <param name="invitationCode"></param>
        /// <param name="nickName"></param>
        /// <param name="headImg"></param>
        /// <returns></returns>
        public string Register(string userName, string pwd, string mobile, string email, string nickName, string headImg = "")
        {
            if (userName.IsNullOrEmpty() || pwd.IsNullOrEmpty() || nickName.IsNullOrEmpty())
            {
                return(JsonStringResult.Error(OperateResCodeEnum.参数错误));
            }
            if (!StringUtil.IsNatural_Number(userName))
            {
                return(JsonStringResult.Error(OperateResCodeEnum.参数错误));
            }
            if (IsRepeat(userName))
            {
                return(JsonStringResult.Error(OperateResCodeEnum.用户名重复));
            }
            //if (!mobile.IsNullOrEmpty() && IsMobileRepeat(mobile))
            //{
            //    return OperateJsonRes.Error(OperateResCodeEnum.手机号重复);
            //}
            //if (!email.IsNullOrEmpty() && IsEmailRepeat(email))
            //{
            //    return OperateJsonRes.Error(OperateResCodeEnum.邮箱重复);
            //}
            string userCode = SignUtil.CreateSign(userName + RandomUtil.CreateRandomStr(10) + DateTime.Now.ToString("yyyyMMddHHmmss"));

            FF_User user = new FF_User();

            user.AddTime    = DateTime.Now;
            user.Email      = email.TryParseString();
            user.Mobile     = mobile.TryParseString();
            user.Password   = SignUtil.CreateSign(pwd);
            user.UserCode   = userCode;
            user.UserName   = userName;
            user.NickName   = nickName;
            user.HeadImg    = headImg.TryParseString();
            user.SecretCode = SignUtil.CreateSign(user.UserName + user.UserCode + RandomUtil.CreateRandomStr(10) + DateTime.Now.Ticks);
            user.OpenID     = "";
            _repository.Insert(user);


            return(JsonStringResult.SuccessResult(user.UserCode));
        }
コード例 #10
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
            HttpContext.Current.Response.ContentType = "text/plain";
            ContentResult contentResult = new ContentResult();

            try
            {
                var    Request = filterContext.RequestContext.HttpContext.Request;
                string data    = "";
                if (Request.HttpMethod.ToLower() == "post")
                {
                    using (Stream s = System.Web.HttpContext.Current.Request.InputStream)
                    {
                        byte[] b = new byte[s.Length];
                        s.Read(b, 0, (int)s.Length);
                        data = Encoding.UTF8.GetString(b);
                    };
                }
                else
                {
                    data = filterContext.RequestContext.HttpContext.Request["data"].TryParseString();
                }
                if (data.IsNullOrEmpty())
                {
                    data = filterContext.Controller.TempData["fullData"].TryParseString();
                }


                if (data.IsNullOrEmpty())
                {
                    contentResult.Content = JsonStringResult.Error(OperateResCodeEnum.签名验证失败, "");
                    filterContext.Result  = contentResult;
                    return;
                }
                APIReciveData im = JsonConvert.DeserializeObject <APIReciveData>(data);

                //if (IsValidate && im.token.IsNullOrEmpty())
                //{
                //    //签名验证
                //    if (string.IsNullOrEmpty(im.appid))
                //    {
                //        contentResult.Content = OperateJsonRes.Error(OperateResCodeEnum.签名验证失败, "");
                //        filterContext.Result = contentResult;
                //        return;
                //    }
                //    if (string.IsNullOrEmpty(im.apiname))
                //    {
                //        contentResult.Content = OperateJsonRes.Error(OperateResCodeEnum.签名验证失败, "");
                //        filterContext.Result = contentResult;
                //        return;
                //    }
                //}
                //else
                if (IsValidate)
                {
                    if (!UsersBll.Instance.AuthenticationSign(im))
                    {
                        contentResult.Content = JsonStringResult.Error(OperateResCodeEnum.签名验证失败);
                        filterContext.Result  = contentResult;
                        return;
                    }

                    //var lt = LoginTokenBll.Instance.GetUserInfoByToken(im.token);
                    //if (lt == null)
                    //{
                    //    contentResult.Content = OperateJsonRes.Error(OperateResCodeEnum.登录失败, "");
                    //    filterContext.Result = contentResult;
                    //    return;
                    //}
                    //else if (lt.AddTime < DateTime.Now.AddDays(-1))
                    //{
                    //    LoginTokenBll.Instance.Delete(lt.ID);
                    //    contentResult.Content = OperateJsonRes.Error(OperateResCodeEnum.登录失败, "");
                    //    filterContext.Result = contentResult;
                    //    return;
                    //}
                    //else
                    //{
                    //    filterContext.Controller.TempData["LoginToken"] = lt;
                    //}
                }
                filterContext.Controller.TempData["param"]    = im.param.TryParseString();
                filterContext.Controller.TempData["version"]  = im.version.TryParseString();
                filterContext.Controller.TempData["fullData"] = JsonConvert.SerializeObject(im);
            }
            catch (Exception ex) {
                contentResult.Content = JsonStringResult.Error(OperateResCodeEnum.内部错误, "内部错误");
                filterContext.Result  = contentResult;
            }
            return;
        }