aboutsummaryrefslogtreecommitdiff
path: root/src/emails
diff options
context:
space:
mode:
Diffstat (limited to 'src/emails')
-rw-r--r--src/emails/.keep0
-rw-r--r--src/emails/base_email.cr15
-rw-r--r--src/emails/password_reset_request_email.cr13
-rw-r--r--src/emails/templates/password_reset_request_email/html.ecr3
-rw-r--r--src/emails/templates/password_reset_request_email/text.ecr3
5 files changed, 34 insertions, 0 deletions
diff --git a/src/emails/.keep b/src/emails/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/emails/.keep
diff --git a/src/emails/base_email.cr b/src/emails/base_email.cr
new file mode 100644
index 0000000..656f4f1
--- /dev/null
+++ b/src/emails/base_email.cr
@@ -0,0 +1,15 @@
+# Learn about sending emails
+# https://luckyframework.org/guides/emails/sending-emails-with-carbon
+abstract class BaseEmail < Carbon::Email
+ # You can add defaults using the 'inherited' hook
+ #
+ # Example:
+ #
+ # macro inherited
+ # from default_from
+ # end
+ #
+ # def default_from
+ # Carbon::Address.new("support@app.com")
+ # end
+end
diff --git a/src/emails/password_reset_request_email.cr b/src/emails/password_reset_request_email.cr
new file mode 100644
index 0000000..a41c8ba
--- /dev/null
+++ b/src/emails/password_reset_request_email.cr
@@ -0,0 +1,13 @@
+class PasswordResetRequestEmail < BaseEmail
+ Habitat.create { setting stubbed_token : String? }
+ delegate stubbed_token, to: :settings
+
+ def initialize(@user : User)
+ @token = stubbed_token || Authentic.generate_password_reset_token(@user)
+ end
+
+ to @user
+ from "myapp@support.com" # or set a default in src/emails/base_email.cr
+ subject "Reset your password"
+ templates html, text
+end
diff --git a/src/emails/templates/password_reset_request_email/html.ecr b/src/emails/templates/password_reset_request_email/html.ecr
new file mode 100644
index 0000000..00c24fc
--- /dev/null
+++ b/src/emails/templates/password_reset_request_email/html.ecr
@@ -0,0 +1,3 @@
+<h1>Please reset your password</h1>
+
+<a href="<%= PasswordResets::New.url(@user.id, @token) %>">Reset password</a>
diff --git a/src/emails/templates/password_reset_request_email/text.ecr b/src/emails/templates/password_reset_request_email/text.ecr
new file mode 100644
index 0000000..7a7a0ab
--- /dev/null
+++ b/src/emails/templates/password_reset_request_email/text.ecr
@@ -0,0 +1,3 @@
+Please reset your password:
+
+<%= PasswordResets::New.url(@user.id, @token) %>