Beispiel #1
0
        public async Task<IActionResult> RecuperarContrasena(EmailRequest viewModel)
        {
            ViewBag.Title = MessageCenter.commonTitlePageRecoverPwd;
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(viewModel.Email);
                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, MessageCenter.commonMessageRecoverNoEmail);
                    return View(viewModel);
                }

                var myToken   = await _userHelper.GeneratePasswordResetTokenAsync(user);
                var tokenLink = Url.Action("ResetPassword", "Account", new { token = myToken }, protocol: HttpContext.Request.Scheme);

                _mailHelper.SendEmailRecoverPwd(viewModel.Email, tokenLink);               

                ViewBag.Message = MessageCenter.commonMessageRecoverEmail;

                return View();

            }

            return View(viewModel);
        }
    public async Task<IActionResult> RecoverPassword([FromBody] EmailRequest request)
    {
	    if (!ModelState.IsValid)
	       { return BadRequest(new Resp<object> { IsSuccess = false, Message = "Bad request" }); }

	    var user = await _userHelper.GetUserByEmailAsync(request.Email);
	    if (user == null)
	       { return BadRequest(new Resp<object> { IsSuccess = false, Message = MessageCenter.commonMessageRecoverNoEmail }); }

	    var myToken   = await _userHelper.GeneratePasswordResetTokenAsync(user);
	    var tokenLink = Url.Action("ResetPassword", "Account", new { token = myToken }, protocol: HttpContext.Request.Scheme);
        _mailHelper.SendEmailRecoverPwd(request.Email, tokenLink);
            
	    return Ok(new Resp<object> { IsSuccess = true, Message = MessageCenter.commonMessageRecoverEmail });
    }