From b3d8082480d5253fe75644554b74d946c01661cf Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 5 Apr 2018 17:12:56 -0700 Subject: [PATCH] now we can send emails. --- docker-compose.prod.yml | 2 +- project.clj | 4 ++-- src/clj/auto_ap/handler.clj | 22 +++++++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index a14a745d..569231da 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -24,4 +24,4 @@ services: database: restart: always volumes: - - /opt/integreat/var/lib/postgresql/data:/var/lib/postgresql/data \ No newline at end of file + - /opt/integreat/var/lib/postgresql/data:/var/lib/postgresql/data diff --git a/project.clj b/project.clj index 8911e51c..25bf9cf1 100644 --- a/project.clj +++ b/project.clj @@ -10,7 +10,6 @@ [kibu/pushy "0.3.8"] [bidi "2.1.2"] [ring/ring-defaults "0.2.1"] - [ring/ring-json "0.4.0"] [ring "1.4.0"] [yogthos/config "0.8"] [dk.ative/docjure "1.12.0"] @@ -25,7 +24,8 @@ [fogus/ring-edn "0.3.0"] [buddy/buddy-auth "2.1.0"] [buddy/buddy-sign "2.1.0"] - [clj-time "0.14.2"]] + [clj-time "0.14.2"] + [amazonica "0.3.121"]] :plugins [[lein-ring "0.9.7"] [lein-cljsbuild "1.1.5"]] :clean-targets ^{:protect false} ["resources/public/js/compiled" "target"] diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index 65058462..8f12826f 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -11,7 +11,6 @@ [ring.middleware.defaults :refer [wrap-defaults site-defaults]] [ring.middleware.params :refer [wrap-params]] [ring.middleware.reload :refer [wrap-reload]] - [ring.middleware.json :refer [wrap-json-response]] [ring.middleware.edn :refer [wrap-edn-params]] [clojure.java.jdbc :as j] [clj-fuzzy.metrics :as m] @@ -24,7 +23,9 @@ [buddy.sign.jwt :as jwt] [buddy.auth.backends.token :refer [jws-backend]] [buddy.auth.middleware :refer [wrap-authorization wrap-authentication]] - [auto-ap.db.companies :as companies])) + [auto-ap.db.companies :as companies] + [amazonica.core :refer [defcredential]] + [amazonica.aws.simpleemail :as ses])) (defn best-match [companies company-identifier] (->> companies (map (fn [company] @@ -38,6 +39,7 @@ (def google-client-secret "OC-WemHurPXYpuIw5cT-B90g") (def jwt-secret "auto ap invoices are awesome") +(defcredential "AKIAIRKDGLBX7J7VJZ6Q" "OtRw2t/xktJBDjP8Jnx1Yf6G+uzBfIkrQEc6nmgo" "us-east-1") (defroutes unauthenticated-routes (GET "/" [] @@ -102,6 +104,19 @@ :body (pr-str (invoices/get-pending (query-params "company"))) :headers {"Content-Type" "application/edn"}}) + (POST "/api/reminders/send" {:keys [query-params]} + (doseq [{:keys [name email invoice-reminder-schedule]} (companies/get-all)] + (when (= "Weekly" invoice-reminder-schedule) + (println "Sending email to" email) + (ses/send-email :destination {:to-addresses [email]} + :source "invoices@mail.integreat.aws.brycecovertoperations.com" + :message {:subject "Reminder to send invoices" + :body {:html (str "

Hello " name ",

This is a reminder to send this week's invoices to us. You can just reply to this email.

- Integreat.

") + :text (str "Hello " name ",\r\nThis is a reminder to send this week's invoices to us. You can just reply to this email.\r\n - Integreat.")}}))) + {:status 200 + :body "{}" + :headers {"Content-Type" "application/edn"}}) + (PUT "/api/companies/:id" {:keys [edn-params] {:keys [id]} :route-params :as r} {:status 200 :body (pr-str (companies/upsert id edn-params)) @@ -122,7 +137,8 @@ {:status 200 :body (pr-str (invoices/get-pending (query-params "company"))) :headers {"Content-Type" "application/edn"}}) - (wrap-json-response (GET "/api/export" {:keys [query-params]} + ;; Removing the export view for now... + #_(wrap-json-response (GET "/api/export" {:keys [query-params]} (println query-params) (doto (invoices/get-unpaid (query-params "company")) println)))