2016-11-20 20:04:52 +01:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
2020-05-26 12:28:35 +02:00
|
|
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
|
|
;; defined by the Mozilla Public License, v. 2.0.
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2020 UXBOX Labs SL
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2020-08-18 19:26:37 +02:00
|
|
|
(ns app.emails
|
2016-11-20 20:04:52 +01:00
|
|
|
"Main api for send emails."
|
2019-11-18 11:52:57 +01:00
|
|
|
(:require
|
2020-08-18 19:26:37 +02:00
|
|
|
[app.common.spec :as us]
|
2020-12-02 12:36:08 +01:00
|
|
|
[app.config :as cfg]
|
2020-08-18 19:26:37 +02:00
|
|
|
[app.tasks :as tasks]
|
2020-12-02 12:36:08 +01:00
|
|
|
[app.util.emails :as emails]
|
|
|
|
[clojure.spec.alpha :as s]))
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2019-11-26 14:17:10 +01:00
|
|
|
;; --- Defaults
|
|
|
|
|
2020-05-26 13:56:32 +02:00
|
|
|
(defn default-context
|
|
|
|
[]
|
2020-06-01 13:19:35 +02:00
|
|
|
{:assets-uri (:assets-uri cfg/config)
|
2020-05-26 13:56:32 +02:00
|
|
|
:public-uri (:public-uri cfg/config)})
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2019-11-26 14:17:10 +01:00
|
|
|
;; --- Public API
|
|
|
|
|
2019-11-22 18:08:27 +01:00
|
|
|
(defn render
|
2020-11-10 18:24:02 +01:00
|
|
|
[email-factory context]
|
|
|
|
(email-factory context))
|
2019-11-18 11:52:57 +01:00
|
|
|
|
|
|
|
(defn send!
|
|
|
|
"Schedule the email for sending."
|
2020-11-10 18:24:02 +01:00
|
|
|
[conn email-factory context]
|
|
|
|
(us/verify fn? email-factory)
|
|
|
|
(us/verify map? context)
|
|
|
|
(let [email (email-factory context)]
|
|
|
|
(tasks/submit! conn {:name "sendmail"
|
|
|
|
:delay 0
|
|
|
|
:max-retries 1
|
|
|
|
:priority 200
|
|
|
|
:props email})))
|
2020-01-13 23:52:31 +01:00
|
|
|
|
|
|
|
;; --- Emails
|
|
|
|
|
|
|
|
(s/def ::name ::us/string)
|
|
|
|
(s/def ::register
|
|
|
|
(s/keys :req-un [::name]))
|
|
|
|
|
|
|
|
(def register
|
|
|
|
"A new profile registration welcome email."
|
2020-11-10 18:24:02 +01:00
|
|
|
(emails/template-factory ::register default-context))
|
2020-01-13 23:52:31 +01:00
|
|
|
|
|
|
|
(s/def ::token ::us/string)
|
|
|
|
(s/def ::password-recovery
|
|
|
|
(s/keys :req-un [::name ::token]))
|
|
|
|
|
|
|
|
(def password-recovery
|
|
|
|
"A password recovery notification email."
|
2020-11-10 18:24:02 +01:00
|
|
|
(emails/template-factory ::password-recovery default-context))
|
2020-05-22 13:48:21 +02:00
|
|
|
|
2020-05-26 12:28:35 +02:00
|
|
|
(s/def ::pending-email ::us/email)
|
2020-05-22 13:48:21 +02:00
|
|
|
(s/def ::change-email
|
|
|
|
(s/keys :req-un [::name ::pending-email ::token]))
|
|
|
|
|
|
|
|
(def change-email
|
|
|
|
"Password change confirmation email"
|
2020-11-10 18:24:02 +01:00
|
|
|
(emails/template-factory ::change-email default-context))
|
2020-10-05 18:12:40 +02:00
|
|
|
|
|
|
|
(s/def :internal.emails.invite-to-team/invited-by ::us/string)
|
|
|
|
(s/def :internal.emails.invite-to-team/team ::us/string)
|
|
|
|
(s/def :internal.emails.invite-to-team/token ::us/string)
|
|
|
|
|
|
|
|
(s/def ::invite-to-team
|
|
|
|
(s/keys :keys [:internal.emails.invite-to-team/invited-by
|
|
|
|
:internal.emails.invite-to-team/token
|
|
|
|
:internal.emails.invite-to-team/team]))
|
|
|
|
|
|
|
|
(def invite-to-team
|
|
|
|
"Teams member invitation email."
|
2020-11-10 18:24:02 +01:00
|
|
|
(emails/template-factory ::invite-to-team default-context))
|