Commit 8062667f

mo khan <mo@mokhan.ca>
2014-01-08 00:38:14
send welcome email when someone signs up. fixes #5
1 parent 21eedc8
Changed files (5)
app/mailers/user_mailer.rb
@@ -0,0 +1,9 @@
+class UserMailer < ActionMailer::Base
+  default from: "from@example.com"
+
+  def welcome_email(user)
+    @url = 'https://www.cakeside.com/login'
+    @user = user
+    mail(to: @user.email, subject: "Welcome to CakeSide")
+  end
+end
app/models/user.rb
@@ -8,6 +8,7 @@ class User < ActiveRecord::Base
 
   before_save :geocode, :reverse_geocode
   before_save :ensure_authentication_token
+  after_create :send_welcome_email
 
   validates :name,  :presence => true
   validates :website, :format => URI::regexp(%w(http https)), :allow_blank => true
@@ -50,6 +51,10 @@ class User < ActiveRecord::Base
    self.is_admin
   end
 
+  def send_welcome_email
+    UserMailer.delay.welcome_email(self)
+  end
+
   class << self
     def ordered
       User.order(:creations_count => :desc)
app/views/user_mailer/welcome_email.html.erb
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
+  </head>
+  <body>
+    <h1>Welcome to CakeSide.com, <%= @user.name %></h1>
+    <p>
+    You have successfully signed up to cakeside.com,
+    your username is: <%= @user.email %>.<br/>
+    </p>
+    <p>
+    To login to the site, just follow this link: <%= @url %>.
+    </p>
+    <p>Thanks for joining and have a great day!</p>
+  </body>
+</html>
+
app/views/user_mailer/welcome_email.text.erb
@@ -0,0 +1,9 @@
+Welcome to CakeSide.com, <%= @user.name %>
+
+You have successfully signed up to cakeside.com,
+your username is: <%= @user.email %>.<br/>
+
+To login to the site, just follow this link: <%= @url %>.
+
+Thanks for joining and have a great day!
+
spec/mailers/user_mailer_spec.rb
@@ -0,0 +1,4 @@
+require "spec_helper"
+
+describe UserMailer do
+end