Skip to content

Commit

Permalink
fix: validate template
Browse files Browse the repository at this point in the history
  • Loading branch information
dorothyyzh committed Dec 25, 2024
1 parent b96aa43 commit e5dd06f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions email/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ func (b *Builder) createTemplate(w http.ResponseWriter, r *http.Request) {
http.Error(w, "invalid request body", http.StatusBadRequest)
return
}
// validate template format
if _, err := GetTemplate(et.Subject); err != nil {
http.Error(w, "invalid subject", http.StatusBadRequest)
return
}
if _, err := GetTemplate(et.HTMLBody); err != nil {
http.Error(w, "invalid html body", http.StatusBadRequest)
return
}
// save in db
if err := b.db.Create(&et).Error; err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit e5dd06f

Please sign in to comment.