janus 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +77 -154
 - data/lib/generators/janus/install_generator.rb +19 -0
 - data/lib/generators/janus/resource_generator.rb +64 -0
 - data/lib/generators/templates/confirmations/new.html.erb +16 -0
 - data/lib/generators/templates/confirmations_controller.erb +3 -0
 - data/lib/generators/templates/janus.en.yml +62 -0
 - data/lib/generators/templates/janus.rb +25 -0
 - data/lib/generators/templates/model.erb +8 -0
 - data/lib/generators/templates/passwords/edit.html.erb +21 -0
 - data/lib/generators/templates/passwords/new.html.erb +16 -0
 - data/lib/generators/templates/passwords_controller.erb +3 -0
 - data/lib/generators/templates/registrations/edit.html.erb +31 -0
 - data/lib/generators/templates/registrations/new.html.erb +26 -0
 - data/lib/generators/templates/registrations_controller.erb +17 -0
 - data/lib/generators/templates/sessions/new.html.erb +30 -0
 - data/lib/generators/templates/sessions_controller.erb +11 -0
 - data/lib/janus.rb +1 -0
 - data/lib/janus/config.rb +10 -4
 - data/lib/janus/controllers/confirmations_controller.rb +6 -6
 - data/lib/janus/controllers/helpers.rb +4 -4
 - data/lib/janus/controllers/passwords_controller.rb +3 -3
 - data/lib/janus/controllers/registrations_controller.rb +12 -9
 - data/lib/janus/controllers/sessions_controller.rb +15 -7
 - data/lib/janus/helper.rb +1 -1
 - data/lib/janus/hooks.rb +6 -6
 - data/lib/janus/hooks/rememberable.rb +2 -2
 - data/lib/janus/hooks/remote_authenticatable.rb +1 -1
 - data/lib/janus/manager.rb +5 -5
 - data/lib/janus/models/base.rb +2 -2
 - data/lib/janus/models/confirmable.rb +7 -4
 - data/lib/janus/models/database_authenticatable.rb +26 -16
 - data/lib/janus/models/rememberable.rb +12 -9
 - data/lib/janus/models/remote_authenticatable.rb +21 -18
 - data/lib/janus/models/trackable.rb +11 -8
 - data/lib/janus/routes.rb +22 -22
 - data/lib/janus/strategies.rb +3 -3
 - data/lib/janus/strategies/database_authenticatable.rb +1 -1
 - data/lib/janus/strategies/rememberable.rb +1 -1
 - data/lib/janus/strategies/remote_authenticatable.rb +1 -1
 - data/lib/janus/test_helper.rb +6 -2
 - metadata +19 -36
 
| 
         @@ -0,0 +1,8 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class <%= class_name %> < ActiveRecord::Base
         
     | 
| 
      
 2 
     | 
    
         
            +
              include Janus::Models::Base
         
     | 
| 
      
 3 
     | 
    
         
            +
              include Janus::Models::DatabaseAuthenticatable
         
     | 
| 
      
 4 
     | 
    
         
            +
              include Janus::Models::Confirmable
         
     | 
| 
      
 5 
     | 
    
         
            +
              include Janus::Models::Rememberable
         
     | 
| 
      
 6 
     | 
    
         
            +
              # include Janus::Models::RemoteAuthenticatable
         
     | 
| 
      
 7 
     | 
    
         
            +
              # include Janus::Models::Trackable
         
     | 
| 
      
 8 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <h1><%%= t 'janus.passwords.edit.change_password' %></h1>
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            <%%= form_for @<%= singular_name %>, :url => <%= singular_name %>_password_path, :method => :put do |f| %>
         
     | 
| 
      
 4 
     | 
    
         
            +
              <%%= janus_error_messages %>
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              <%%= f.hidden_field :reset_password_token %>
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              <div class="field">
         
     | 
| 
      
 9 
     | 
    
         
            +
                <%%= f.label :password %>
         
     | 
| 
      
 10 
     | 
    
         
            +
                <%%= f.password_field :password %>
         
     | 
| 
      
 11 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              <div class="field">
         
     | 
| 
      
 14 
     | 
    
         
            +
                <%%= f.label :password_confirmation %>
         
     | 
| 
      
 15 
     | 
    
         
            +
                <%%= f.password_field :password_confirmation %>
         
     | 
| 
      
 16 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              <div class="actions">
         
     | 
| 
      
 19 
     | 
    
         
            +
                <%%= f.submit t('janus.passwords.edit.change_password_btn') %>
         
     | 
| 
      
 20 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 21 
     | 
    
         
            +
            <%% end %>
         
     | 
| 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <h1><%%= t 'janus.passwords.new.forgot_password' %></h1>
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            <%%= form_for @<%= singular_name %>, :url => <%= singular_name %>_password_path, :method => :post do |f| %>
         
     | 
| 
      
 4 
     | 
    
         
            +
              <%%= janus_error_messages %>
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              <%% <%= class_name %>.authentication_keys.each do |key| %>
         
     | 
| 
      
 7 
     | 
    
         
            +
                <div class="field">
         
     | 
| 
      
 8 
     | 
    
         
            +
                  <%%= f.label key %>
         
     | 
| 
      
 9 
     | 
    
         
            +
                  <%%= f.text_field key %>
         
     | 
| 
      
 10 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 11 
     | 
    
         
            +
              <%% end %>
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              <div class="actions">
         
     | 
| 
      
 14 
     | 
    
         
            +
                <%%= f.submit t('janus.passwords.new.send_instructions_btn') %>
         
     | 
| 
      
 15 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 16 
     | 
    
         
            +
            <%% end %>
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <h1><%%= t 'janus.registrations.edit.my_account' %></h1>
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            <%%= form_for @<%= singular_name %>, :url => <%= singular_name %>_registration_path, :method => :put do |f| %>
         
     | 
| 
      
 4 
     | 
    
         
            +
              <%%= janus_error_messages %>
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              <%% <%= class_name %>.authentication_keys.each do |key| %>
         
     | 
| 
      
 7 
     | 
    
         
            +
                <div class="field">
         
     | 
| 
      
 8 
     | 
    
         
            +
                  <%%= f.label key %>
         
     | 
| 
      
 9 
     | 
    
         
            +
                  <%%= f.text_field key %>
         
     | 
| 
      
 10 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 11 
     | 
    
         
            +
              <%% end %>
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              <div class="field">
         
     | 
| 
      
 14 
     | 
    
         
            +
                <%%= f.label :current_password %>
         
     | 
| 
      
 15 
     | 
    
         
            +
                <%%= f.password_field :current_password %>
         
     | 
| 
      
 16 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              <div class="field">
         
     | 
| 
      
 19 
     | 
    
         
            +
                <%%= f.label :password %>
         
     | 
| 
      
 20 
     | 
    
         
            +
                <%%= f.password_field :password %>
         
     | 
| 
      
 21 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              <div class="field">
         
     | 
| 
      
 24 
     | 
    
         
            +
                <%%= f.label :password_confirmation %>
         
     | 
| 
      
 25 
     | 
    
         
            +
                <%%= f.password_field :password_confirmation %>
         
     | 
| 
      
 26 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              <div class="actions">
         
     | 
| 
      
 29 
     | 
    
         
            +
                <%%= f.submit t('janus.registrations.edit.save_changes_btn') %>
         
     | 
| 
      
 30 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 31 
     | 
    
         
            +
            <%% end %>
         
     | 
| 
         @@ -0,0 +1,26 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <h1><%%= t 'janus.registrations.new.sign_up' %></h1>
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            <%%= form_for @<%= singular_name %>, :url => <%= singular_name %>_registration_path do |f| %>
         
     | 
| 
      
 4 
     | 
    
         
            +
              <%%= janus_error_messages %>
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              <%% <%= class_name %>.authentication_keys.each do |key| %>
         
     | 
| 
      
 7 
     | 
    
         
            +
                <div class="field">
         
     | 
| 
      
 8 
     | 
    
         
            +
                  <%%= f.label key %>
         
     | 
| 
      
 9 
     | 
    
         
            +
                  <%%= f.text_field key %>
         
     | 
| 
      
 10 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 11 
     | 
    
         
            +
              <%% end %>
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              <div class="field">
         
     | 
| 
      
 14 
     | 
    
         
            +
                <%%= f.label :password %>
         
     | 
| 
      
 15 
     | 
    
         
            +
                <%%= f.password_field :password %>
         
     | 
| 
      
 16 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              <div class="field">
         
     | 
| 
      
 19 
     | 
    
         
            +
                <%%= f.label :password_confirmation %>
         
     | 
| 
      
 20 
     | 
    
         
            +
                <%%= f.password_field :password_confirmation %>
         
     | 
| 
      
 21 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              <div class="actions">
         
     | 
| 
      
 24 
     | 
    
         
            +
                <%%= f.submit t('janus.registrations.new.sign_up_btn') %>
         
     | 
| 
      
 25 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 26 
     | 
    
         
            +
            <%% end %>
         
     | 
| 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class <%= class_name.pluralize %>::RegistrationsController < Janus::RegistrationsController
         
     | 
| 
      
 2 
     | 
    
         
            +
              respond_to :html
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              # def after_sign_up_url(<%= singular_name %>)
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   profile_url(<%= singular_name %>)
         
     | 
| 
      
 6 
     | 
    
         
            +
              # end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              def <%= singular_name %>_params
         
     | 
| 
      
 9 
     | 
    
         
            +
                if params.respond_to?(:permit)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  # Rails 4 (or Rails 3 + strong_parameters)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  params.require(:<%= singular_name %>).permit(:email, :current_password, :password, :password_confirmation)
         
     | 
| 
      
 12 
     | 
    
         
            +
                else
         
     | 
| 
      
 13 
     | 
    
         
            +
                  # Rails 3
         
     | 
| 
      
 14 
     | 
    
         
            +
                  params[:<%= singular_name %>].slice(:email, :current_password, :password, :password_confirmation)
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <h1><%%= t 'janus.sessions.new.sign_in' %></h1>
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            <%%= form_for @<%= singular_name %>, :url => <%= singular_name %>_session_path, :method => :post do |f| %>
         
     | 
| 
      
 4 
     | 
    
         
            +
              <%%= hidden_field_tag :return_to, params[:return_to] if params[:return_to] %>
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              <%%= janus_error_messages %>
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              <%% <%= class_name %>.authentication_keys.each do |key| %>
         
     | 
| 
      
 9 
     | 
    
         
            +
                <div class="field">
         
     | 
| 
      
 10 
     | 
    
         
            +
                  <%%= f.label key %>
         
     | 
| 
      
 11 
     | 
    
         
            +
                  <%%= f.text_field key %>
         
     | 
| 
      
 12 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 13 
     | 
    
         
            +
              <%% end %>
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              <div class="field">
         
     | 
| 
      
 16 
     | 
    
         
            +
                <%%= f.label :password %>
         
     | 
| 
      
 17 
     | 
    
         
            +
                <%%= f.password_field :password %>
         
     | 
| 
      
 18 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              <%% if @<%= singular_name %>.respond_to?(:remember_me!) %>
         
     | 
| 
      
 21 
     | 
    
         
            +
                <div class="field">
         
     | 
| 
      
 22 
     | 
    
         
            +
                  <%%= check_box_tag :remember_me, '1' %>
         
     | 
| 
      
 23 
     | 
    
         
            +
                  <%%= label_tag :remember_me, <%= class_name %>.human_attribute_name(:remember_me) %>
         
     | 
| 
      
 24 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 25 
     | 
    
         
            +
              <%% end %>
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              <div class="actions">
         
     | 
| 
      
 28 
     | 
    
         
            +
                <%%= f.submit t('janus.sessions.new.sign_in_btn') %>
         
     | 
| 
      
 29 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 30 
     | 
    
         
            +
            <%% end %>
         
     | 
| 
         @@ -0,0 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class <%= class_name.pluralize %>::SessionsController < Janus::SessionsController
         
     | 
| 
      
 2 
     | 
    
         
            +
              respond_to :html
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              # def after_sign_in_url(<%= singular_name %>)
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   profile_url(<%= singular_name %>)
         
     | 
| 
      
 6 
     | 
    
         
            +
              # end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              # def valid_remote_host?(host)
         
     | 
| 
      
 9 
     | 
    
         
            +
              #   ['www.example.com', 'test.host'].include?(host)
         
     | 
| 
      
 10 
     | 
    
         
            +
              # end
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/janus.rb
    CHANGED
    
    
    
        data/lib/janus/config.rb
    CHANGED
    
    | 
         @@ -3,26 +3,32 @@ require 'active_support/time' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            module Janus
         
     | 
| 
       4 
4 
     | 
    
         
             
              module Config
         
     | 
| 
       5 
5 
     | 
    
         
             
                mattr_accessor :contact_email
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       7 
7 
     | 
    
         
             
                # DatabaseAuthenticatable
         
     | 
| 
       8 
8 
     | 
    
         
             
                mattr_accessor :authentication_keys, :encryptor, :stretches, :pepper, :scrypt_options
         
     | 
| 
       9 
9 
     | 
    
         
             
                self.authentication_keys = [ :email ]
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       10 
11 
     | 
    
         
             
                self.encryptor = :bcrypt
         
     | 
| 
      
 12 
     | 
    
         
            +
            #    self.encryptor = :scrypt
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                # bcrypt config
         
     | 
| 
       11 
15 
     | 
    
         
             
                self.stretches = 10
         
     | 
| 
       12 
16 
     | 
    
         
             
                self.pepper = nil
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                # scrypt config
         
     | 
| 
       13 
19 
     | 
    
         
             
                self.scrypt_options = { :max_time => 0.25 }
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       15 
21 
     | 
    
         
             
                # Confirmable
         
     | 
| 
       16 
22 
     | 
    
         
             
                mattr_accessor :confirmation_key #,reconfirmable
         
     | 
| 
       17 
23 
     | 
    
         
             
                self.confirmation_key = :confirm_token
         
     | 
| 
       18 
24 
     | 
    
         
             
            #    self.reconfirmable = true
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       20 
26 
     | 
    
         
             
                # Rememberable
         
     | 
| 
       21 
27 
     | 
    
         
             
                mattr_accessor :remember_for, :extend_remember_period #, :remember_across_browsers
         
     | 
| 
       22 
28 
     | 
    
         
             
                self.remember_for = 1.year
         
     | 
| 
       23 
29 
     | 
    
         
             
                self.extend_remember_period = false
         
     | 
| 
       24 
30 
     | 
    
         
             
            #    self.remember_across_browsers = false
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       26 
32 
     | 
    
         
             
                # RemoteAuthenticatable
         
     | 
| 
       27 
33 
     | 
    
         
             
                mattr_accessor :remote_authentication_key
         
     | 
| 
       28 
34 
     | 
    
         
             
                self.remote_authentication_key = :remote_token
         
     | 
| 
         @@ -7,10 +7,10 @@ class Janus::ConfirmationsController < ApplicationController 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              def show
         
     | 
| 
       9 
9 
     | 
    
         
             
                self.resource = resource_class.find_for_confirmation(params[resource_class.confirmation_key])
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       11 
11 
     | 
    
         
             
                if resource
         
     | 
| 
       12 
12 
     | 
    
         
             
                  resource.confirm!
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       14 
14 
     | 
    
         
             
                  respond_to do |format|
         
     | 
| 
       15 
15 
     | 
    
         
             
                    format.html { redirect_to root_url, :notice => t('flash.janus.confirmations.edit.confirmed') }
         
     | 
| 
       16 
16 
     | 
    
         
             
                    format.any  { head :ok }
         
     | 
| 
         @@ -22,7 +22,7 @@ class Janus::ConfirmationsController < ApplicationController 
     | 
|
| 
       22 
22 
     | 
    
         
             
                      resource.errors.add(:base, :invalid_token)
         
     | 
| 
       23 
23 
     | 
    
         
             
                      render 'new'
         
     | 
| 
       24 
24 
     | 
    
         
             
                    end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       26 
26 
     | 
    
         
             
                    format.any { head :bad_request }
         
     | 
| 
       27 
27 
     | 
    
         
             
                  end
         
     | 
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
         @@ -35,10 +35,10 @@ class Janus::ConfirmationsController < ApplicationController 
     | 
|
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
              def create
         
     | 
| 
       37 
37 
     | 
    
         
             
                self.resource = resource_class.find_for_database_authentication(params[resource_name])
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
       39 
39 
     | 
    
         
             
                if resource
         
     | 
| 
       40 
40 
     | 
    
         
             
                  JanusMailer.confirmation_instructions(resource).deliver
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
       42 
42 
     | 
    
         
             
                  respond_to do |format|
         
     | 
| 
       43 
43 
     | 
    
         
             
                    format.html { redirect_to root_url, :notice => t('flash.janus.confirmations.create.email_sent') }
         
     | 
| 
       44 
44 
     | 
    
         
             
                    format.any  { head :ok }
         
     | 
| 
         @@ -50,7 +50,7 @@ class Janus::ConfirmationsController < ApplicationController 
     | 
|
| 
       50 
50 
     | 
    
         
             
                      resource.errors.add(:base, :not_found)
         
     | 
| 
       51 
51 
     | 
    
         
             
                      render 'new'
         
     | 
| 
       52 
52 
     | 
    
         
             
                    end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
       54 
54 
     | 
    
         
             
                    format.any { head :not_found }
         
     | 
| 
       55 
55 
     | 
    
         
             
                  end
         
     | 
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
         @@ -47,19 +47,19 @@ module Janus 
     | 
|
| 
       47 
47 
     | 
    
         
             
                    scopes.each do |scope|
         
     | 
| 
       48 
48 
     | 
    
         
             
                      class_eval <<-EOV
         
     | 
| 
       49 
49 
     | 
    
         
             
                        helper_method :#{scope}_signed_in?, :current_#{scope}, :#{scope}_session
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       51 
51 
     | 
    
         
             
                        def authenticate_#{scope}!
         
     | 
| 
       52 
52 
     | 
    
         
             
                          janus.authenticate!(:#{scope})
         
     | 
| 
       53 
53 
     | 
    
         
             
                        end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
       55 
55 
     | 
    
         
             
                        def current_#{scope}
         
     | 
| 
       56 
56 
     | 
    
         
             
                          @current_#{scope} ||= janus.authenticate(:#{scope})
         
     | 
| 
       57 
57 
     | 
    
         
             
                        end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
       59 
59 
     | 
    
         
             
                        def #{scope}_signed_in?
         
     | 
| 
       60 
60 
     | 
    
         
             
                          janus.authenticate?(:#{scope})
         
     | 
| 
       61 
61 
     | 
    
         
             
                        end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
       63 
63 
     | 
    
         
             
                        def #{scope}_session
         
     | 
| 
       64 
64 
     | 
    
         
             
                          janus.session(:#{scope}) if #{scope}_signed_in?
         
     | 
| 
       65 
65 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -12,11 +12,11 @@ class Janus::PasswordsController < ApplicationController 
     | 
|
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              def create
         
     | 
| 
       14 
14 
     | 
    
         
             
                self.resource = resource_class.find_for_database_authentication(params[resource_name])
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       16 
16 
     | 
    
         
             
                if resource
         
     | 
| 
       17 
17 
     | 
    
         
             
                  resource.generate_reset_password_token!
         
     | 
| 
       18 
18 
     | 
    
         
             
                  JanusMailer.reset_password_instructions(resource).deliver
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
       20 
20 
     | 
    
         
             
                  respond_to do |format|
         
     | 
| 
       21 
21 
     | 
    
         
             
                    format.html { redirect_to root_url, :notice => t('flash.janus.passwords.create.email_sent') }
         
     | 
| 
       22 
22 
     | 
    
         
             
                    format.any  { head :ok }
         
     | 
| 
         @@ -40,7 +40,7 @@ class Janus::PasswordsController < ApplicationController 
     | 
|
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
              def update
         
     | 
| 
       42 
42 
     | 
    
         
             
                self.resource = resource_class.find_for_password_reset(params[resource_name][:reset_password_token])
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
       44 
44 
     | 
    
         
             
                if resource
         
     | 
| 
       45 
45 
     | 
    
         
             
                  if resource.reset_password!(params[resource_name])
         
     | 
| 
       46 
46 
     | 
    
         
             
                    respond_to do |format|
         
     | 
| 
         @@ -17,33 +17,29 @@ class Janus::RegistrationsController < ApplicationController 
     | 
|
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
              def create
         
     | 
| 
       20 
     | 
    
         
            -
                self.resource = resource_class.new( 
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                self.resource = resource_class.new(send("#{janus_scope}_params"))
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
       22 
22 
     | 
    
         
             
                if resource.save
         
     | 
| 
       23 
23 
     | 
    
         
             
                  janus.login(resource, :scope => janus_scope, :rememberable => true)
         
     | 
| 
       24 
24 
     | 
    
         
             
                  JanusMailer.confirmation_instructions(resource).deliver if resource.respond_to?(:confirm!)
         
     | 
| 
       25 
25 
     | 
    
         
             
                else
         
     | 
| 
       26 
26 
     | 
    
         
             
                  resource.clean_up_passwords
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       29 
29 
     | 
    
         
             
                respond_with(resource, :location => after_sign_up_url(resource))
         
     | 
| 
       30 
30 
     | 
    
         
             
              end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
              def update
         
     | 
| 
       33 
     | 
    
         
            -
                params[resource_name].each do |key, value|
         
     | 
| 
       34 
     | 
    
         
            -
                  params[resource_name].delete(key) if value.blank? && [:password, :password_confirmation].include?(key.to_sym)
         
     | 
| 
       35 
     | 
    
         
            -
                end
         
     | 
| 
       36 
     | 
    
         
            -
                
         
     | 
| 
       37 
33 
     | 
    
         
             
                self.resource = send("current_#{janus_scope}")
         
     | 
| 
       38 
34 
     | 
    
         
             
                resource.current_password = ""
         
     | 
| 
       39 
     | 
    
         
            -
                resource.clean_up_passwords unless resource.update_attributes( 
     | 
| 
      
 35 
     | 
    
         
            +
                resource.clean_up_passwords unless resource.update_attributes(resource_params)
         
     | 
| 
       40 
36 
     | 
    
         
             
                respond_with(resource, :location => after_sign_up_url(resource))
         
     | 
| 
       41 
37 
     | 
    
         
             
              end
         
     | 
| 
       42 
38 
     | 
    
         | 
| 
       43 
39 
     | 
    
         
             
              def destroy
         
     | 
| 
       44 
40 
     | 
    
         
             
                self.resource = send("current_#{janus_scope}")
         
     | 
| 
       45 
41 
     | 
    
         
             
                janus.unset_user(janus_scope) if resource.destroy
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
       47 
43 
     | 
    
         
             
                respond_with(resource) do |format|
         
     | 
| 
       48 
44 
     | 
    
         
             
                  format.html { redirect_to root_url }
         
     | 
| 
       49 
45 
     | 
    
         
             
                end
         
     | 
| 
         @@ -52,4 +48,11 @@ class Janus::RegistrationsController < ApplicationController 
     | 
|
| 
       52 
48 
     | 
    
         
             
              def after_sign_up_url(user)
         
     | 
| 
       53 
49 
     | 
    
         
             
                user
         
     | 
| 
       54 
50 
     | 
    
         
             
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              def resource_params
         
     | 
| 
      
 53 
     | 
    
         
            +
                keys = %w{current_password password password_confirmation}
         
     | 
| 
      
 54 
     | 
    
         
            +
                send("#{janus_scope}_params").reject do |key, value|
         
     | 
| 
      
 55 
     | 
    
         
            +
                  value.blank? and keys.include?(key)
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
       55 
58 
     | 
    
         
             
            end
         
     | 
| 
         @@ -17,7 +17,7 @@ class Janus::SessionsController < ApplicationController 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
              def new
         
     | 
| 
       19 
19 
     | 
    
         
             
                params[:return_to] ||= request.env["HTTP_REFERER"]
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       21 
21 
     | 
    
         
             
                if signed_in?(janus_scope)
         
     | 
| 
       22 
22 
     | 
    
         
             
                  redirect_after_sign_in(send("current_#{janus_scope}"))
         
     | 
| 
       23 
23 
     | 
    
         
             
                else
         
     | 
| 
         @@ -28,10 +28,10 @@ class Janus::SessionsController < ApplicationController 
     | 
|
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
              def create
         
     | 
| 
       30 
30 
     | 
    
         
             
                self.resource = resource_class.find_for_database_authentication(params[resource_name])
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       32 
32 
     | 
    
         
             
                if resource && resource.valid_password?(params[resource_name][:password])
         
     | 
| 
       33 
33 
     | 
    
         
             
                  janus.login(resource, :scope => janus_scope, :rememberable => params[:remember_me])
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       35 
35 
     | 
    
         
             
                  respond_to do |format|
         
     | 
| 
       36 
36 
     | 
    
         
             
                    format.html { redirect_after_sign_in(resource) }
         
     | 
| 
       37 
37 
     | 
    
         
             
                    format.any  { head :ok }
         
     | 
| 
         @@ -39,7 +39,7 @@ class Janus::SessionsController < ApplicationController 
     | 
|
| 
       39 
39 
     | 
    
         
             
                else
         
     | 
| 
       40 
40 
     | 
    
         
             
                  respond_to do |format|
         
     | 
| 
       41 
41 
     | 
    
         
             
                    format.html do
         
     | 
| 
       42 
     | 
    
         
            -
                      self.resource ||= resource_class.new( 
     | 
| 
      
 42 
     | 
    
         
            +
                      self.resource ||= resource_class.new(resource_params)
         
     | 
| 
       43 
43 
     | 
    
         
             
                      resource.clean_up_passwords
         
     | 
| 
       44 
44 
     | 
    
         
             
                      resource.errors.add(:base, :not_found)
         
     | 
| 
       45 
45 
     | 
    
         
             
                      render "new", :status => :unauthorized
         
     | 
| 
         @@ -51,7 +51,7 @@ class Janus::SessionsController < ApplicationController 
     | 
|
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
              def destroy
         
     | 
| 
       53 
53 
     | 
    
         
             
                janus.logout(janus_scope)
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
       55 
55 
     | 
    
         
             
                respond_to do |format|
         
     | 
| 
       56 
56 
     | 
    
         
             
                  format.html { redirect_to after_sign_out_url(janus_scope) }
         
     | 
| 
       57 
57 
     | 
    
         
             
                  format.any  { head :ok }
         
     | 
| 
         @@ -119,13 +119,21 @@ class Janus::SessionsController < ApplicationController 
     | 
|
| 
       119 
119 
     | 
    
         
             
                        query = return_to.query_values || {}
         
     | 
| 
       120 
120 
     | 
    
         
             
                        return_to.query_values = query.merge(user.class.remote_authentication_key => user.generate_remote_token!)
         
     | 
| 
       121 
121 
     | 
    
         
             
                      end
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
       123 
123 
     | 
    
         
             
                      redirect_to return_to.to_s
         
     | 
| 
       124 
124 
     | 
    
         
             
                      return
         
     | 
| 
       125 
125 
     | 
    
         
             
                    end
         
     | 
| 
       126 
126 
     | 
    
         
             
                  end
         
     | 
| 
       127 
127 
     | 
    
         
             
                end
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
       129 
129 
     | 
    
         
             
                redirect_to after_sign_in_url(user)
         
     | 
| 
       130 
130 
     | 
    
         
             
              end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
              def resource_params
         
     | 
| 
      
 133 
     | 
    
         
            +
                if params.respond_to?(:permit)
         
     | 
| 
      
 134 
     | 
    
         
            +
                  params.require(janus_scope).permit(*resource_class.authentication_keys)
         
     | 
| 
      
 135 
     | 
    
         
            +
                else
         
     | 
| 
      
 136 
     | 
    
         
            +
                  params[janus_scope].slice(*resource_class.authentication_keys)
         
     | 
| 
      
 137 
     | 
    
         
            +
                end
         
     | 
| 
      
 138 
     | 
    
         
            +
              end
         
     | 
| 
       131 
139 
     | 
    
         
             
            end
         
     | 
    
        data/lib/janus/helper.rb
    CHANGED
    
    
    
        data/lib/janus/hooks.rb
    CHANGED
    
    | 
         @@ -5,19 +5,19 @@ module Janus 
     | 
|
| 
       5 
5 
     | 
    
         
             
                # Hooks allow you the react at the different steps of a user session.
         
     | 
| 
       6 
6 
     | 
    
         
             
                # All callbacks will receive the same arguments: +user+, +manager+ and
         
     | 
| 
       7 
7 
     | 
    
         
             
                # +options+.
         
     | 
| 
       8 
     | 
    
         
            -
                # 
     | 
| 
      
 8 
     | 
    
         
            +
                #
         
     | 
| 
       9 
9 
     | 
    
         
             
                # Example:
         
     | 
| 
       10 
     | 
    
         
            -
                # 
     | 
| 
      
 10 
     | 
    
         
            +
                #
         
     | 
| 
       11 
11 
     | 
    
         
             
                #   Janus::Manager.after_login do |user, manager, options|
         
     | 
| 
       12 
12 
     | 
    
         
             
                #     session = manager.session(options[:scope])
         
     | 
| 
       13 
     | 
    
         
            -
                # 
     | 
| 
      
 13 
     | 
    
         
            +
                #
         
     | 
| 
       14 
14 
     | 
    
         
             
                #     # write some great code here
         
     | 
| 
       15 
15 
     | 
    
         
             
                #   end
         
     | 
| 
       16 
     | 
    
         
            -
                # 
     | 
| 
      
 16 
     | 
    
         
            +
                #
         
     | 
| 
       17 
17 
     | 
    
         
             
                # Options:
         
     | 
| 
       18 
     | 
    
         
            -
                # 
     | 
| 
      
 18 
     | 
    
         
            +
                #
         
     | 
| 
       19 
19 
     | 
    
         
             
                # - +:scope+
         
     | 
| 
       20 
     | 
    
         
            -
                # 
     | 
| 
      
 20 
     | 
    
         
            +
                #
         
     | 
| 
       21 
21 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       22 
22 
     | 
    
         
             
                  # Executed after a strategy succeeds to authenticate a user.
         
     | 
| 
       23 
23 
     | 
    
         
             
                  def after_authenticate(&block)
         
     |