public async Task <JsonResult> ConfirmYourEmail(string UserId) { try { if (UserId == null) { return(Json(false, JsonRequestBehavior.AllowGet)); } string code = await UserManager.GenerateEmailConfirmationTokenAsync(UserId); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = UserId, code }, protocol: Request.Url.Scheme); var userDetail = UserManager.FindById(UserId); //Fetching Path of email teamplate folder in Shared . string FilePath = Shared.FilePath.GetEmailTemplatesFolderPath; // Read the file as one string. StreamReader str = new StreamReader(FilePath); string MailText = str.ReadToEnd(); str.Close(); //Repalce variables MailText = MailText.Replace("[UserName]", userDetail.FirstName); MailText = MailText.Replace("[CallBackUrl]", callbackUrl); MailText = MailText.Replace("[CompanyName]", CommonBAL.CompanyName()); await UserManager.SendEmailAsync(UserId, CommonBAL.CompanyName() + ": Confirm your account", MailText); return(Json(true, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(false, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist or is not confirmed ViewBag.Header = "User does not exist!"; ViewBag.Error = "It seems that this Email is not registered with us. Please contact to the administrator."; ViewBag.Class = "alert alert-warning"; return(View("ForgotPasswordConfirmation")); } else if (!(await UserManager.IsEmailConfirmedAsync(user.Id))) { ViewBag.Header = "Email does not confirmed!"; ViewBag.Error = "It seems that your Email does not confirmed please confirm your Email first or contact to the administrator."; ViewBag.Class = "alert alert-warning"; return(View("ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code }, protocol: Request.Url.Scheme); StringBuilder st = new StringBuilder(); st.Append("<!DOCTYPE html><html><head><meta charset='utf - 8'/><title>Reset Password</title></head><body><div style='width: 650px; min - height:420px; margin: 0 auto; padding - top:1px; background - color:#1d8e07'><div style='height:auto;margin-left:8px;width:642px;min-height:420px;background-color:#fff'><div style='min-height:250px;padding:30px 35px 30px;margin:0;line-height:1.5em;word-wrap:break-word'><br /><div>Hi " + user.FirstName + ", <br></div><div><br></div><div>We heard that you lost your password. Sorry about that!<br/>But don’t worry! You can use the following link to reset your password:<br></div><div><br></div>"); st.Append("<div><a style='border: 1px solid #1d8e07;background:#1d8e07;display:inline-block;padding:7px 15px;text-decoration:none;color:#fff' href=\"" + callbackUrl + "\" target='_blank'>Click here to reset</a> <br></div>"); st.Append("<div><br></div><br /><br /><br /><div>Thanks!<br></div><div><br></div><div>BASE Institution Team,<br></div></div></div></div></body></html>"); await UserManager.SendEmailAsync(user.Id, CommonBAL.CompanyName() + ": Reset Password", st.ToString()); ViewBag.Header = "Email sent succesfully!"; ViewBag.Error = "Please check your email to reset your password."; ViewBag.Class = "alert alert-success"; return(View("ForgotPasswordConfirmation")); } // If we got this far, something failed, redisplay form return(View(model)); }