public async Task<ActionResult> Send() { Guid userId = new Guid("5c771db7-ee95-4bda-8bbe-f44eef49de79"); string userIdString = userId.ToString(); using (ApplicationUserManager userManager = Startup.UserManagerFactory()) { userManager.SetUserTokenProvider("ForgottenPassword"); string passwordResetToken = await userManager.GeneratePasswordResetTokenAsync(userIdString); //ApplicationUser user = await userManager.Users.FirstAsync(u => u.Id == userIdString); string baseUrl = ConfigurationManager.AppSettings["Site.BaseUrl"]; string resetPasswordPath = ConfigurationManager.AppSettings["Site.ResetPasswordPath"]; string resetPasswordUrl = string.Concat(baseUrl, resetPasswordPath.TrimStart('/'), "/", passwordResetToken); MailSendingFacade mailSender = new MailSendingFacade(); mailSender.SendForgottenPasswordMail(baseUrl, resetPasswordUrl, userIdString); } return this.Content("Done!"); }
public async Task<IHttpActionResult> SendResetPasswordMail(string email) { if (string.IsNullOrEmpty(email)) { return this.BadRequest("Email is required!"); } ApplicationUser user = await this.UserManager.FindByNameAsync(email); if (user == null) { return this.BadRequest("User with email: " + email + " is not found!"); } if (string.IsNullOrEmpty(user.PasswordHash)) { return this.BadRequest("The user with email: " + email + "does not have local login!"); } this.UserManager.SetUserTokenProvider("ForgottenPassword"); string passwordResetToken = await this.UserManager.GeneratePasswordResetTokenAsync(user.Id); string baseUrl = ConfigurationManager.AppSettings["Site.BaseUrl"]; string resetPasswordPath = ConfigurationManager.AppSettings["Site.ResetPasswordPath"]; string resetPasswordUrl = string.Concat(baseUrl, resetPasswordPath.TrimStart('/'), "/", HttpUtility.UrlEncode(email), "?token=", HttpUtility.UrlEncode(passwordResetToken)); MailSendingFacade mailSender = new MailSendingFacade(); mailSender.SendForgottenPasswordMail(baseUrl, resetPasswordUrl, email); return this.Ok(); }