diff options
| -rw-r--r-- | Gemfile | 3 | ||||
| -rw-r--r-- | Gemfile.lock | 10 | ||||
| -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 | ||||
| -rw-r--r-- | config/initializers/devise.rb | 41 | ||||
| -rw-r--r-- | config/locales/devise.fr.yml | 5 | ||||
| -rw-r--r-- | config/routes.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20120823053740_create_organisation.rb | 24 | ||||
| -rw-r--r-- | db/migrate/20120824094751_add_name_to_user.rb | 7 | ||||
| -rw-r--r-- | db/migrate/20120830092409_add_encrypt_confirm_lock_token_to_user.rb | 23 | ||||
| -rw-r--r-- | db/migrate/20120830095442_add_invitable_to_user.rb | 18 | ||||
| -rw-r--r-- | spec/mailers/user_mailer_spec.rb | 21 |
18 files changed, 170 insertions, 70 deletions
@@ -2,6 +2,8 @@ source 'http://rubygems.org' gem 'rails', '3.2.6' gem 'devise' +gem 'devise_invitable' +#gem 'devise-encryptable' gem "ffi-proj4", :git => 'git://github.com/dryade/ffi-proj4.git' @@ -34,6 +36,7 @@ gem 'squeel' gem 'RedCloth' gem 'jquery-rails' gem "modernizr-rails", "~> 2.0.6" +gem 'gravatar_image_tag' gem "acts_as_tree", :git => "git://github.com/dryade/acts_as_tree.git" #gem 'ninoxe', :git => 'git://github.com/dryade/ninoxe.git' diff --git a/Gemfile.lock b/Gemfile.lock index 5e512e990..9b161c5d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,7 +61,7 @@ GIT GIT remote: git://sim.dryade.priv/user_interface - revision: 2d551a49dc3942851f5f94f8c0f86d2570f80dd2 + revision: 71a7cb5b5db38777d5a251a12d9cd7b6fe3cda95 specs: user_interface (0.0.1) rails (> 3.1.0) @@ -147,6 +147,10 @@ GEM orm_adapter (~> 0.1) railties (~> 3.1) warden (~> 1.2.1) + devise_invitable (1.1.0) + actionmailer (~> 3.0) + devise (>= 2.1.0) + railties (~> 3.0) diff-lcs (1.1.3) erubis (2.7.0) execjs (1.4.0) @@ -165,6 +169,7 @@ GEM geokit (1.6.5) multi_json georuby (1.9.7) + gravatar_image_tag (1.1.3) guard (1.2.3) listen (>= 0.4.2) thor (>= 0.14.6) @@ -188,6 +193,7 @@ GEM jruby-rack (1.1.7) jruby-rack-worker (0.4-java) jruby-rack (>= 1.1.1) + json (1.7.5) json (1.7.5-java) json_pure (1.7.3) launchy (2.1.0) @@ -345,10 +351,12 @@ DEPENDENCIES database_cleaner! delayed_job_active_record devise + devise_invitable factory_girl_rails (= 1.7) ffi-proj4! formtastic georuby-ext! + gravatar_image_tag guard guard-rspec inherited_resources 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> diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 6b256c3b4..d77e42f46 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -4,7 +4,7 @@ Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class with default "from" parameter. - config.mailer_sender = "chouette@dryade.net" + config.mailer_sender = "chouette@cityway.fr" # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" @@ -55,7 +55,7 @@ Devise.setup do |config| # It can be set to an array that will enable http authentication only for the # given strategies, for example, `config.http_authenticatable = [:token]` will # enable it only for token authentication. - config.http_authenticatable = true + # config.http_authenticatable = false # If http headers should be returned for AJAX requests. True by default. # config.http_authenticatable_on_xhr = true @@ -85,7 +85,27 @@ Devise.setup do |config| config.stretches = Rails.env.test? ? 1 : 10 # Setup a pepper to generate the encrypted password. - # config.pepper = "1926c0fc3d2c6dd214aad1676080f50dddb588b6f1ca480b9301035b00071a3d78edb76226373af8228c1f85d605d476675760c7e916a37fe8be8696a2922b51" + # config.pepper = "0420ef6a1b6b0ac63b9ac1e2b9624b411e331345a1bad99c85986f70aef62e9c7912955ea1616135224fc7c4ac319085a5e33831fb215a5e45043816746a2c2f" + + # ==> Configuration for :invitable + # The period the generated invitation token is valid, after + # this period, the invited resource won't be able to accept the invitation. + # When invite_for is 0 (the default), the invitation won't expire. + # config.invite_for = 2.weeks + + # Number of invitations users can send. + # If invitation_limit is nil, users can send unlimited invitations. + # If invitation_limit is 0, users can't send invitations. + # If invitation_limit n > 0, users can send n invitations. + # Default: nil + # config.invitation_limit = 5 + + # The key to be used to check existing users when sending an invitation + # config.invite_key = :email + + # Flag that force a record to be valid before being actually invited + # Default: false + # config.validate_on_invite = true # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without @@ -95,11 +115,11 @@ Devise.setup do |config| # the user cannot access the website without confirming his account. # config.allow_unconfirmed_access_for = 2.days - # If true, requires any email changes to be confirmed (exctly the same way as + # If true, requires any email changes to be confirmed (exactly the same way as # initial account confirmation) to be applied. Requires additional unconfirmed_email # db field (see migrations). Until confirmed new email is stored in # unconfirmed email column, and copied to email column on successful confirmation. - config.reconfirmable = true + config.reconfirmable = false # Defines which key will be used when confirming an account # config.confirmation_keys = [ :email ] @@ -111,13 +131,14 @@ Devise.setup do |config| # If true, extends the user's remember period when remembered via cookie. # config.extend_remember_period = false - # If true, uses the password salt as remember token. This should be turned - # to false if you are not using database authenticatable. + # This configures your application to use the salt as the remember token. + # Leave this set to true - this option was kept for backwards compatibility + # and will be removed in some future releases. config.use_salt_as_remember_token = true # Options to be passed to the created cookie. For instance, you can set # :secure => true in order to force SSL only cookies. - # config.cookie_options = {} + # config.rememberable_options = {} # ==> Configuration for :validatable # Range for password length. Default is 6..128. @@ -172,7 +193,7 @@ Devise.setup do |config| # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) # and :restful_authentication_sha1 (then you should set stretches to 10, and copy # REST_AUTH_SITE_KEY to pepper) - # config.encryptor = :sha512 + config.encryptor = :sha1 # ==> Configuration for :token_authenticatable # Defines name of the authentication token params key @@ -205,7 +226,7 @@ Devise.setup do |config| # config.navigational_formats = ["*/*", :html] # The default HTTP method used to sign out a resource. Default is :delete. - config.sign_out_via = :delete + config.sign_out_via = Rails.env.test? ? :get : :delete # ==> OmniAuth # Add a new OmniAuth provider. Check the wiki for more information on setting diff --git a/config/locales/devise.fr.yml b/config/locales/devise.fr.yml new file mode 100644 index 000000000..68e0dcb0f --- /dev/null +++ b/config/locales/devise.fr.yml @@ -0,0 +1,5 @@ +fr: + devise: + mailer: + invitation_instructions: + subject: "Invitation sur l'application Chouette" diff --git a/config/routes.rb b/config/routes.rb index e9f574d5d..53c5f89d3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,10 @@ ChouetteIhm::Application.routes.draw do devise_for :users do - get "/users/sign_up" => "subscriptions#new" - post "/subscription" => "subscriptions#create" + match "/users/sign_up" => redirect("/subscription/new") end + resource :subscription + resource :organisation do resources :users end diff --git a/db/migrate/20120823053740_create_organisation.rb b/db/migrate/20120823053740_create_organisation.rb new file mode 100644 index 000000000..d3778f057 --- /dev/null +++ b/db/migrate/20120823053740_create_organisation.rb @@ -0,0 +1,24 @@ +class CreateOrganisation < ActiveRecord::Migration + def up + create_table :organisations do |t| + t.string :name + t.timestamps + end + change_table :referentials do |n| + n.belongs_to :organisation + end + change_table :users do |u| + u.belongs_to :organisation + end + Referential.reset_column_information + User.reset_column_information + + organisation = Organisation.create! :name => "Chouette" + Referential.update_all :organisation_id => organisation.id + User.update_all :organisation_id => organisation.id + end + + def down + drop_table :organisations + end +end diff --git a/db/migrate/20120824094751_add_name_to_user.rb b/db/migrate/20120824094751_add_name_to_user.rb new file mode 100644 index 000000000..6822e4d6e --- /dev/null +++ b/db/migrate/20120824094751_add_name_to_user.rb @@ -0,0 +1,7 @@ +class AddNameToUser < ActiveRecord::Migration + def change + change_table :users do |t| + t.string :name + end + end +end diff --git a/db/migrate/20120830092409_add_encrypt_confirm_lock_token_to_user.rb b/db/migrate/20120830092409_add_encrypt_confirm_lock_token_to_user.rb new file mode 100644 index 000000000..23425959e --- /dev/null +++ b/db/migrate/20120830092409_add_encrypt_confirm_lock_token_to_user.rb @@ -0,0 +1,23 @@ +class AddEncryptConfirmLockTokenToUser < ActiveRecord::Migration + def change + change_table :users do |t| + ## Encryptable + # t.string :password_salt + + ## Confirmable + t.string :confirmation_token + t.datetime :confirmed_at + t.datetime :confirmation_sent_at + t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts + t.string :unlock_token # Only if unlock strategy is :email or :both + t.datetime :locked_at + + ## Token authenticatable + t.string :authentication_token + end + + end +end diff --git a/db/migrate/20120830095442_add_invitable_to_user.rb b/db/migrate/20120830095442_add_invitable_to_user.rb new file mode 100644 index 000000000..33720cb95 --- /dev/null +++ b/db/migrate/20120830095442_add_invitable_to_user.rb @@ -0,0 +1,18 @@ +class AddInvitableToUser < ActiveRecord::Migration + def change + change_table :users do |t| + t.string :invitation_token, :limit => 60 + t.datetime :invitation_sent_at + t.datetime :invitation_accepted_at + t.integer :invitation_limit + t.integer :invited_by_id + t.string :invited_by_type + + end + + # Allow null encrypted_password + change_column :users, :encrypted_password, :string, :null => true + # Allow null password_salt (add it if you are using Devise's encryptable module) + change_column :users, :password_salt, :string, :null => true + end +end diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb deleted file mode 100644 index 2471de988..000000000 --- a/spec/mailers/user_mailer_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "spec_helper" - -describe UserMailer do - - describe "welcome" do - let(:user) {Factory(:user)} - - it "should verify if email send" do - email = UserMailer.welcome(user).deliver - ActionMailer::Base.deliveries.empty?.should be_false - end - - it "should verify the content of sending email" do - email = UserMailer.welcome(user).deliver - email.to.should == [user.email] - email.subject.should == "Welcome to #{user.organisation.name}" - end - - end - -end |
