4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/revise/controllers/invitations.rb', line 4
def self.extended(klass)
klass.controllers :invitations do
before(:new, :create) do
halt 403, 'Login first' unless current_account
end
before(:create) do
halt 403, "You've no invitations left" unless current_account.has_invitations_left? || current_account.role?(:admin)
end
get :new, :map => '/invitations/new', :priority => :low do
@account = Account.new
render 'invitations/new'
end
post :create, :map => '/invitations', :priority => :low do
@account = Account.invite!(params[:account], current_account)
if @account.errors.empty?
flash[:notice] = "You've invited #{params[:account][:email]}"
redirect url(:main, :index)
else
status 400
render 'invitations/new'
end
end
get :edit, :map => '/invitations/:invitation_token', :priority => :low do
if params[:invitation_token] && @account = Account.to_adapter.find_first(:invitation_token => params[:invitation_token])
render 'invitations/edit'
else
status 404
flash.now[:alert] = "Invitation Token Invalid"
render 'invitations/404'
end
end
put :update, :map => '/invitations/:invitation_token', :priority => :low do
@account = Account.accept_invitation!(params[:account])
if @account.errors.empty?
flash[:notice] = "Accepted Invitation. Now login"
respond(@account, url(:sessions, :new))
else
render 'invitations/edit'
end
end
end
end
|