Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor email sending

  • Loading branch information...
commit f09161988ec000dfe03d127d1d759b18c3b79c2a 1 parent 331b91f
@leafo authored
View
7 applications/user.moon
@@ -114,11 +114,8 @@ class MoonRocksUser extends lapis.Application
reset_url = @build_url @url_for"user_forgot_password",
query: "token=#{token}&id=#{user.id}"
- user\send_email "Reset your password", ->
- h2 "Reset Your Password"
- p "Someone attempted to reset your password. If that person was you, click the link below to update your password. If it wasn't you then you don't have to do anything."
- p ->
- a href: reset_url, reset_url
+ UserPasswordResetEmail = require "emails.user_password_reset"
+ UserPasswordResetEmail\send @, user.email, { :user, :reset_url }
redirect_to: @url_for"user_forgot_password" .. "?sent=true"
}
View
1  emails/Tupfile
@@ -0,0 +1 @@
+include_rules
View
32 emails/base.moon
@@ -0,0 +1,32 @@
+
+import Widget from require "lapis.html"
+
+class Email extends Widget
+ @render: (r, params) =>
+ i = @(params)
+ i\include_helper r
+ i\subject!, i\render_to_string!, html: true
+
+ @send: (r, recipient, ...) =>
+ import send_email from require "helpers.email"
+ send_email recipient, @render r, ...
+
+ url_for: (...) =>
+ url_for = @_find_helper "url_for"
+ @build_url url_for nil, ...
+
+ subject: => "MoonRocks"
+
+ content: =>
+ div -> @body!
+ @hr!
+ @footer!
+
+ body: => error "fill me out"
+
+ footer: =>
+ h4 ->
+ a href: "http://rocks.moonscript.org", "MoonRocks"
+
+ hr: =>
+ hr style: "border: 0; height: 1px; background: #dadada"
View
13 emails/user_password_reset.moon
@@ -0,0 +1,13 @@
+
+class UserPasswordResetEmail extends require "emails.base"
+ subject: => "Reset your password"
+ content: =>
+ h2 "Reset your password"
+ p "Hello #{@user.username},"
+ p "Someone attempted to reset your password on MoonRocks. If that person
+ was you, click the link below to update your password. If it wasn't you
+ then you don't have to do anything."
+
+ p ->
+ a href: @reset_url, @reset_url
+
View
1  lint_config.moon
@@ -148,6 +148,7 @@ html_builer = {
["views/"]: html_builer
["widgets/"]: html_builer
+ ["emails/"]: html_builer
}
}
View
12 models/users.moon
@@ -75,18 +75,6 @@ class Users extends Model
@data = UserData\find(@id) or UserData\create(@id)
@data
- send_email: (subject, body) =>
- import render_html from require "lapis.html"
- import send_email from require "helpers.email"
-
- body_html = render_html ->
- div body
- hr!
- h4 ->
- a href: "http://rocks.moonscript.org", "MoonRocks"
-
- send_email @email, subject, body_html, html: true
-
gravatar: (size) =>
url = "http://www.gravatar.com/avatar/#{ngx.md5 @email}?d=identicon"
url = url .. "&s=#{size}" if size
View
2  views/user_forgot_password.moon
@@ -33,7 +33,7 @@ class UserForgotPassword extends require "widgets.base"
request_reset_form: =>
if @params.sent
- p -> b "A password reset link has been sent to you email address."
+ p -> b "A password reset link has been sent to your email address."
h2 "Reset Password"
@render_errors!
Please sign in to comment.
Something went wrong with that request. Please try again.