Skip to content

Commit

Permalink
Better error messages for folks coming in with a bad invitation token…
Browse files Browse the repository at this point in the history
…, whether by clicking the "view this invitation in your browser" link or by clicking the accept invitation button.

Get rid of 500 error on the "view this invitation in your browser" link
  • Loading branch information
Sarah Mei & Tim Frazer committed Nov 15, 2011
1 parent ebad0f5 commit e38cb41
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
5 changes: 2 additions & 3 deletions app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class InvitationsController < Devise::InvitationsController

before_filter :check_token, :only => [:edit]
before_filter :check_token, :only => [:edit, :email]
before_filter :check_if_invites_open, :only =>[:create]

def new
Expand Down Expand Up @@ -73,8 +73,7 @@ def email
protected
def check_token
if User.find_by_invitation_token(params[:invitation_token]).nil?
flash[:error] = I18n.t 'invitations.check_token.not_found'
redirect_to root_url
render 'invitations/token_not_found'
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/mailer/invitation_instructions.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%- self.extend NotifierHelper -%>
<% @invites = @resource.invitations_to_me.includes(:sender =>{:person => :profile}).where(:admin => false).all%>
<% @invites = @resource.invitations_to_me.includes(:sender =>{:person => :profile}).where(:admin => false).all %>
<head>
<title><%=invite_email_title %></title>
</head>
Expand Down
3 changes: 3 additions & 0 deletions app/views/invitations/token_not_found.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.span-15.last
%h2
= t('devise.invitations.invitation_token_invalid')
6 changes: 3 additions & 3 deletions config/locales/devise/devise.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ en:
resend_unlock: "Resend unlock instructions"
invitations:
send_instructions: 'Your invitation has been sent.'
invitation_token_invalid: 'The invitation token provided is not valid!'
invitation_token_invalid: 'Our apologies! That invitation token is not valid.'
updated: 'Your password was set successfully. You are now signed in.'
mailer:
welcome: "Welcome %{email}!"
Expand All @@ -73,8 +73,8 @@ en:
click_to_unlock: "Click the link below to unlock your account:"
unlock: "Unlock my account"
invitation_instructions:
displaying_correctly: "Email not displaying correctly? %{link} in your browser"
view_in: "View in"
displaying_correctly: "Email not displaying correctly? %{link}"
view_in: "View it in your browser."
finally: "Finally - it's here"
arrived: "The social network you have been waiting for has arrived. Revamped, more secure, and more fun, %{strong_diaspora} is ready to help you share and explore the web in a whole new way."
sign_up_now: "Sign up now &rarr;"
Expand Down
24 changes: 21 additions & 3 deletions spec/controllers/invitations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
end

it 'saves and invitation' do
it 'saves an invitation' do
expect {
post :create, :user => @invite
}.should change(Invitation, :count).by(1)
end

it 'handles a comma seperated list of emails' do
it 'handles a comma-separated list of emails' do
expect{
post :create, :user => @invite.merge(
:email => "[email protected], [email protected]")
}.should change(Invitation, :count).by(2)
end

it 'handles a comma seperated list of emails with whitespace' do
it 'handles a comma-separated list of emails with whitespace' do
expect {
post :create, :user => @invite.merge(
:email => "[email protected] , [email protected]")
Expand Down Expand Up @@ -70,6 +70,24 @@
end
end

describe "#email" do
before do
invites = Invitation.batch_invite(["[email protected]"], :message => "hi", :sender => @user, :aspect => @user.aspects.first, :service => 'email', :language => "en-US")
invites.first.send!
@invited_user = User.find_by_email("[email protected]")
end

it "succeeds" do
get :email, :invitation_token => @invited_user.invitation_token
response.should be_success
end

it "shows an error if there's no such invitation token" do
get :email, :invitation_token => 12345
response.should render_template(:token_not_found)
end
end

describe "#update" do
before do
invite = Factory(:invitation, :sender => @user, :service => 'email', :identifier => "[email protected]")
Expand Down

0 comments on commit e38cb41

Please sign in to comment.