示例#1
0
        public HttpResponseMessage AddUser([FromBody] JObject jdata)
        {
            /**
             * 添加用户信息
             * 所需参数:头部使用auth验证
             *                用户自行设置的用户名称
             * 根据auth头解密出信息 获取手机号,后台自动生成用户唯一ID
             * UserID生成 使用随机数进行生成 生成前判断数据库中是否存在该ID
             * 返回1为添加成功 0为添加失败 -1为用户已存在
             */
            //获取解析过的token值 包含手机号和短信ID
            AuthInfo            info   = RequestContext.RouteData.Values["auth"] as AuthInfo;
            HttpResponseMessage result = new HttpResponseMessage();
            dynamic             json   = jdata;
            retUserAuth         ret    = new retUserAuth();
            //判断用户是否已经存在
            UserInfo userSelect = userSer.Where(a => a.UserTel == info.UserTel).FirstOrDefault();

            if (userSelect != null)
            {
                ret.IsUser     = -1;
                ret.userAuth   = string.Empty;
                result.Content = new StringContent(JsonConvert.SerializeObject(ret), Encoding.GetEncoding("UTF-8"), "application/json");
                return(result);
            }
            UserInfo userModel = new UserInfo();

            userModel.UserTel  = info.UserTel;
            userModel.RegDate  = DateTime.Now;
            userModel.UserName = json.UserName;
            userModel.UserID   = GetRandomID().ToString();
            try
            {
                userSer.Add(userModel);
                ret.IsUser     = 1;
                ret.userAuth   = getUserAuth(userModel.UserTel);
                result.Content = new StringContent(JsonConvert.SerializeObject(ret), Encoding.GetEncoding("UTF-8"), "application/json");
                return(result);
            }
            catch
            {
                ret.IsUser     = 0;
                ret.userAuth   = string.Empty;
                result.Content = new StringContent(JsonConvert.SerializeObject(ret), Encoding.GetEncoding("UTF-8"), "application/json");
                return(result);
            }
        }
示例#2
0
        public HttpResponseMessage IsUser(dynamic obj)
        {   /**
             * 根据auth获取手机号信息 对数据库进行查询
             * 返回1表示手机号已经被注册过
             * 返回0表示手机号第一次注册 需要设置用户名 才可进行后续操作
             */
            AuthInfo            info   = RequestContext.RouteData.Values["auth"] as AuthInfo;
            HttpResponseMessage result = new HttpResponseMessage();


            if (!string.IsNullOrEmpty(info.UserTel))
            {
                UserInfo userModel = userSer.Where(a => a.UserTel == info.UserTel).FirstOrDefault();
                if (userModel != null)
                {
                    retUserAuth ret = new retUserAuth();
                    ret.IsUser     = 1;
                    ret.userAuth   = getUserAuth(info.UserTel);
                    result.Content = new StringContent(JsonConvert.SerializeObject(ret), Encoding.GetEncoding("UTF-8"), "application/json");
                    return(result);
                    //return JsonConvert.SerializeObject(ret);
                }
                else
                {
                    retUserAuth ret = new retUserAuth();
                    ret.IsUser     = 0;
                    ret.userAuth   = string.Empty;
                    result.Content = new StringContent(JsonConvert.SerializeObject(ret), Encoding.GetEncoding("UTF-8"), "application/json");
                    return(result);
                }
            }
            else
            {
                retUserAuth ret = new retUserAuth();
                ret.IsUser     = 0;
                ret.userAuth   = string.Empty;
                result.Content = new StringContent(JsonConvert.SerializeObject(ret), Encoding.GetEncoding("UTF-8"), "application/json");
                return(result);
                //HttpResponseMessage result=new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(ret), Encoding.GetEncoding("UTF-8"), "application/json") };
                //return result;
            }
        }