shingara-devise 0.4.3

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.
Files changed (99) hide show
  1. data/CHANGELOG.rdoc +119 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +253 -0
  4. data/Rakefile +45 -0
  5. data/TODO +5 -0
  6. data/app/controllers/confirmations_controller.rb +33 -0
  7. data/app/controllers/passwords_controller.rb +41 -0
  8. data/app/controllers/sessions_controller.rb +33 -0
  9. data/app/models/devise_mailer.rb +53 -0
  10. data/app/views/confirmations/new.html.erb +16 -0
  11. data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
  12. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  13. data/app/views/passwords/edit.html.erb +20 -0
  14. data/app/views/passwords/new.html.erb +16 -0
  15. data/app/views/sessions/new.html.erb +23 -0
  16. data/generators/devise/USAGE +5 -0
  17. data/generators/devise/devise_generator.rb +25 -0
  18. data/generators/devise/lib/route_devise.rb +32 -0
  19. data/generators/devise/templates/README +22 -0
  20. data/generators/devise/templates/migration.rb +20 -0
  21. data/generators/devise/templates/model.rb +5 -0
  22. data/generators/devise_install/USAGE +3 -0
  23. data/generators/devise_install/devise_install_generator.rb +9 -0
  24. data/generators/devise_install/templates/devise.rb +47 -0
  25. data/generators/devise_views/USAGE +3 -0
  26. data/generators/devise_views/devise_views_generator.rb +24 -0
  27. data/init.rb +2 -0
  28. data/lib/devise/controllers/filters.rb +111 -0
  29. data/lib/devise/controllers/helpers.rb +130 -0
  30. data/lib/devise/controllers/url_helpers.rb +49 -0
  31. data/lib/devise/encryptors/authlogic_sha512.rb +28 -0
  32. data/lib/devise/encryptors/clearance_sha1.rb +26 -0
  33. data/lib/devise/encryptors/restful_authentication_sha1.rb +29 -0
  34. data/lib/devise/encryptors/sha1.rb +34 -0
  35. data/lib/devise/encryptors/sha512.rb +34 -0
  36. data/lib/devise/failure.rb +36 -0
  37. data/lib/devise/hooks/confirmable.rb +11 -0
  38. data/lib/devise/hooks/rememberable.rb +27 -0
  39. data/lib/devise/locales/en.yml +18 -0
  40. data/lib/devise/mapping.rb +120 -0
  41. data/lib/devise/migrations.rb +57 -0
  42. data/lib/devise/models/authenticatable.rb +87 -0
  43. data/lib/devise/models/confirmable.rb +156 -0
  44. data/lib/devise/models/recoverable.rb +88 -0
  45. data/lib/devise/models/rememberable.rb +95 -0
  46. data/lib/devise/models/validatable.rb +36 -0
  47. data/lib/devise/models.rb +110 -0
  48. data/lib/devise/orm/mongo_mapper.rb +26 -0
  49. data/lib/devise/rails/routes.rb +109 -0
  50. data/lib/devise/rails/warden_compat.rb +26 -0
  51. data/lib/devise/rails.rb +17 -0
  52. data/lib/devise/strategies/authenticatable.rb +46 -0
  53. data/lib/devise/strategies/base.rb +24 -0
  54. data/lib/devise/strategies/rememberable.rb +35 -0
  55. data/lib/devise/version.rb +3 -0
  56. data/lib/devise/warden.rb +20 -0
  57. data/lib/devise.rb +130 -0
  58. data/test/controllers/filters_test.rb +103 -0
  59. data/test/controllers/helpers_test.rb +55 -0
  60. data/test/controllers/url_helpers_test.rb +47 -0
  61. data/test/devise_test.rb +72 -0
  62. data/test/encryptors_test.rb +28 -0
  63. data/test/failure_test.rb +34 -0
  64. data/test/integration/authenticatable_test.rb +195 -0
  65. data/test/integration/confirmable_test.rb +89 -0
  66. data/test/integration/recoverable_test.rb +131 -0
  67. data/test/integration/rememberable_test.rb +65 -0
  68. data/test/mailers/confirmation_instructions_test.rb +59 -0
  69. data/test/mailers/reset_password_instructions_test.rb +62 -0
  70. data/test/mapping_test.rb +101 -0
  71. data/test/models/authenticatable_test.rb +130 -0
  72. data/test/models/confirmable_test.rb +237 -0
  73. data/test/models/recoverable_test.rb +141 -0
  74. data/test/models/rememberable_test.rb +130 -0
  75. data/test/models/validatable_test.rb +99 -0
  76. data/test/models_test.rb +111 -0
  77. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  78. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  79. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  80. data/test/rails_app/app/controllers/users_controller.rb +7 -0
  81. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  82. data/test/rails_app/app/models/account.rb +3 -0
  83. data/test/rails_app/app/models/admin.rb +3 -0
  84. data/test/rails_app/app/models/organizer.rb +3 -0
  85. data/test/rails_app/app/models/user.rb +3 -0
  86. data/test/rails_app/config/boot.rb +110 -0
  87. data/test/rails_app/config/environment.rb +41 -0
  88. data/test/rails_app/config/environments/development.rb +17 -0
  89. data/test/rails_app/config/environments/production.rb +28 -0
  90. data/test/rails_app/config/environments/test.rb +28 -0
  91. data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
  92. data/test/rails_app/config/initializers/session_store.rb +15 -0
  93. data/test/rails_app/config/routes.rb +18 -0
  94. data/test/routes_test.rb +79 -0
  95. data/test/support/assertions_helper.rb +22 -0
  96. data/test/support/integration_tests_helper.rb +66 -0
  97. data/test/support/model_tests_helper.rb +51 -0
  98. data/test/test_helper.rb +40 -0
  99. metadata +161 -0
@@ -0,0 +1,23 @@
1
+ <h2>Sign in</h2>
2
+
3
+ <% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
4
+ <p><%= f.label :email %></p>
5
+ <p><%= f.text_field :email %></p>
6
+
7
+ <p><%= f.label :password %></p>
8
+ <p><%= f.password_field :password %></p>
9
+
10
+ <% if devise_mapping.rememberable? -%>
11
+ <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
12
+ <% end -%>
13
+
14
+ <p><%= f.submit "Sign in" %></p>
15
+ <% end -%>
16
+
17
+ <%- if devise_mapping.recoverable? %>
18
+ <%= link_to "Forgot password?", new_password_path(resource_name) %><br />
19
+ <% end -%>
20
+
21
+ <%- if devise_mapping.confirmable? %>
22
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
23
+ <% end -%>
@@ -0,0 +1,5 @@
1
+ To create a devise resource user:
2
+
3
+ script/generate devise User
4
+
5
+ This will generate a model named User, a route map for devise called :users, and a migration file for table :users with all devise modules.
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/route_devise.rb")
2
+
3
+ class DeviseGenerator < Rails::Generator::NamedBase
4
+
5
+ def manifest
6
+ record do |m|
7
+ # Check for class naming collisions.
8
+ m.class_collisions(class_name)
9
+
10
+ # Model
11
+ m.directory(File.join('app', 'models', class_path))
12
+ m.template 'model.rb', File.join('app', 'models', "#{file_path}.rb")
13
+
14
+ # Migration
15
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "devise_create_#{table_name}"
16
+
17
+ # Routing
18
+ m.route_devise table_name
19
+
20
+ # Readme
21
+ m.readme "README"
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,32 @@
1
+ module Rails
2
+ module Generator
3
+ module Commands
4
+ class Create < Base
5
+
6
+ # Create devise route. Based on route_resources
7
+ def route_devise(*resources)
8
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
9
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
10
+
11
+ logger.route "map.devise_for #{resource_list}"
12
+ unless options[:pretend]
13
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
14
+ "#{match}\n map.devise_for #{resource_list}\n"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ class Destroy < RewindBase
21
+
22
+ # Destroy devise route. Based on route_resources
23
+ def route_devise(*resources)
24
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
25
+ look_for = "\n map.devise_for #{resource_list}\n"
26
+ logger.route "map.devise_for #{resource_list}"
27
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+
2
+ ================================================================================
3
+
4
+ Some setup you must do manually if you haven't yet:
5
+
6
+ 1. Setup defaut url options for your specific environment. Here is an example of development environment:
7
+
8
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
9
+
10
+ It's a Rails required configuration. In production it must be the actual host your application is deployed to.
11
+
12
+ 2. Setup default sender for mails. In config/environment.rb:
13
+
14
+ DeviseMailer.sender = "test@example.com"
15
+
16
+ You can also configure this value by running script/generate devise_install and setting config.mailer_sender,
17
+
18
+ 3. Ensure you have defined root_url to *something* in your config/routes.rb:
19
+
20
+ map.root :controller => 'home'
21
+
22
+ ================================================================================
@@ -0,0 +1,20 @@
1
+ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:<%= table_name %>) do |t|
4
+ t.authenticatable :encryptor => :sha1
5
+ t.confirmable
6
+ t.recoverable
7
+ t.rememberable
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :<%= table_name %>, :email, :unique => true
13
+ add_index :<%= table_name %>, :confirmation_token, :unique => true
14
+ add_index :<%= table_name %>, :reset_password_token, :unique => true
15
+ end
16
+
17
+ def self.down
18
+ drop_table :<%= table_name %>
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ devise :all
3
+ # Setup accessible (or protected) attributes for your model
4
+ attr_accessible :email, :password, :password_confirmation
5
+ end
@@ -0,0 +1,3 @@
1
+ To copy a Devise initializer to your Rails App, with some configuration values, just do:
2
+
3
+ script/generate devise_install
@@ -0,0 +1,9 @@
1
+ class DeviseInstallGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.file "devise.rb", "config/initializers/devise.rb"
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,47 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth. The first
2
+ # four configuration values can also be set straight in your models.
3
+ Devise.setup do |config|
4
+ # Invoke `rake secret` and use the printed value to setup a pepper to generate
5
+ # the encrypted password. By default no pepper is used.
6
+ # config.pepper = "rake secret output"
7
+
8
+ # Configure how many times you want the password is reencrypted. Default is 10.
9
+ # config.stretches = 10
10
+
11
+ # Define which will be the encryption algorithm. Supported algorithms are :sha1
12
+ # (default) and :sha512. Devise also supports encryptors from others authentication
13
+ # frameworks as :clearance_sha1, :authlogic_sha512 (then you should set stretches
14
+ # above to 20 for default behavior) and :restful_authentication_sha1 (then you
15
+ # should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
16
+ # config.encryptor = :sha1
17
+
18
+ # The time you want give to your user to confirm his account. During this time
19
+ # he will be able to access your application without confirming. Default is nil.
20
+ # config.confirm_within = 2.days
21
+
22
+ # The time the user will be remembered without asking for credentials again.
23
+ # config.remember_for = 2.weeks
24
+
25
+ # Configure the e-mail address which will be shown in DeviseMailer.
26
+ # config.mailer_sender = "foo.bar@yourapp.com"
27
+
28
+ # If you want to use other strategies, that are not (yet) supported by Devise,
29
+ # you can configure them inside the config.warden block. The example below
30
+ # allows you to setup OAuth, using http://github.com/roman/warden_oauth
31
+ #
32
+ # config.warden do |manager|
33
+ # manager.oauth(:twitter) do |twitter|
34
+ # twitter.consumer_secret = <YOUR CONSUMER SECRET>
35
+ # twitter.consumer_key = <YOUR CONSUMER KEY>
36
+ # twitter.options :site => 'http://twitter.com'
37
+ # end
38
+ # manager.default_strategies.unshift :twitter_oauth
39
+ # end
40
+
41
+ # Configure default_url_options if you are using dynamic segments in :path_prefix
42
+ # for devise_for.
43
+ #
44
+ # config.default_url_options do
45
+ # { :locale => I18n.locale }
46
+ # end
47
+ end
@@ -0,0 +1,3 @@
1
+ To copy all session, password, confirmation and mailer views from devise to your app just run the following command:
2
+
3
+ script/generate devise_views
@@ -0,0 +1,24 @@
1
+ class DeviseViewsGenerator < Rails::Generator::Base
2
+
3
+ def initialize(*args)
4
+ super
5
+ @source_root = options[:source] || File.join(spec.path, '..', '..')
6
+ end
7
+
8
+ def manifest
9
+ record do |m|
10
+ m.directory "app/views"
11
+
12
+ Dir[File.join(@source_root, "app", "views", "**/*.erb")].each do |file|
13
+ file = file.gsub(@source_root, "")[1..-1]
14
+
15
+ m.directory File.dirname(file)
16
+ m.file file, file
17
+ end
18
+
19
+ m.directory "config/locales"
20
+ m.file "lib/devise/locales/en.yml", "config/locales/devise.en.yml"
21
+ end
22
+ end
23
+
24
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # We need to load devise here to ensure routes extensions are loaded.
2
+ require 'devise'
@@ -0,0 +1,111 @@
1
+ module Devise
2
+ module Controllers
3
+ # Those filters are convenience methods added to ApplicationController to
4
+ # deal with Warden.
5
+ module Filters
6
+
7
+ def self.included(base)
8
+ base.class_eval do
9
+ helper_method :warden, :signed_in?, :devise_controller?,
10
+ *Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
11
+
12
+ # Use devise default_url_options. We have to declare it here to overwrite
13
+ # default definitions.
14
+ def default_url_options(options=nil)
15
+ Devise::Mapping.default_url_options
16
+ end
17
+ end
18
+ end
19
+
20
+ # The main accessor for the warden proxy instance
21
+ def warden
22
+ request.env['warden']
23
+ end
24
+
25
+ # Return true if it's a devise_controller. false to all controllers unless
26
+ # the controllers defined inside devise. Useful if you want to apply a before
27
+ # filter to all controller, except the ones in devise:
28
+ #
29
+ # before_filter :my_filter, :unless => { |c| c.devise_controller? }
30
+ def devise_controller?
31
+ false
32
+ end
33
+
34
+ # Attempts to authenticate the given scope by running authentication hooks,
35
+ # but does not redirect in case of failures.
36
+ def authenticate(scope)
37
+ warden.authenticate(:scope => scope)
38
+ end
39
+
40
+ # Attempts to authenticate the given scope by running authentication hooks,
41
+ # redirecting in case of failures.
42
+ def authenticate!(scope)
43
+ warden.authenticate!(:scope => scope)
44
+ end
45
+
46
+ # Check if the given scope is signed in session, without running
47
+ # authentication hooks.
48
+ def signed_in?(scope)
49
+ warden.authenticated?(scope)
50
+ end
51
+
52
+ # Set the warden user with the scope, signing in the resource automatically,
53
+ # without running hooks.
54
+ def sign_in(scope, resource)
55
+ warden.set_user(resource, :scope => scope)
56
+ end
57
+
58
+ # Sign out based on scope.
59
+ def sign_out(scope, *args)
60
+ warden.user(scope) # Without loading user here, before_logout hook is not called
61
+ warden.raw_session.inspect # Without this inspect here. The session does not clear.
62
+ warden.logout(scope, *args)
63
+ end
64
+
65
+ # Define authentication filters and accessor helpers based on mappings.
66
+ # These filters should be used inside the controllers as before_filters,
67
+ # so you can control the scope of the user who should be signed in to
68
+ # access that specific controller/action.
69
+ # Example:
70
+ #
71
+ # Maps:
72
+ # User => :authenticatable
73
+ # Admin => :authenticatable
74
+ #
75
+ # Generated methods:
76
+ # authenticate_user! # Signs user in or redirect
77
+ # authenticate_admin! # Signs admin in or redirect
78
+ # user_signed_in? # Checks whether there is an user signed in or not
79
+ # admin_signed_in? # Checks whether there is an admin signed in or not
80
+ # current_user # Current signed in user
81
+ # current_admin # Currend signed in admin
82
+ # user_session # Session data available only to the user scope
83
+ # admin_session # Session data available only to the admin scope
84
+ #
85
+ # Use:
86
+ # before_filter :authenticate_user! # Tell devise to use :user map
87
+ # before_filter :authenticate_admin! # Tell devise to use :admin map
88
+ #
89
+ Devise.mappings.each_key do |mapping|
90
+ class_eval <<-METHODS, __FILE__, __LINE__
91
+ def authenticate_#{mapping}!
92
+ warden.authenticate!(:scope => :#{mapping})
93
+ end
94
+
95
+ def #{mapping}_signed_in?
96
+ warden.authenticated?(:#{mapping})
97
+ end
98
+
99
+ def current_#{mapping}
100
+ @current_#{mapping} ||= warden.user(:#{mapping})
101
+ end
102
+
103
+ def #{mapping}_session
104
+ warden.session(:#{mapping})
105
+ end
106
+ METHODS
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,130 @@
1
+ module Devise
2
+ module Controllers
3
+ # Those helpers are used only inside Devise controllers and should not be
4
+ # included in ApplicationController since they all depend on the url being
5
+ # accessed.
6
+ module Helpers
7
+
8
+ def self.included(base)
9
+ base.class_eval do
10
+ helper_method :resource, :resource_name, :resource_class, :devise_mapping, :devise_controller?
11
+ hide_action :resource, :resource_name, :resource_class, :devise_mapping, :devise_controller?
12
+
13
+ skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
14
+ before_filter :is_devise_resource?
15
+ end
16
+ end
17
+
18
+ # Gets the actual resource stored in the instance variable
19
+ def resource
20
+ instance_variable_get(:"@#{resource_name}")
21
+ end
22
+
23
+ # Proxy to devise map name
24
+ def resource_name
25
+ devise_mapping.name
26
+ end
27
+
28
+ # Proxy to devise map class
29
+ def resource_class
30
+ devise_mapping.to
31
+ end
32
+
33
+ # Attempt to find the mapped route for devise based on request path
34
+ def devise_mapping
35
+ @devise_mapping ||= Devise::Mapping.find_by_path(request.path)
36
+ end
37
+
38
+ # Overwrites devise_controller? to return true
39
+ def devise_controller?
40
+ true
41
+ end
42
+
43
+ protected
44
+
45
+ # Redirects to stored uri before signing in or the default path and clear
46
+ # return to.
47
+ def redirect_back_or_to(default)
48
+ redirect_to(return_to || default)
49
+ clear_return_to
50
+ end
51
+
52
+ # Access to scoped stored uri
53
+ def return_to
54
+ session[:"#{resource_name}.return_to"]
55
+ end
56
+
57
+ # Clear scoped stored uri
58
+ def clear_return_to
59
+ session[:"#{resource_name}.return_to"] = nil
60
+ end
61
+
62
+ # Checks for the existence of the resource root path. If it exists,
63
+ # returns it, otherwise returns the default root_path.
64
+ # Used after authenticating a user, confirming it's account or updating
65
+ # it's password, so we are able to redirect to scoped root paths.
66
+ # Examples (for a user scope):
67
+ # map.user_root '/users', :controller => 'users' # creates user_root_path
68
+ #
69
+ # map.namespace :users do |users|
70
+ # users.root # creates user_root_path
71
+ # end
72
+ def home_or_root_path
73
+ home_path = :"#{resource_name}_root_path"
74
+ respond_to?(home_path, true) ? send(home_path) : root_path
75
+ end
76
+
77
+ # Checks whether it's a devise mapped resource or not.
78
+ def is_devise_resource? #:nodoc:
79
+ raise ActionController::UnknownAction unless devise_mapping && devise_mapping.allows?(controller_name)
80
+ end
81
+
82
+ # Sets the resource creating an instance variable
83
+ def resource=(new_resource)
84
+ instance_variable_set(:"@#{resource_name}", new_resource)
85
+ end
86
+
87
+ # Build a devise resource without setting password and password confirmation fields.
88
+ def build_resource
89
+ self.resource ||= begin
90
+ attributes = params[resource_name].try(:except, :password, :password_confirmation)
91
+ resource_class.new(attributes)
92
+ end
93
+ end
94
+
95
+ # Helper for use in before_filters where no authentication is required.
96
+ #
97
+ # Example:
98
+ # before_filter :require_no_authentication, :only => :new
99
+ def require_no_authentication
100
+ redirect_to home_or_root_path if warden.authenticated?(resource_name)
101
+ end
102
+
103
+ # Sets the flash message with :key, using I18n. By default you are able
104
+ # to setup your messages using specific resource scope, and if no one is
105
+ # found we look to default scope.
106
+ # Example (i18n locale file):
107
+ #
108
+ # en:
109
+ # devise:
110
+ # passwords:
111
+ # #default_scope_messages - only if resource_scope is not found
112
+ # user:
113
+ # #resource_scope_messages
114
+ #
115
+ # Please refer to README or en.yml locale file to check what messages are
116
+ # available.
117
+ def set_flash_message(key, kind, now=false)
118
+ flash_hash = now ? flash.now : flash
119
+ flash_hash[key] = I18n.t(:"#{resource_name}.#{kind}",
120
+ :scope => [:devise, controller_name.to_sym], :default => kind)
121
+ end
122
+
123
+ # Shortcut to set flash.now message. Same rules applied from set_flash_message
124
+ def set_now_flash_message(key, kind)
125
+ set_flash_message(key, kind, true)
126
+ end
127
+
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,49 @@
1
+ module Devise
2
+ module Controllers
3
+ # Create url helpers to be used with resource/scope configuration. Acts as
4
+ # proxies to the generated routes created by devise.
5
+ # Resource param can be a string or symbol, a class, or an instance object.
6
+ # Example using a :user resource:
7
+ #
8
+ # new_session_path(:user) => new_user_session_path
9
+ # session_path(:user) => user_session_path
10
+ # destroy_session_path(:user) => destroy_user_session_path
11
+ #
12
+ # new_password_path(:user) => new_user_password_path
13
+ # password_path(:user) => user_password_path
14
+ # edit_password_path(:user) => edit_user_password_path
15
+ #
16
+ # new_confirmation_path(:user) => new_user_confirmation_path
17
+ # confirmation_path(:user) => user_confirmation_path
18
+ #
19
+ # Those helpers are added to your ApplicationController.
20
+ module UrlHelpers
21
+
22
+ [:session, :password, :confirmation].each do |module_name|
23
+ [:path, :url].each do |path_or_url|
24
+ actions = [ nil, :new_ ]
25
+ actions << :edit_ if module_name == :password
26
+ actions << :destroy_ if module_name == :session
27
+
28
+ actions.each do |action|
29
+ class_eval <<-URL_HELPERS
30
+ def #{action}#{module_name}_#{path_or_url}(resource, *args)
31
+ resource = case resource
32
+ when Symbol, String
33
+ resource
34
+ when Class
35
+ resource.name.underscore
36
+ else
37
+ resource.class.name.underscore
38
+ end
39
+
40
+ send("#{action}\#{resource}_#{module_name}_#{path_or_url}", *args)
41
+ end
42
+ URL_HELPERS
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ require "digest/sha2"
2
+
3
+ module Devise
4
+ # Implements a way of adding different encryptions.
5
+ # The class should implement a self.digest method that taks the following params:
6
+ # - password
7
+ # - stretches: the number of times the encryption will be applied
8
+ # - salt: the password salt as defined by devise
9
+ # - pepper: Devise config option
10
+ #
11
+ module Encryptors
12
+ # = AuthlogicSha512
13
+ # Simulates Authlogic's default encryption mechanism.
14
+ # Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to silumate
15
+ # the default behavior.
16
+ class AuthlogicSha512
17
+
18
+ # Gererates a default password digest based on salt, pepper and the
19
+ # incoming password.
20
+ def self.digest(password, stretches, salt, pepper)
21
+ digest = [password, salt].flatten.join('')
22
+ stretches.times { digest = Digest::SHA512.hexdigest(digest) }
23
+ digest
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ require "digest/sha1"
2
+
3
+ module Devise
4
+ # Implements a way of adding different encryptions.
5
+ # The class should implement a self.digest method that taks the following params:
6
+ # - password
7
+ # - stretches: the number of times the encryption will be applied
8
+ # - salt: the password salt as defined by devise
9
+ # - pepper: Devise config option
10
+ #
11
+ module Encryptors
12
+ # = ClearanceSha1
13
+ # Simulates Clearance's default encryption mechanism.
14
+ # Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
15
+ # Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES
16
+ class ClearanceSha1
17
+
18
+ # Gererates a default password digest based on salt, pepper and the
19
+ # incoming password.
20
+ def self.digest(password, stretches, salt, pepper)
21
+ Digest::SHA1.hexdigest("--#{salt}--#{password}--")
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ require "digest/sha1"
2
+
3
+ module Devise
4
+ # Implements a way of adding different encryptions.
5
+ # The class should implement a self.digest method that taks the following params:
6
+ # - password
7
+ # - stretches: the number of times the encryption will be applied
8
+ # - salt: the password salt as defined by devise
9
+ # - pepper: Devise config option
10
+ #
11
+ module Encryptors
12
+ # = RestfulAuthenticationSha1
13
+ # Simulates Restful Authentication's default encryption mechanism.
14
+ # Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
15
+ # Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES. Should be set to 10 in
16
+ # the initializer to silumate the default behavior.
17
+ class RestfulAuthenticationSha1
18
+
19
+ # Gererates a default password digest based on salt, pepper and the
20
+ # incoming password.
21
+ def self.digest(password, stretches, salt, pepper)
22
+ digest = pepper
23
+ stretches.times { digest = Digest::SHA1.hexdigest([digest, salt, password, pepper].flatten.join('--')) }
24
+ digest
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ require "digest/sha1"
2
+
3
+ module Devise
4
+ # Implements a way of adding different encryptions.
5
+ # The class should implement a self.digest method that taks the following params:
6
+ # - password
7
+ # - stretches: the number of times the encryption will be applied
8
+ # - salt: the password salt as defined by devise
9
+ # - pepper: Devise config option
10
+ #
11
+ module Encryptors
12
+ # = Sha1
13
+ # Uses the Sha1 hash algorithm to encrypt passwords.
14
+ class Sha1
15
+
16
+ # Gererates a default password digest based on stretches, salt, pepper and the
17
+ # incoming password.
18
+ def self.digest(password, stretches, salt, pepper)
19
+ digest = pepper
20
+ stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
21
+ digest
22
+ end
23
+
24
+ private
25
+
26
+ # Generate a SHA1 digest joining args. Generated token is something like
27
+ # --arg1--arg2--arg3--argN--
28
+ def self.secure_digest(*tokens)
29
+ ::Digest::SHA1.hexdigest('--' << tokens.flatten.join('--') << '--')
30
+ end
31
+
32
+ end
33
+ end
34
+ end