diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/subscriptions_controller.rb | 20 | ||||
| -rw-r--r-- | app/controllers/users_controller.rb | 14 | ||||
| -rw-r--r-- | app/mailers/.gitkeep | 0 | ||||
| -rw-r--r-- | app/mailers/user_mailer.rb | 11 | ||||
| -rw-r--r-- | app/models/user.rb | 4 | ||||
| -rw-r--r-- | app/views/devise/invitations/edit.html.erb | 14 | ||||
| -rw-r--r-- | app/views/devise/invitations/new.html.erb | 12 | ||||
| -rw-r--r-- | app/views/devise/mailer/invitation_instructions.html.erb | 8 |
8 files changed, 47 insertions, 36 deletions
diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index e860e94ec..a1dca5a5d 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -1,18 +1,12 @@ -class SubscriptionsController < Devise::RegistrationsController +class SubscriptionsController < InheritedResources::Base + skip_filter :authenticate_user! - def new - @subscription = Subscription.new - end def create - @subscription = Subscription.new(params[:subscription]) - - if @subscription.save - sign_in @subscription.user - flash[:notice] = t('subscriptions.success') - redirect_to referentials_path - else - flash[:error] = t('subscriptions.failure') - render :action => "new" + create! do |success, failure| + success.html do + sign_in resource.user + redirect_to referentials_path + end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ee9cbcda1..3c9ad214d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,17 +1,9 @@ class UsersController < InheritedResources::Base def create - Rails.logger.info( "call user_controller.create") - Rails.logger.info( "resource=#{build_resource.inspect}") - Rails.logger.info( "resourc.valid?e=#{build_resource.valid?}") - Rails.logger.info( "resourc.errors=#{build_resource.errors.inspect}") - create! do |success, failure| - success.html { - Rails.logger.info( "success user_controller") - mail = UserMailer.welcome(@user) - mail.deliver - redirect_to organisation_user_path(@user) } - end + @user = current_organisation.users.create(params[:user]) + @user.invite! + respond_with @user, :location => organisation_user_path(@user) end def update diff --git a/app/mailers/.gitkeep b/app/mailers/.gitkeep deleted file mode 100644 index e69de29bb..000000000 --- a/app/mailers/.gitkeep +++ /dev/null diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb deleted file mode 100644 index 4c831dae4..000000000 --- a/app/mailers/user_mailer.rb +++ /dev/null @@ -1,11 +0,0 @@ -class UserMailer < ActionMailer::Base - default :from => 'sim@dryade.net' - - def welcome(user) - @user = user - mail(:subject => "Welcome to #{user.organisation.name}", - :to => user.email) - end - -end - diff --git a/app/models/user.rb b/app/models/user.rb index 4d6f72c0e..cc880759e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,9 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable + :recoverable, :rememberable, :trackable, :validatable, + :invitable + # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :name diff --git a/app/views/devise/invitations/edit.html.erb b/app/views/devise/invitations/edit.html.erb new file mode 100644 index 000000000..becfb8efc --- /dev/null +++ b/app/views/devise/invitations/edit.html.erb @@ -0,0 +1,14 @@ +<h2><%= t 'devise.invitations.edit.header' %></h2> + +<%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => { :method => :put } do |f| %> + <%= devise_error_messages! %> + <%= f.hidden_field :invitation_token %> + + <p><%= f.label :password %><br /> + <%= f.password_field :password %></p> + + <p><%= f.label :password_confirmation %><br /> + <%= f.password_field :password_confirmation %></p> + + <p><%= f.submit t("devise.invitations.edit.submit_button") %></p> +<% end %> diff --git a/app/views/devise/invitations/new.html.erb b/app/views/devise/invitations/new.html.erb new file mode 100644 index 000000000..b5acf475a --- /dev/null +++ b/app/views/devise/invitations/new.html.erb @@ -0,0 +1,12 @@ +<h2><%= t "devise.invitations.new.header" %></h2> + +<%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :post} do |f| %> + <%= devise_error_messages! %> + +<% resource.class.invite_key_fields.each do |field| -%> + <p><%= f.label field %><br /> + <%= f.text_field field %></p> +<% end -%> + + <p><%= f.submit t("devise.invitations.new.submit_button") %></p> +<% end %> diff --git a/app/views/devise/mailer/invitation_instructions.html.erb b/app/views/devise/mailer/invitation_instructions.html.erb new file mode 100644 index 000000000..a3fa4e314 --- /dev/null +++ b/app/views/devise/mailer/invitation_instructions.html.erb @@ -0,0 +1,8 @@ +<p>Hello <%= @resource.email %>!</p> + +<p>Someone has invited you to <%= root_url %>, you can accept it through the link below.</p> + +<p><%= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) %></p> + +<p>If you don't want to accept the invitation, please ignore this email.<br /> +Your account won't be created until you access the link above and set your password.</p> |
