public async Task <RepositoryResponse <string> > ForgotPassword([FromBody] Mix.Identity.Models.AccountViewModels.ForgotPasswordViewModel model) { var result = new RepositoryResponse <string>() { IsSucceed = true }; if (string.IsNullOrEmpty(model.Email)) { result.IsSucceed = false; result.Data = "Invalid Email"; result.Errors.Add("Invalid Email"); return(result); } var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { result.IsSucceed = false; result.Data = "Email Not Exist"; result.Errors.Add("Email Not Exist"); return(result); } //if (!await _userManager.IsEmailConfirmedAsync(user)) // result.Data = "Invalid Email"; var confrimationCode = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackurl = $"{Request.Scheme}://{Request.Host}/security/reset-password/?token={System.Web.HttpUtility.UrlEncode(confrimationCode)}"; var getEdmTemplate = await Lib.ViewModels.MixTemplates.ReadViewModel.Repository.GetSingleModelAsync( m => m.FolderType == MixTemplateFolders.Edms && m.FileName == "ForgotPassword"); string content = callbackurl; if (getEdmTemplate.IsSucceed) { content = getEdmTemplate.Data.Content.Replace("[URL]", callbackurl); } MixService.SendMail( to: user.Email, subject: "Reset Password", message: content); return(result); }
public async Task <RepositoryResponse <string> > ForgotPassword([FromBody] Mix.Identity.Models.AccountViewModels.ForgotPasswordViewModel model) { var result = new RepositoryResponse <string>() { IsSucceed = true }; if (string.IsNullOrEmpty(model.Email)) { result.IsSucceed = false; result.Data = "Invalid Email"; result.Errors.Add("Invalid Email"); return(result); } var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { result.IsSucceed = false; result.Data = "Email Not Exist"; result.Errors.Add("Email Not Exist"); return(result); } //if (!await _userManager.IsEmailConfirmedAsync(user)) // result.Data = "Invalid Email"; var confrimationCode = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackurl = $"{Request.Scheme}://{Request.Host}/security/reset-password/?token={System.Web.HttpUtility.UrlEncode(confrimationCode)}"; MixService.SendMail( to: user.Email, subject: "Reset Password", message: callbackurl); return(result); }