Exemplo n.º 1
0
        public HttpResponseMessage AddUser(UserParam data)
        {
            string content = this._addUser(data);

            return(new HttpResponseMessage
            {
                Content = new StringContent(content, Encoding.UTF8, "application/json")
            });
        }
Exemplo n.º 2
0
        private bool CheckAddUserParameters(UserParam parameter, out string result)
        {
            if (!OpenApiHelper.CheckSystemParameters(parameter.app_key, parameter.timestamp, parameter.sign, out result))
            {
                return(false);
            }
            parameter.user_name = DataHelper.CleanSearchString(parameter.user_name);
            if (string.IsNullOrWhiteSpace(parameter.user_name))
            {
                result = OpenApiErrorMessage.ShowErrorMsg((Enum)(object)OpenApiErrorCode.Parameters_Format_Error, "user_name");
                return(false);
            }
            if (MemberProcessor.FindMemberByUsername(parameter.user_name) != null)
            {
                result = OpenApiErrorMessage.ShowErrorMsg((Enum)(object)OpenApiErrorCode.Parameters_Format_Error, "user_name");
                return(false);
            }
            Regex regex  = new Regex("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$", RegexOptions.Compiled);
            Regex regex2 = new Regex("^0?(13|15|18|14|17)[0-9]{9}$", RegexOptions.Compiled);

            if (!string.IsNullOrWhiteSpace(parameter.email))
            {
                if (!regex.IsMatch(parameter.email))
                {
                    result = OpenApiErrorMessage.ShowErrorMsg((Enum)(object)OpenApiErrorCode.Parameters_Format_Error, "email");
                    return(false);
                }
                if (MemberProcessor.FindMemberByEmail(parameter.email) != null)
                {
                    result = OpenApiErrorMessage.ShowErrorMsg((Enum)(object)OpenApiErrorCode.Parameters_Format_Error, "email");
                    return(false);
                }
            }
            if (!string.IsNullOrWhiteSpace(parameter.mobile))
            {
                if (!regex2.IsMatch(parameter.mobile))
                {
                    result = OpenApiErrorMessage.ShowErrorMsg((Enum)(object)OpenApiErrorCode.Parameters_Format_Error, "mobile");
                    return(false);
                }
                if (MemberProcessor.FindMemberByCellphone(parameter.mobile) != null)
                {
                    result = OpenApiErrorMessage.ShowErrorMsg((Enum)(object)OpenApiErrorCode.Parameters_Format_Error, "mobile");
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        private string _addUser(UserParam data)
        {
            string result = default(string);

            if (this.CheckAddUserParameters(data, out result))
            {
                SiteSettings siteSettings = HiContext.Current.SiteSettings;
                string       text         = OpenApiSign.Sign(data.SignStr(siteSettings.CheckCode), "MD5", "utf-8");
                if (text.Equals(data.sign))
                {
                    result = this.lastAddUser(data);
                    return(result);
                }
                result = OpenApiErrorMessage.ShowErrorMsg((Enum)(object)OpenApiErrorCode.Invalid_Signature, "sign");
                return(result);
            }
            return(result);
        }
Exemplo n.º 4
0
        private string lastAddUser(UserParam parameter)
        {
            string     format     = "{{\"user_add_response\":{{\"user\":{{ \"uid\":\"{0}\",\"password\":\"{1}\",\"created\":\"{2}\" }} }} }}";
            MemberInfo memberInfo = new MemberInfo();

            memberInfo.GradeId   = MemberProcessor.GetDefaultMemberGrade();
            memberInfo.UserName  = parameter.user_name;
            memberInfo.RealName  = parameter.real_name;
            memberInfo.Email     = parameter.email;
            memberInfo.CellPhone = parameter.mobile;
            string text = Globals.RndStr(128, true);

            if (string.IsNullOrWhiteSpace(parameter.password))
            {
                parameter.password = Globals.RndStr(6, true);
            }
            string password = parameter.password;

            password = (memberInfo.Password = Users.EncodePassword(password, text));
            memberInfo.PasswordSalt = text;
            if (parameter.sex.IndexOf("男") >= 0)
            {
                memberInfo.Gender = Gender.Female;
            }
            else if (parameter.sex.IndexOf("女") >= 0)
            {
                memberInfo.Gender = Gender.Female;
            }
            else
            {
                memberInfo.Gender = Gender.NotSet;
            }
            memberInfo.BirthDate  = parameter.birthday;
            memberInfo.RegionId   = RegionHelper.GetRegionId(parameter.town, parameter.district, parameter.city, parameter.state);
            memberInfo.Address    = parameter.address;
            memberInfo.CreateDate = DateTime.Now;
            int num = MemberProcessor.CreateMember(memberInfo);

            if (num > 0)
            {
                return(string.Format(format, num, parameter.password, memberInfo.CreateDate.ToString("yyyy-MM-dd HH:mm:ss")));
            }
            return(OpenApiErrorMessage.ShowErrorMsg((Enum)(object)OpenApiErrorCode.System_Error, "create user"));
        }
Exemplo n.º 5
0
        public HttpResponseMessage AddUser()
        {
            NameValueCollection nameValueCollection = base.Request.RequestUri.ParseQueryString();
            UserParam           userParam           = new UserParam();

            if (nameValueCollection.AllKeys.Contains("app_key"))
            {
                userParam.app_key = nameValueCollection["app_key"];
            }
            if (nameValueCollection.AllKeys.Contains("timestamp"))
            {
                userParam.timestamp = nameValueCollection["timestamp"];
            }
            if (nameValueCollection.AllKeys.Contains("sign"))
            {
                userParam.sign = nameValueCollection["sign"];
            }
            if (nameValueCollection.AllKeys.Contains("user_name"))
            {
                userParam.user_name = nameValueCollection["user_name"];
            }
            if (nameValueCollection.AllKeys.Contains("password"))
            {
                userParam.password = nameValueCollection["password"];
            }
            if (nameValueCollection.AllKeys.Contains("created") && !string.IsNullOrEmpty(nameValueCollection["created"]))
            {
                userParam.created = Convert.ToDateTime(nameValueCollection["created"]);
            }
            else
            {
                userParam.created = DateTime.Now;
            }
            if (nameValueCollection.AllKeys.Contains("real_name"))
            {
                userParam.real_name = nameValueCollection["real_name"];
            }
            if (nameValueCollection.AllKeys.Contains("mobile"))
            {
                userParam.mobile = nameValueCollection["mobile"];
            }
            if (nameValueCollection.AllKeys.Contains("email"))
            {
                userParam.email = nameValueCollection["email"];
            }
            if (nameValueCollection.AllKeys.Contains("sex"))
            {
                userParam.sex = nameValueCollection["sex"];
            }
            if (nameValueCollection.AllKeys.Contains("birthday") && !string.IsNullOrEmpty(nameValueCollection["birthday"]))
            {
                userParam.birthday = Convert.ToDateTime(nameValueCollection["birthday"]);
            }
            if (nameValueCollection.AllKeys.Contains("state"))
            {
                userParam.state = nameValueCollection["state"];
            }
            if (nameValueCollection.AllKeys.Contains("city"))
            {
                userParam.city = nameValueCollection["city"];
            }
            if (nameValueCollection.AllKeys.Contains("district"))
            {
                userParam.district = nameValueCollection["district"];
            }
            if (nameValueCollection.AllKeys.Contains("town"))
            {
                userParam.town = nameValueCollection["town"];
            }
            if (nameValueCollection.AllKeys.Contains("address"))
            {
                userParam.address = nameValueCollection["address"];
            }
            string content = this._addUser(userParam);

            return(new HttpResponseMessage
            {
                Content = new StringContent(content, Encoding.UTF8, "application/json")
            });
        }