Added confirmation email + specs + User#mail_confirm_email + call User#mail_confirm_email in UsersController#update
This commit is contained in:
parent
602382e24e
commit
37ccbce153
10 changed files with 99 additions and 0 deletions
|
|
@ -56,6 +56,7 @@ class UsersController < ApplicationController
|
|||
elsif u[:email]
|
||||
@user.unconfirmed_email = u[:email]
|
||||
if @user.save
|
||||
@user.mail_confirm_email
|
||||
flash[:notice] = I18n.t 'users.update.unconfirmed_email_changed'
|
||||
else
|
||||
flash[:error] = I18n.t 'users.update.unconfirmed_email_not_changed'
|
||||
|
|
|
|||
|
|
@ -115,6 +115,18 @@ class Notifier < ActionMailer::Base
|
|||
end
|
||||
end
|
||||
|
||||
def confirm_email(receiver_id)
|
||||
@receiver = User.find_by_id(receiver_id)
|
||||
|
||||
attachments.inline['logo_caps.png'] = ATTACHMENT
|
||||
|
||||
I18n.with_locale(@receiver.language) do
|
||||
mail(:to => "\"#{@receiver.name}\" <#{@receiver.unconfirmed_email}>",
|
||||
:subject => I18n.t('notifier.confirm_email.subject', :unconfirmed_email => @receiver.unconfirmed_email),
|
||||
:host => AppConfig[:pod_uri].host)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def log_mail recipient_id, sender_id, type
|
||||
log_string = "event=mail mail_type=#{type} recipient_id=#{recipient_id} sender_id=#{sender_id}"
|
||||
|
|
|
|||
8
app/models/jobs/mail_confirm_email.rb
Normal file
8
app/models/jobs/mail_confirm_email.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
module Job
|
||||
class MailConfirmEmail < Base
|
||||
@queue = :mail
|
||||
def self.perform_delegate(user_id)
|
||||
Notifier.confirm_email(user_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -206,6 +206,12 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def mail_confirm_email
|
||||
return false if unconfirmed_email.blank?
|
||||
Resque.enqueue(Job::MailConfirmEmail, id)
|
||||
true
|
||||
end
|
||||
|
||||
######### Posts and Such ###############
|
||||
def retract(post)
|
||||
if post.respond_to?(:relayable?) && post.relayable?
|
||||
|
|
|
|||
12
app/views/notifier/confirm_email.html.haml
Normal file
12
app/views/notifier/confirm_email.html.haml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
%p
|
||||
= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||
%p
|
||||
!= t('notifier.confirm_email.click_link', :unconfirmed_email => @receiver.unconfirmed_email)
|
||||
%br
|
||||
= link_to root_url, root_url
|
||||
|
||||
%br
|
||||
%br
|
||||
= t('notifier.love')
|
||||
%br
|
||||
= t('notifier.diaspora')
|
||||
7
app/views/notifier/confirm_email.text.haml
Normal file
7
app/views/notifier/confirm_email.text.haml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
!= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||
|
||||
!= t('notifier.confirm_email.click_link', :unconfirmed_email => @receiver.unconfirmed_email)
|
||||
!= root_url
|
||||
|
||||
!= "#{t('notifier.love')} \n"
|
||||
!= t('notifier.diaspora')
|
||||
|
|
@ -401,6 +401,9 @@ en:
|
|||
subject: "%{name} has just liked your post"
|
||||
liked: "%{name} has just liked your post: "
|
||||
sign_in: "Sign in to view it"
|
||||
confirm_email:
|
||||
subject: "Please activate your new e-mail address %{unconfirmed_email}"
|
||||
click_link: "To activate your new e-mail address %{unconfirmed_email}, please click this link:"
|
||||
|
||||
people:
|
||||
zero: "no people"
|
||||
|
|
|
|||
|
|
@ -109,6 +109,10 @@ describe UsersController do
|
|||
end
|
||||
|
||||
describe 'email' do
|
||||
before do
|
||||
Resque.stub!(:enqueue)
|
||||
end
|
||||
|
||||
it 'allow the user to change his (unconfirmed) email' do
|
||||
put(:update, :id => @user.id, :user => { :email => "my@newemail.com"})
|
||||
@user.reload
|
||||
|
|
@ -132,6 +136,11 @@ describe UsersController do
|
|||
@user.reload
|
||||
@user.unconfirmed_email.should eql(nil)
|
||||
end
|
||||
|
||||
it 'sends out activation email on success' do
|
||||
Resque.should_receive(:enqueue).with(Job::MailConfirmEmail, @user.id).once
|
||||
put(:update, :id => @user.id, :user => { :email => "my@newemail.com"})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'email settings' do
|
||||
|
|
|
|||
|
|
@ -207,5 +207,33 @@ describe Notifier do
|
|||
|
||||
end
|
||||
|
||||
describe ".confirm_email" do
|
||||
before do
|
||||
user.update_attribute(:unconfirmed_email, "my@newemail.com")
|
||||
end
|
||||
|
||||
let!(:confirm_email) { Notifier.confirm_email(user.id) }
|
||||
|
||||
it 'goes to the right person' do
|
||||
confirm_email.to.should == [user.unconfirmed_email]
|
||||
end
|
||||
|
||||
it 'has the unconfirmed emil in the subject' do
|
||||
confirm_email.subject.should include(user.unconfirmed_email)
|
||||
end
|
||||
|
||||
it 'has the unconfirmed emil in the body' do
|
||||
confirm_email.body.encoded.should include(user.unconfirmed_email)
|
||||
end
|
||||
|
||||
it 'has the receivers name in the body' do
|
||||
confirm_email.body.encoded.should include(user.person.profile.first_name)
|
||||
end
|
||||
|
||||
it 'has the activation link in the body' do
|
||||
pending
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -673,5 +673,18 @@ describe User do
|
|||
user.confirm_email_token.size.should eql(30)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mail_confirm_email' do
|
||||
it 'enqueues a mail job on user with unconfirmed email' do
|
||||
user.update_attribute(:unconfirmed_email, "alice@newmail.com")
|
||||
Resque.should_receive(:enqueue).with(Job::MailConfirmEmail, alice.id).once
|
||||
alice.mail_confirm_email.should eql(true)
|
||||
end
|
||||
|
||||
it 'enqueues NO mail job on user without unconfirmed email' do
|
||||
Resque.should_not_receive(:enqueue).with(Job::MailConfirmEmail, alice.id)
|
||||
alice.mail_confirm_email.should eql(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue