public virtual JsonResult RequestUser()
 {
     try
     {
         string token = Request.Headers["Authorization"];
         if (string.IsNullOrEmpty(token))
         {
             throw new TokenException("身份验证失败");
         }
         AuthInfo authInfo = JwtHelper.GetJwtDecode(token);
         //判断token正确性
         if (authInfo == null)
         {
             throw new TokenException("身份验证失败");
         }
         if (authInfo.Level == 2 || authInfo.Level == 3)
         {
             this.us = IBUIC.QueryUserNameUser(authInfo.UserName);
         }
         ;
         if (authInfo.Level == 1 || authInfo.Level == 5 || authInfo.Level == 4)
         {
             this.us = IBUC.QueryUserNameUser(authInfo.UserName);
         }
         //验证身份信息是否正确
         if (us == null || authInfo.UserName != us.UserName)
         {
             throw new TokenException("身份验证过期,请重新登录");
         }
         ;
         DateTime time = DateTime.Now;
         //验证token是否已经过期
         if (time > authInfo.EndTime)
         {
             throw new TokenException("身份验证过期,请重新登录");
         }
         ;
         using (StreamReader stream = new StreamReader(Request.InputStream))
         {
             string json = stream.ReadToEnd();
             if (!string.IsNullOrEmpty(json))
             {
                 try
                 {
                     this.param = JObject.Parse(json);
                 }
                 catch
                 {
                 }
             }
             else
             {
                 resultData.res = 205;
                 return(Json(resultData));
             }
         }
     }
     catch (HttpException ex)
     {
         this.resultData.res = 403;
         this.resultData.msg = ex.Message;
         return(Json(resultData));
     }
     resultData.res = 200;
     return(Json(resultData));
 }
        /// <summary>
        /// 买家登录
        /// </summary>
        /// <returns></returns>
        public JsonResult BuyerUserLogin()
        {
            string msgcode = string.Empty;

            using (StreamReader sr = new StreamReader(Request.InputStream))
            {
                string json = sr.ReadToEnd();
                if (string.IsNullOrEmpty(json))
                {
                    resultdata.msg = "没有获取到用户名和密码";
                    return(Json(resultdata));
                }
                obj = JObject.Parse(json);
            }
            string        UserName = obj["username"].ToString();
            string        PassWord = obj["password"].ToString();
            Regex         r1       = new Regex(@"^[1]+[3,5,6,7,8,9]+\d{9}$");
            Regex         r2       = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
            BuyerUserInfo bui      = null;

            #region 正则验证
            if (r1.IsMatch(UserName))
            {
                bui = IBUIC.QueryPhoneUser(UserName);
            }
            else if (r2.IsMatch(UserName))
            {
                bui = IBUIC.QueryEmailUser(UserName);
            }
            else
            {
                bui = IBUIC.QueryUserNameUser(UserName);
            }
            #endregion
            #region 登录验证
            if (bui == null)
            {
                resultdata.msg = "该账户不存在";
                return(Json(resultdata));
            }
            else
            {
                string loginstate = rh.GetString(BuyerUserLoginInfo + bui.ID.ToString());
                if ("1".Equals(loginstate))
                {
                    resultdata.msg = "该账户已经登录,请勿重复登录";
                    return(Json(resultdata));
                }
                else
                {
                    if (PassWord.Equals(bui.PassWord))
                    {
                        resultdata.res = 200;
                        resultdata.msg = "登录成功";
                        DateTime StartTime = DateTime.Now;
                        string   token     = JwtHelper.CreateToken(bui, StartTime);
                        var      result    = new
                        {
                            token = token,
                            type  = bui.Level
                        };
                        resultdata.data = result;

                        //保存用户登录状态
                        DateTime EndTime = StartTime.AddDays(7);
                        TimeSpan Time    = EndTime - StartTime;
                        //保存用户登录状态
                        rh.SetString(BuyerUserLoginInfo + bui.ID.ToString(), "1", Time);
                        return(Json(resultdata));
                    }
                    else
                    {
                        resultdata.msg = "密码错误";
                        return(Json(resultdata));
                    }
                }
            }
            #endregion
        }
Пример #3
0
        /// <summary>
        /// 添加提现记录
        /// </summary>
        /// <returns></returns>
        public JsonResult AddWithdrawalInfo()
        {
            RequestUser();
            int            userInfo;
            int            userType;
            int            Mode   = 0;
            string         select = string.Empty;
            DataDictionary result = new DataDictionary();

            select   = GetParams("select");
            userInfo = int.Parse(GetParams("userInfo"));
            result   = IDDC.ITEM(user_info_Index, userInfo);
            DataDictionary results = new DataDictionary();

            userType = int.Parse(GetParams("userType"));
            results  = IDDC.ITEM(user_type_Index, userType);
            decimal Price = decimal.Parse(GetParams("price"));

            if (results.Key == "买家")
            {
                Mode = 2;
                if (result.Key == "用户名")
                {
                    var bui = IBUIC.QueryUserNameUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的用户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
                if (result.Key == "邮箱")
                {
                    var bui = IBUIC.QueryEmailUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的用户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
                if (result.Key == "电话号码")
                {
                    var bui = IBUIC.QueryPhoneUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的账户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
            }
            if (results.Key == "团队买家")
            {
                Mode = 3;
                if (result.Key == "用户名")
                {
                    var bui = IBUIC.QueryUserNameUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的用户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
                if (result.Key == "邮箱")
                {
                    var bui = IBUIC.QueryEmailUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的用户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
                if (result.Key == "电话号码")
                {
                    var bui = IBUIC.QueryPhoneUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的账户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
            }
            if (results.Key == "卖家")
            {
                Mode = 2;
                if (result.Key == "用户名")
                {
                    var bui = IBUC.QueryUserNameUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的用户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
                if (result.Key == "邮箱")
                {
                    var bui = IBUC.QueryEmailUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的用户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
                if (result.Key == "电话号码")
                {
                    var bui = IBUC.QueryPhoneUser(select);
                    if (bui != null)
                    {
                        mm.UserName    = bui.UserName;
                        mm.Email       = bui.Email;
                        mm.PhoneNumber = bui.PhoneNumber;
                        mm.Time        = DateTime.Now;
                    }
                    else
                    {
                        resultData.res = 500;
                        resultData.msg = "添加的账户不存在";
                        return(this.ResultJson(resultData));
                    }
                }
            }
            mm.Price     = Price;
            mm.Mode      = Mode;
            mm.MoneyType = 2;
            if (ICC.AddMoney(mm))
            {
                resultData.res = 200;
                resultData.msg = "添加成功";
                return(this.ResultJson(resultData));
            }
            else
            {
                resultData.msg = "添加失败";
                return(this.ResultJson(resultData));
            }
        }
        /// <summary>
        /// 买家注册
        /// </summary>
        /// <returns></returns>
        public JsonResult BuyerRegister()
        {
            string msgcode = string.Empty;

            using (StreamReader sr = new StreamReader(Request.InputStream))
            {
                string json = sr.ReadToEnd();
                if (string.IsNullOrEmpty(json))
                {
                    resultdata.msg = "没有获取到用户名和密码";
                    return(Json(resultdata));
                }
                obj = JObject.Parse(json);
            }
            ///账户类型
            int    Usertype            = int.Parse(obj["user_type"].ToString());
            string UserName            = obj["username"].ToString();
            string PhoneNumber         = obj["phonenumber"].ToString();
            string Email               = obj["email"].ToString();
            string WechatNumber        = obj["wechatnumber"].ToString();
            string PassWord            = obj["password"].ToString();
            string EnterpriseName      = obj["enterprisename"].ToString();
            string head                = obj["head"].ToString();
            string EnterpriseTaxNumber = obj["enterprisetaxnumber"].ToString();
            string code                = obj["code"].ToString();

            msgcode = rh.GetString(PhoneNumber);
            if (string.IsNullOrEmpty(msgcode))
            {
                resultdata.res = 500;
                resultdata.msg = "该验证码已失效,请重新输入";
                return(Json(resultdata));
            }
            else
            {
                if (!msgcode.Equals(code))
                {
                    resultdata.res = 500;
                    resultdata.msg = "该验证码有误,请重新输入";
                    return(Json(resultdata));
                }
            }
            if (IBUIC.QueryUserNameUser(UserName) != null)
            {
                resultdata.msg = "用户名已存在";
                return(Json(resultdata));
            }
            if (IBUIC.QueryPhoneUser(PhoneNumber) != null)
            {
                resultdata.msg = "电话号码已存在 ";
                return(Json(resultdata));
            }
            if (IBUIC.QueryEmailUser(Email) != null)
            {
                resultdata.msg = "邮箱已存在 ";
                return(Json(resultdata));
            }
            if (Usertype == 2)
            {
                BuyerUserInfo bui = new BuyerUserInfo();
                bui.UserName     = UserName;
                bui.PhoneNumber  = PhoneNumber;
                bui.Email        = Email;
                bui.WechatNumber = WechatNumber;
                bui.PassWord     = PassWord;
                bui.Head         = head;
                bui.Money        = 0;
                bui.Shape        = 0;                              //此属性表示审核状态
                bui.Level        = Convert.ToInt32(PowerEnum.Two); //接单权限
                if (IBUIC.BuyerUserInfoRegister(bui))
                {
                    resultdata.res = 200;
                    resultdata.msg = "注册成功";
                    return(Json(resultdata));
                }
                else
                {
                    resultdata.msg = "注册失败";
                    return(Json(resultdata));
                }
            }
            else if (Usertype == 3)
            {
                BuyerUserInfo bui = new BuyerUserInfo();
                bui.UserName            = UserName;
                bui.PhoneNumber         = PhoneNumber;
                bui.Email               = Email;
                bui.Head                = head;
                bui.WechatNumber        = WechatNumber;
                bui.PassWord            = PassWord;
                bui.EnterpriseName      = EnterpriseName;
                bui.EnterpriseTaxNumber = EnterpriseTaxNumber;
                bui.Money               = 0;
                bui.Shape               = 0;                                //此属性表示审核状态
                bui.Level               = Convert.ToInt32(PowerEnum.Three); //接单权限
                if (IBUIC.BuyerUserInfoRegister(bui))
                {
                    resultdata.res = 200;
                    resultdata.msg = "注册成功";
                    return(Json(resultdata));
                }
                else
                {
                    resultdata.msg = "注册失败";
                    return(Json(resultdata));
                }
            }
            else
            {
                resultdata.msg = "注册失败";
                return(Json(resultdata));
            }
        }