public IHttpActionResult SendResetEmail([FromBody] SendResetEmailRequest request) { try { PasswordManager pm = new PasswordManager(); int response = pm.SendResetEmail(request.email, request.url); if (response == -1) { return(Content((HttpStatusCode)503, "Email service unavailable")); } else if (response == 0) { return(Content(HttpStatusCode.Unauthorized, "No email was provided")); } else if (response == 1) { return(Content(HttpStatusCode.OK, "An email with further instructions has been sent")); } else { return(Content(HttpStatusCode.BadRequest, "Service Unavailable")); } } catch (Exception ex) { return(Content(HttpStatusCode.BadRequest, "Service Unavailable")); } }
public ActionResult SendResetEmail([FromBody] SendResetEmailRequest request) { var response = _forgotPasswordService.SendResetEmail(request); if (response == null) { return(BadRequest(new { message = "Unable to send reset password information" })); } return(Ok()); }
public async Task <bool> SendResetEmail(SendResetEmailRequest request) { var user = _context.Users .FirstOrDefault(u => u.Email == request.email); if (user == null) { return(false); } //Generate token var reset = new ForgotPassword(); reset.Email = user.Email; reset.Token = Guid.NewGuid().ToString("N"); reset.CreatedAt = DateTime.Now; reset.UpdatedAt = DateTime.Now; //Persist changes to db _context.ForgotPasswords.Add(reset); _context.SaveChanges(); //Send email var to = new List <string> { user.Email }; var client = new TransactionalEmailClient(_config); await client.SendEmail( to, "A request to reset your password was initiated", "If it was you who requested to reset your password, click the link below to reset your password. If you did not request this change, then you can ignore this email.", "/recover/" + reset.Token, "Click Here to Reset Your Password"); return(true); }