public ActionResult <SuccessResponse> VerifyEmail(string email) { int code = 201; BaseResponse response = null; try { bool verifiedEmail = _service.VerifyEmail(email); if (verifiedEmail == true) { TokenAddRequest model = new TokenAddRequest(); model.Email = email; model.Token = Guid.NewGuid(); model.TokenType = 2; _service.InsertToken(model); _emailService.ForgotPassEmail(model); //send email response = new SuccessResponse(); } else { code = 404; response = new ErrorResponse("App Resource not found."); } } catch (Exception ex) { code = 500; response = new ErrorResponse(ex.Message); } return(StatusCode(code, response)); }
public void InsertToken(TokenAddRequest model) { string procName = "[dbo].[UserTokens_InsertByEmail]"; _dataProvider.ExecuteNonQuery(procName, delegate(SqlParameterCollection col) { col.AddWithValue("@UserToken", model.Token); col.AddWithValue("@Email", model.Email); col.AddWithValue("@TokenType", model.TokenType); } ); }
public async Task ForgotPassEmail(TokenAddRequest model) { string domain = _config.GetSection("Domain").Value; string htmlContentPath = _env.WebRootPath + "/EmailTemplates/ForgotPass.html"; string htmlContent = System.IO.File.ReadAllText(htmlContentPath).Replace("{&token}", model.Token.ToString()).Replace("{&domain}", domain); SendGridMessage message = new SendGridMessage() { From = new EmailAddress("*****@*****.**"), Subject = "Reset your Machitia password", HtmlContent = htmlContent, }; message.AddTo(model.Email); await Send(message); }