Exemplo n.º 1
0
        public async Task <IActionResult> RegisterRequestCode(string phone)
        {
            if (!CheckUtility.IsPhone(phone))
            {
                return(Json(new JsonResponse {
                    status = 0, msg = "手机号不正确"
                }));
            }
            if (await ExitedPhone(phone))
            {
                //试用一下Json相应模型
                return(Json(new JsonResponse {
                    status = 0, msg = "手机号已注册"
                }));
            }

            var response = await RequestCodeAsync(phone);

            if (response.IsSuccessful)
            {
                return(Json(new JsonResponse {
                    status = 1, msg = "验证码已发送"
                }));
            }
            else
            {
                return(Json(new JsonResponse {
                    status = 0, msg = "验证码发送失败"
                }));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> RegiserAsync(string phone, string userName, string password, string validate)
        {
            //后端验证
            if (!CheckUtility.IsUserName(userName))
            {
                return(Json(new { status = 0, msg = "昵称不合法" }));
            }

            if (!CheckUtility.IsPhone(phone))
            {
                return(Json(new { status = 0, msg = "手机号不合法" }));
            }

            //验证手机验证码
            var response = await VerifyCodeAsync(phone, validate);

            if (response.IsSuccessful)
            {
                HouseUser newUser = new HouseUser
                {
                    Id                   = phone,
                    UserName             = userName,
                    PhoneNumber          = phone,
                    PhoneNumberConfirmed = true
                };
                await _userManager.CreateAsync(newUser, password);

                await _signInManager.SignInAsync(newUser, false);

                return(Json(new { status = 1, msg = "注册成功", returnUrl = "/Home/Index" }));
            }
            return(Json(new { status = 0, msg = "验证手机失败" }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> LostFirstAsync(string phone, string Verification)
        {
            if (!CheckUtility.IsPhone(phone))
            {
                return(Json(new { status = 0, msg = "手机号不合法" }));
            }

            if (!CheckUtility.IsPhoneCode(Verification))
            {
                return(Json(new { status = 0, msg = "验证码不合法" }));
            }
            var user = await _userManager.FindByIdAsync(phone);

            //用户存在
            if (user != null)
            {
                var response = await VerifyCodeAsync(phone, Verification);

                if (response.IsSuccessful)
                {
                    //修改密码的方法有两个,一个是_userManager.ChangePassword,一个是_userManager.ResetPassword,这里采用第二个
                    //生成一个token用于修改密码
                    var token = await _userManager.GeneratePasswordResetTokenAsync(user);

                    //把token和手机号都存进session
                    HttpContext.Session.SetString("phone", phone);
                    HttpContext.Session.SetString("resetPasswordToken", token);

                    //return Redirect("/Account/Lost");
                    //return View("LostSecond");

                    return(Json(new { status = 1, returnUrl = "/Account/LostSecond" }));
                }
                else
                {
                    return(Json(new { status = 0, msg = "修改失败" }));
                }
            }
            else
            {
                return(Json(new { status = 0, msg = "用户不存在" }));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> LostRequestCode(string phone)
        {
            var exitedPhone = await ExitedPhone(phone);

            if (!CheckUtility.IsPhone(phone))
            {
                return(Json(new { status = 0, msg = "手机号不合法" }));
            }
            if (!exitedPhone)
            {
                return(Json(new { status = 0, msg = "用户不存在" }));
            }
            var response = await RequestCodeAsync(phone);

            if (response.IsSuccessful)
            {
                return(Json(new { status = 1, msg = "验证码发送成功" }));
            }
            else
            {
                return(Json(new { status = 0, msg = "发送失败" }));
            }
        }