Beispiel #1
0
        public ActionResult Register(RegisterModel register)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    Msg = WebCommonHelper.GetValidMsg(ModelState)
                }));
            }

            //防止在发送验证码之后 用户修改了手机号码
            if (register.PhoneNum != (string)TempData["phoneNum"])
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    Msg = "手机号与注册时的手机号码不一致!"
                }));
            }

            if (register.SmsCode != (int)TempData["smsCode"])
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    Msg = "短信验证码错误!"
                }));
            }

            var user = UserService.GetByPhoneNum(register.PhoneNum);

            if (user != null)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    Msg = "该手机号已经注册!"
                }));
            }

            UserService.AddNewUser(register.PhoneNum, register.Password, register.CityId);
            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }