Пример #1
0
        public async Task <ActionResult> SendMobileValidateCode(string mobile)
        {
            //验证传入的是否是有效的手机号。

            Regex reg = new Regex(@"^[1]+[3,4,5,7,8]+\d{9}$");

            if (!reg.IsMatch(mobile))
            {
                return(Json(new { code = 401, msg = "无效的手机号码。" }, "text/plain"));
            }

            using (var client = new TalentGo.ValidationCodeSvc.VerificationCodeClient())
            {
                try
                {
                    var result = await client.SendAsync(mobile);

                    if (result.StatusCode == 0)
                    {
                        return(Json(true));
                    }
                    return(Json(new { code = result.StatusCode, msg = result.Message }, "text/plain"));
                }
                catch (Exception ex)
                {
                    return(Json(new { code = 500, msg = ex.Message }, "text/plain"));
                }
            }
        }
Пример #2
0
        public async Task <ActionResult> FindPasswordViaMobile(FindPasswordViaMobileViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //为了隐藏,构造一个假的token
            string token = "EbzHFOl%2BLSZ%2B3NjS1tgZyL10hmrXA78SfDgKmU%2Fxl5sAXPsfyrsEflP3k%2FBFRL%2BUXNBNtI2XuEQLJi7GiFlMEuUtp%2FCuvgyysDuN6Us3EaVf1kyKNHdyJpx8VkwKc0BwuJ0b1pjfJKITt5UExXTidehh0%2BlyK2NuAFwouA0lVwQ%55";

            var user = await this.personManager.FindByMobileAsync(model.Mobile) as WebUser;

            if (user == null)
            {
                //不要提示用户找不到用户对象,以免被自动程序测试。
                return(RedirectToAction("ResetPasswordViaMobile", "Account", new { code = token }));
            }

            //创建真实的token
            token = this.UserManager.GeneratePasswordResetToken(user.Id);

            //如果手机号码没有被验证,则不发送短信
            if (!user.MobileValid)
            {
                //不要显示任何提示,以免自动程序猜测
                return(RedirectToAction("ResetPasswordViaMobile", "Account", new { code = token }));
            }

            //发送验证码
            //await this.phoneNumberValidationService.SendValidationCodeAsync(model.Mobile);
            using (var client = new TalentGo.ValidationCodeSvc.VerificationCodeClient())
            {
                try
                {
                    var result = await client.SendAsync(model.Mobile);
                }
                catch
                { }
            }
            return(RedirectToAction("ResetPasswordViaMobile", "Account", new { code = token }));
        }