activate emails

This commit is contained in:
Mark Moser 2015-10-08 21:10:33 -05:00
parent 9f7f29f327
commit b407d40747
12 changed files with 66 additions and 18 deletions

View File

@ -14,9 +14,6 @@ class OauthsController < ApplicationController
else else
begin begin
@user = create_from(provider) @user = create_from(provider)
# NOTE: this is the place to add '@user.activate!' if you
# are using user_activation submodule
reset_session # protect from session fixation attack reset_session # protect from session fixation attack
auto_login(@user) auto_login(@user)
redirect_to root_path, notice: "Logged in from #{provider.titleize}!" redirect_to root_path, notice: "Logged in from #{provider.titleize}!"

View File

@ -1,2 +0,0 @@
module OauthsHelper
end

View File

@ -1,6 +1,23 @@
class AccountMailer < ApplicationMailer class AccountMailer < ApplicationMailer
def activation_needed # Subject can be set in your I18n file at config/locales/en.yml
@blarg = "This was blarg" # with the following lookup:
mail(to: 'markamoser+test@gmail.com', subject: 'Activate me please!') #
# en.account_mailer.activation_needed_email.subject
#
def activation_needed_email(user)
@greeting = "Hi"
@user = user
mail to: Person.admins.map(&:email).join(', ')
end
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.account_mailer.activation_success_email.subject
#
def activation_success_email(user)
@greeting = "Hi"
@user = user
mail to: user.email
end end
end end

View File

@ -1,4 +0,0 @@
!!!
%h3 Activate me please
%p and then: #{@blarg}

View File

@ -0,0 +1,4 @@
%h1= "AccountMailer#" + @action.to_s
%p
= @greeting + ", find me in app/views/account_mailer/activation_needed_email.html.haml"

View File

@ -0,0 +1,3 @@
AccountMailer#activation_needed_email
= @greeting + ", find me in app/views/account_mailer/activation_needed_email.text.haml"

View File

@ -0,0 +1,4 @@
%h1= "AccountMailer#" + @action.to_s
%p
= @greeting + ", find me in app/views/account_mailer/activation_success_email.html.haml"

View File

@ -0,0 +1,3 @@
AccountMailer#activation_success_email
= @greeting + ", find me in app/views/account_mailer/activation_success_email.text.haml"

View File

@ -1,3 +1,4 @@
!!!
%hmtl %hmtl
%body %body
= yield = yield

View File

@ -282,7 +282,7 @@ Rails.application.config.sorcery.configure do |config|
# your mailer class. Required. # your mailer class. Required.
# Default: `nil` # Default: `nil`
# #
# user.user_activation_mailer = user.user_activation_mailer = AccountMailer
# when true sorcery will not automatically # when true sorcery will not automatically
@ -290,7 +290,7 @@ Rails.application.config.sorcery.configure do |config|
# manually handle how and when email is sent. # manually handle how and when email is sent.
# Default: `false` # Default: `false`
# #
user.activation_mailer_disabled = true # user.activation_mailer_disabled =
# activation needed email method on your mailer class. # activation needed email method on your mailer class.

View File

@ -1,7 +1,21 @@
require 'test_helper' require 'test_helper'
class AccountMailerTest < ActionMailer::TestCase class AccountMailerTest < ActionMailer::TestCase
# test "the truth" do test "activation_needed_email" do
# assert true user = Person.new
# end mail = AccountMailer.activation_needed_email user
assert_equal "Activation needed email", mail.subject
assert_match "Hi", mail.body.encoded
# assert_equal ["to@example.org"], mail.to
# assert_equal ["from@example.com"], mail.from
end
test "activation_success_email" do
user = Person.new
mail = AccountMailer.activation_success_email user
assert_equal "Activation success email", mail.subject
assert_match "Hi", mail.body.encoded
# assert_equal ["to@example.org"], mail.to
# assert_equal ["from@example.com"], mail.from
end
end end

View File

@ -1,3 +1,14 @@
# Preview all emails at http://localhost:3000/rails/mailers/account_mailer # Preview all emails at http://localhost:3000/rails/mailers/account_mailer
class AccountMailerPreview < ActionMailer::Preview class AccountMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/account_mailer/activation_needed_email
def activation_needed_email
user = Person.new
AccountMailer.activation_needed_email user
end
# Preview this email at http://localhost:3000/rails/mailers/account_mailer/activation_success_email
def activation_success_email
user = Person.new
AccountMailer.activation_success_email user
end
end end