Better error messages for folks coming in with a bad invitation token, 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
This commit is contained in:
parent
ebad0f5ec3
commit
e38cb41f85
5 changed files with 30 additions and 10 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
class InvitationsController < Devise::InvitationsController
|
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]
|
before_filter :check_if_invites_open, :only =>[:create]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|
@ -73,8 +73,7 @@ class InvitationsController < Devise::InvitationsController
|
||||||
protected
|
protected
|
||||||
def check_token
|
def check_token
|
||||||
if User.find_by_invitation_token(params[:invitation_token]).nil?
|
if User.find_by_invitation_token(params[:invitation_token]).nil?
|
||||||
flash[:error] = I18n.t 'invitations.check_token.not_found'
|
render 'invitations/token_not_found'
|
||||||
redirect_to root_url
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<%- self.extend NotifierHelper -%>
|
<%- 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>
|
<head>
|
||||||
<title><%=invite_email_title %></title>
|
<title><%=invite_email_title %></title>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
3
app/views/invitations/token_not_found.html.haml
Normal file
3
app/views/invitations/token_not_found.html.haml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
.span-15.last
|
||||||
|
%h2
|
||||||
|
= t('devise.invitations.invitation_token_invalid')
|
||||||
|
|
@ -52,7 +52,7 @@ en:
|
||||||
resend_unlock: "Resend unlock instructions"
|
resend_unlock: "Resend unlock instructions"
|
||||||
invitations:
|
invitations:
|
||||||
send_instructions: 'Your invitation has been sent.'
|
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.'
|
updated: 'Your password was set successfully. You are now signed in.'
|
||||||
mailer:
|
mailer:
|
||||||
welcome: "Welcome %{email}!"
|
welcome: "Welcome %{email}!"
|
||||||
|
|
@ -73,8 +73,8 @@ en:
|
||||||
click_to_unlock: "Click the link below to unlock your account:"
|
click_to_unlock: "Click the link below to unlock your account:"
|
||||||
unlock: "Unlock my account"
|
unlock: "Unlock my account"
|
||||||
invitation_instructions:
|
invitation_instructions:
|
||||||
displaying_correctly: "Email not displaying correctly? %{link} in your browser"
|
displaying_correctly: "Email not displaying correctly? %{link}"
|
||||||
view_in: "View in"
|
view_in: "View it in your browser."
|
||||||
finally: "Finally - it's here"
|
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."
|
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 →"
|
sign_up_now: "Sign up now →"
|
||||||
|
|
|
||||||
|
|
@ -24,20 +24,20 @@ describe InvitationsController do
|
||||||
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
|
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'saves and invitation' do
|
it 'saves an invitation' do
|
||||||
expect {
|
expect {
|
||||||
post :create, :user => @invite
|
post :create, :user => @invite
|
||||||
}.should change(Invitation, :count).by(1)
|
}.should change(Invitation, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles a comma seperated list of emails' do
|
it 'handles a comma-separated list of emails' do
|
||||||
expect{
|
expect{
|
||||||
post :create, :user => @invite.merge(
|
post :create, :user => @invite.merge(
|
||||||
:email => "foofoofoofoo@example.com, mbs@gmail.com")
|
:email => "foofoofoofoo@example.com, mbs@gmail.com")
|
||||||
}.should change(Invitation, :count).by(2)
|
}.should change(Invitation, :count).by(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles a comma seperated list of emails with whitespace' do
|
it 'handles a comma-separated list of emails with whitespace' do
|
||||||
expect {
|
expect {
|
||||||
post :create, :user => @invite.merge(
|
post :create, :user => @invite.merge(
|
||||||
:email => "foofoofoofoo@example.com , mbs@gmail.com")
|
:email => "foofoofoofoo@example.com , mbs@gmail.com")
|
||||||
|
|
@ -70,6 +70,24 @@ describe InvitationsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#email" do
|
||||||
|
before do
|
||||||
|
invites = Invitation.batch_invite(["foo@example.com"], :message => "hi", :sender => @user, :aspect => @user.aspects.first, :service => 'email', :language => "en-US")
|
||||||
|
invites.first.send!
|
||||||
|
@invited_user = User.find_by_email("foo@example.com")
|
||||||
|
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
|
describe "#update" do
|
||||||
before do
|
before do
|
||||||
invite = Factory(:invitation, :sender => @user, :service => 'email', :identifier => "a@a.com")
|
invite = Factory(:invitation, :sender => @user, :service => 'email', :identifier => "a@a.com")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue