This commit is contained in:
Andros Fenollosa 2020-06-11 17:38:47 +02:00
parent c8cb139aad
commit e8b410012a
5 changed files with 14 additions and 10 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
target/ target/
.lein-failures

View File

@ -1,7 +1,7 @@
domain: "http://localhost" domain: "http://localhost"
debug: true debug: true
port: 7404 port: 7404
from: "api2smtp <no-reply@www.tadam-framework.dev>" smtp-from: "api2smtp <no-reply@www.tadam-framework.dev>"
smtp-host: localhost smtp-host: localhost
smtp-user: smtp-user:
smtp-pass: smtp-pass:

View File

@ -6,7 +6,7 @@
:dependencies [;; Clojure :dependencies [;; Clojure
[org.clojure/clojure "1.10.1"] [org.clojure/clojure "1.10.1"]
;; Tadam core ;; Tadam core
[tadam-core "0.3.2"] [tadam-core "0.4.0"]
;; HTTP Server ;; HTTP Server
[ring "1.8.0"] [ring "1.8.0"]
;; Ring middleware that prevents CSRF attacks ;; Ring middleware that prevents CSRF attacks

View File

@ -6,7 +6,7 @@
(defroutes public (defroutes public
;; Urls public endpoints ;; Urls public endpoints
(POST "/api/v1/email/" [] view-public/send)) (POST "/api/v1/email/" [] view-public/send-email))
(defroutes resources-routes (defroutes resources-routes

View File

@ -3,17 +3,20 @@
(:require (:require
[tadam.templates :refer [render-template render-JSON]] [tadam.templates :refer [render-template render-JSON]]
[tadam.responses :refer [response]] [tadam.responses :refer [response]]
[tadam.email :refer [send]])) [tadam.utils :refer [get-JSON]]
[tadam.email :refer [send]]
[api2smtp.config :refer [config]]))
(defn send (defn send-email
;; View Send email ;; View Send email
[req] [req]
(let [params {:name (-> req :params :name) (let [json (get-JSON req)
:subject (-> req :params :subject) params {:name (-> json :name)
:email (-> req :params :email) :subject (-> json :subject)
:message (-> req :params :message)}] :email (-> json :email)
:message (-> json :message)}]
;; Send email ;; Send email
(send "to@email.com" "Contact" (render-template "emails/contact.html" params) (render-template "emails/contact.txt" params)) (send config "to@email.com" "Contact" (render-template "emails/contact.html" params) (render-template "emails/contact.txt" params))
;; Response OK ;; Response OK
(render-JSON req {:status "ok"}))) (render-JSON req {:status "ok"})))