Beispiel #1
0
        public ActionResult RegisterJson(string mobile, string name, string password, string compassword, string code)
        {
            var model = new MRegisterModel()
            {
                ConfirmPassword = compassword,
                Mobile          = mobile,
                Password        = password,
                UserName        = name
            };

            var codevalid = _phoneCodeSerice.Valid(code, mobile);

            if (!codevalid)
            {
                return(Json("验证码错误!"));
            }

            var m = CommonHelper.ValidateString(mobile, ValidataType.Mobile);

            if (!m)
            {
                return(Json("请输入正确的手机号码"));
            }

            var user = _service.InsertGuestUser();

            if (_service.GetUserByMobile(model.Mobile) != null)
            {
                return(Json("电话号码已注册过"));
            }

            if (ModelState.IsValid)
            {
                if (model.UserName != null)
                {
                    model.UserName = model.UserName.Trim();
                }

                var registerRequest    = new UserRegistrationRequest(user, "", model.Mobile, model.UserName, model.Password, PasswordFormat.Encrypted);
                var registrationResult = _accountService.RegisterUser(registerRequest, true);
                if (registrationResult.Success)
                {
                    AuthenticationService.SignIn(user, true);
                    Success("注册成功!初始密码为学号,请修改密码");
                    return(Json(1));
                }
                var str = "";
                foreach (var error in registrationResult.Errors)
                {
                    str += error + "\n";
                }

                return(Json(str));
            }
            return(Json("注册失败"));
        }
Beispiel #2
0
        public ActionResult BindMobile(string mobile, string code)
        {
            if (!CommonHelper.ValidateString(mobile, ValidataType.Mobile))
            {
                return(Json("请输入正确的手机号码", JsonRequestBehavior.AllowGet));
            }

            var codevalid = _phoneCodeSerice.Valid(code, mobile);

            if (!codevalid)
            {
                return(Json("验证码错误", JsonRequestBehavior.AllowGet));
            }

            var user = _userService.GetUserById(CurrentUser.Id);

            user.Mobile = mobile;

            _userService.UpdateUser(user);

            return(Json(true, JsonRequestBehavior.AllowGet));
        }