loyal_devise 2.1.2
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/.gitignore +10 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.rdoc +881 -0
- data/CONTRIBUTING.md +12 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +388 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +44 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
- data/app/controllers/devise/passwords_controller.rb +57 -0
- data/app/controllers/devise/registrations_controller.rb +120 -0
- data/app/controllers/devise/sessions_controller.rb +51 -0
- data/app/controllers/devise/unlocks_controller.rb +45 -0
- data/app/controllers/devise_controller.rb +193 -0
- data/app/helpers/devise_helper.rb +26 -0
- data/app/mailers/devise/mailer.rb +16 -0
- data/app/views/devise/_links.erb +3 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +59 -0
- data/devise.gemspec +26 -0
- data/gemfiles/Gemfile.rails-3.1.x +35 -0
- data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
- data/lib/devise/controllers/helpers.rb +273 -0
- data/lib/devise/controllers/rememberable.rb +53 -0
- data/lib/devise/controllers/scoped_views.rb +18 -0
- data/lib/devise/controllers/url_helpers.rb +68 -0
- data/lib/devise/delegator.rb +17 -0
- data/lib/devise/failure_app.rb +188 -0
- data/lib/devise/hooks/activatable.rb +12 -0
- data/lib/devise/hooks/forgetable.rb +10 -0
- data/lib/devise/hooks/lockable.rb +8 -0
- data/lib/devise/hooks/rememberable.rb +7 -0
- data/lib/devise/hooks/timeoutable.rb +26 -0
- data/lib/devise/hooks/trackable.rb +10 -0
- data/lib/devise/mailers/helpers.rb +92 -0
- data/lib/devise/mapping.rb +173 -0
- data/lib/devise/models/authenticatable.rb +269 -0
- data/lib/devise/models/confirmable.rb +271 -0
- data/lib/devise/models/database_authenticatable.rb +127 -0
- data/lib/devise/models/lockable.rb +194 -0
- data/lib/devise/models/omniauthable.rb +28 -0
- data/lib/devise/models/recoverable.rb +141 -0
- data/lib/devise/models/registerable.rb +26 -0
- data/lib/devise/models/rememberable.rb +126 -0
- data/lib/devise/models/timeoutable.rb +50 -0
- data/lib/devise/models/token_authenticatable.rb +90 -0
- data/lib/devise/models/trackable.rb +36 -0
- data/lib/devise/models/validatable.rb +67 -0
- data/lib/devise/models.rb +129 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +46 -0
- data/lib/devise/omniauth/url_helpers.rb +19 -0
- data/lib/devise/omniauth.rb +29 -0
- data/lib/devise/orm/active_record.rb +4 -0
- data/lib/devise/orm/mongoid.rb +4 -0
- data/lib/devise/param_filter.rb +42 -0
- data/lib/devise/rails/routes.rb +447 -0
- data/lib/devise/rails/warden_compat.rb +44 -0
- data/lib/devise/rails.rb +55 -0
- data/lib/devise/strategies/authenticatable.rb +177 -0
- data/lib/devise/strategies/base.rb +21 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +56 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +132 -0
- data/lib/devise/time_inflector.rb +15 -0
- data/lib/devise/version.rb +4 -0
- data/lib/devise.rb +445 -0
- data/lib/generators/active_record/devise_generator.rb +80 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/active_record/templates/migration_existing.rb +27 -0
- data/lib/generators/devise/devise_generator.rb +25 -0
- data/lib/generators/devise/install_generator.rb +25 -0
- data/lib/generators/devise/orm_helpers.rb +33 -0
- data/lib/generators/devise/views_generator.rb +117 -0
- data/lib/generators/mongoid/devise_generator.rb +58 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/devise.rb +241 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
- data/test/controllers/custom_strategy_test.rb +63 -0
- data/test/controllers/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +111 -0
- data/test/controllers/sessions_controller_test.rb +58 -0
- data/test/controllers/url_helpers_test.rb +60 -0
- data/test/delegator_test.rb +20 -0
- data/test/devise_test.rb +73 -0
- data/test/failure_app_test.rb +222 -0
- data/test/generators/active_record_generator_test.rb +76 -0
- data/test/generators/devise_generator_test.rb +40 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/mongoid_generator_test.rb +24 -0
- data/test/generators/views_generator_test.rb +53 -0
- data/test/helpers/devise_helper_test.rb +52 -0
- data/test/indifferent_hash.rb +34 -0
- data/test/integration/authenticatable_test.rb +634 -0
- data/test/integration/confirmable_test.rb +299 -0
- data/test/integration/database_authenticatable_test.rb +83 -0
- data/test/integration/http_authenticatable_test.rb +98 -0
- data/test/integration/lockable_test.rb +243 -0
- data/test/integration/omniauthable_test.rb +134 -0
- data/test/integration/recoverable_test.rb +307 -0
- data/test/integration/registerable_test.rb +346 -0
- data/test/integration/rememberable_test.rb +159 -0
- data/test/integration/timeoutable_test.rb +141 -0
- data/test/integration/token_authenticatable_test.rb +162 -0
- data/test/integration/trackable_test.rb +93 -0
- data/test/mailers/confirmation_instructions_test.rb +103 -0
- data/test/mailers/reset_password_instructions_test.rb +84 -0
- data/test/mailers/unlock_instructions_test.rb +78 -0
- data/test/mapping_test.rb +128 -0
- data/test/models/authenticatable_test.rb +8 -0
- data/test/models/confirmable_test.rb +392 -0
- data/test/models/database_authenticatable_test.rb +190 -0
- data/test/models/lockable_test.rb +274 -0
- data/test/models/omniauthable_test.rb +8 -0
- data/test/models/recoverable_test.rb +206 -0
- data/test/models/registerable_test.rb +8 -0
- data/test/models/rememberable_test.rb +175 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +47 -0
- data/test/models/token_authenticatable_test.rb +56 -0
- data/test/models/trackable_test.rb +14 -0
- data/test/models/validatable_test.rb +117 -0
- data/test/models_test.rb +180 -0
- data/test/omniauth/config_test.rb +58 -0
- data/test/omniauth/url_helpers_test.rb +52 -0
- data/test/orm/active_record.rb +10 -0
- data/test/orm/mongoid.rb +15 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/shim.rb +3 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +12 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +26 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
- data/test/rails_app/app/controllers/users_controller.rb +24 -0
- data/test/rails_app/app/helpers/application_helper.rb +4 -0
- data/test/rails_app/app/mailers/users/mailer.rb +9 -0
- data/test/rails_app/app/mongoid/admin.rb +28 -0
- data/test/rails_app/app/mongoid/shim.rb +25 -0
- data/test/rails_app/app/mongoid/user.rb +43 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config/application.rb +42 -0
- data/test/rails_app/config/boot.rb +9 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +6 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +34 -0
- data/test/rails_app/config/environments/test.rb +34 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
- data/test/rails_app/config/initializers/devise.rb +179 -0
- data/test/rails_app/config/initializers/inflections.rb +3 -0
- data/test/rails_app/config/initializers/secret_token.rb +3 -0
- data/test/rails_app/config/routes.rb +101 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
- data/test/rails_app/db/schema.rb +53 -0
- data/test/rails_app/lib/shared_admin.rb +15 -0
- data/test/rails_app/lib/shared_user.rb +27 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +249 -0
- data/test/support/assertions.rb +41 -0
- data/test/support/helpers.rb +92 -0
- data/test/support/integration.rb +93 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +25 -0
- data/test/test_helper.rb +28 -0
- data/test/test_helpers_test.rb +152 -0
- metadata +407 -0
data/lib/devise.rb
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'rails'
|
|
3
|
+
require 'active_support/core_ext/numeric/time'
|
|
4
|
+
require 'active_support/dependencies'
|
|
5
|
+
require 'orm_adapter'
|
|
6
|
+
require 'set'
|
|
7
|
+
require 'securerandom'
|
|
8
|
+
|
|
9
|
+
module Devise
|
|
10
|
+
autoload :Delegator, 'devise/delegator'
|
|
11
|
+
autoload :FailureApp, 'devise/failure_app'
|
|
12
|
+
autoload :OmniAuth, 'devise/omniauth'
|
|
13
|
+
autoload :ParamFilter, 'devise/param_filter'
|
|
14
|
+
autoload :TestHelpers, 'devise/test_helpers'
|
|
15
|
+
autoload :TimeInflector, 'devise/time_inflector'
|
|
16
|
+
|
|
17
|
+
module Controllers
|
|
18
|
+
autoload :Helpers, 'devise/controllers/helpers'
|
|
19
|
+
autoload :Rememberable, 'devise/controllers/rememberable'
|
|
20
|
+
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
|
21
|
+
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module Mailers
|
|
25
|
+
autoload :Helpers, 'devise/mailers/helpers'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
module Strategies
|
|
29
|
+
autoload :Base, 'devise/strategies/base'
|
|
30
|
+
autoload :Authenticatable, 'devise/strategies/authenticatable'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Constants which holds devise configuration for extensions. Those should
|
|
34
|
+
# not be modified by the "end user" (this is why they are constants).
|
|
35
|
+
ALL = []
|
|
36
|
+
CONTROLLERS = ActiveSupport::OrderedHash.new
|
|
37
|
+
ROUTES = ActiveSupport::OrderedHash.new
|
|
38
|
+
STRATEGIES = ActiveSupport::OrderedHash.new
|
|
39
|
+
URL_HELPERS = ActiveSupport::OrderedHash.new
|
|
40
|
+
|
|
41
|
+
# Strategies that do not require user input.
|
|
42
|
+
NO_INPUT = []
|
|
43
|
+
|
|
44
|
+
# True values used to check params
|
|
45
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
|
46
|
+
|
|
47
|
+
# Custom domain for cookies. Not set by default
|
|
48
|
+
mattr_accessor :rememberable_options
|
|
49
|
+
@@rememberable_options = {}
|
|
50
|
+
|
|
51
|
+
# The number of times to encrypt password.
|
|
52
|
+
mattr_accessor :stretches
|
|
53
|
+
@@stretches = 10
|
|
54
|
+
|
|
55
|
+
# Keys used when authenticating a user.
|
|
56
|
+
mattr_accessor :authentication_keys
|
|
57
|
+
@@authentication_keys = [ :email ]
|
|
58
|
+
|
|
59
|
+
# Request keys used when authenticating a user.
|
|
60
|
+
mattr_accessor :request_keys
|
|
61
|
+
@@request_keys = []
|
|
62
|
+
|
|
63
|
+
# Keys that should be case-insensitive.
|
|
64
|
+
mattr_accessor :case_insensitive_keys
|
|
65
|
+
@@case_insensitive_keys = [ :email ]
|
|
66
|
+
|
|
67
|
+
# Keys that should have whitespace stripped.
|
|
68
|
+
mattr_accessor :strip_whitespace_keys
|
|
69
|
+
@@strip_whitespace_keys = []
|
|
70
|
+
|
|
71
|
+
# If http authentication is enabled by default.
|
|
72
|
+
mattr_accessor :http_authenticatable
|
|
73
|
+
@@http_authenticatable = false
|
|
74
|
+
|
|
75
|
+
# If http headers should be returned for ajax requests. True by default.
|
|
76
|
+
mattr_accessor :http_authenticatable_on_xhr
|
|
77
|
+
@@http_authenticatable_on_xhr = true
|
|
78
|
+
|
|
79
|
+
# If params authenticatable is enabled by default.
|
|
80
|
+
mattr_accessor :params_authenticatable
|
|
81
|
+
@@params_authenticatable = true
|
|
82
|
+
|
|
83
|
+
# The realm used in Http Basic Authentication.
|
|
84
|
+
mattr_accessor :http_authentication_realm
|
|
85
|
+
@@http_authentication_realm = "Application"
|
|
86
|
+
|
|
87
|
+
# Email regex used to validate email formats. It simply asserts that
|
|
88
|
+
# an one (and only one) @ exists in the given string. This is mainly
|
|
89
|
+
# to give user feedback and not to assert the e-mail validity.
|
|
90
|
+
mattr_accessor :email_regexp
|
|
91
|
+
@@email_regexp = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
|
|
92
|
+
|
|
93
|
+
# Range validation for password length
|
|
94
|
+
mattr_accessor :password_length
|
|
95
|
+
@@password_length = 6..128
|
|
96
|
+
|
|
97
|
+
# The time the user will be remembered without asking for credentials again.
|
|
98
|
+
mattr_accessor :remember_for
|
|
99
|
+
@@remember_for = 2.weeks
|
|
100
|
+
|
|
101
|
+
# If true, extends the user's remember period when remembered via cookie.
|
|
102
|
+
mattr_accessor :extend_remember_period
|
|
103
|
+
@@extend_remember_period = false
|
|
104
|
+
|
|
105
|
+
# Time interval you can access your account before confirming your account.
|
|
106
|
+
mattr_accessor :allow_unconfirmed_access_for
|
|
107
|
+
@@allow_unconfirmed_access_for = 0.days
|
|
108
|
+
|
|
109
|
+
# Time interval the confirmation token is valid. nil = unlimited
|
|
110
|
+
mattr_accessor :confirm_within
|
|
111
|
+
@@confirm_within = nil
|
|
112
|
+
|
|
113
|
+
# Defines which key will be used when confirming an account.
|
|
114
|
+
mattr_accessor :confirmation_keys
|
|
115
|
+
@@confirmation_keys = [ :email ]
|
|
116
|
+
|
|
117
|
+
# Defines if email should be reconfirmable.
|
|
118
|
+
# False by default for backwards compatibility.
|
|
119
|
+
mattr_accessor :reconfirmable
|
|
120
|
+
@@reconfirmable = false
|
|
121
|
+
|
|
122
|
+
# Time interval to timeout the user session without activity.
|
|
123
|
+
mattr_accessor :timeout_in
|
|
124
|
+
@@timeout_in = 30.minutes
|
|
125
|
+
|
|
126
|
+
# Authentication token expiration on timeout
|
|
127
|
+
mattr_accessor :expire_auth_token_on_timeout
|
|
128
|
+
@@expire_auth_token_on_timeout = false
|
|
129
|
+
|
|
130
|
+
# Used to encrypt password. Please generate one with rake secret.
|
|
131
|
+
mattr_accessor :pepper
|
|
132
|
+
@@pepper = nil
|
|
133
|
+
|
|
134
|
+
# Scoped views. Since it relies on fallbacks to render default views, it's
|
|
135
|
+
# turned off by default.
|
|
136
|
+
mattr_accessor :scoped_views
|
|
137
|
+
@@scoped_views = false
|
|
138
|
+
|
|
139
|
+
# Defines which strategy can be used to lock an account.
|
|
140
|
+
# Values: :failed_attempts, :none
|
|
141
|
+
mattr_accessor :lock_strategy
|
|
142
|
+
@@lock_strategy = :failed_attempts
|
|
143
|
+
|
|
144
|
+
# Defines which key will be used when locking and unlocking an account
|
|
145
|
+
mattr_accessor :unlock_keys
|
|
146
|
+
@@unlock_keys = [ :email ]
|
|
147
|
+
|
|
148
|
+
# Defines which strategy can be used to unlock an account.
|
|
149
|
+
# Values: :email, :time, :both
|
|
150
|
+
mattr_accessor :unlock_strategy
|
|
151
|
+
@@unlock_strategy = :both
|
|
152
|
+
|
|
153
|
+
# Number of authentication tries before locking an account
|
|
154
|
+
mattr_accessor :maximum_attempts
|
|
155
|
+
@@maximum_attempts = 20
|
|
156
|
+
|
|
157
|
+
# Time interval to unlock the account if :time is defined as unlock_strategy.
|
|
158
|
+
mattr_accessor :unlock_in
|
|
159
|
+
@@unlock_in = 1.hour
|
|
160
|
+
|
|
161
|
+
# Defines which key will be used when recovering the password for an account
|
|
162
|
+
mattr_accessor :reset_password_keys
|
|
163
|
+
@@reset_password_keys = [ :email ]
|
|
164
|
+
|
|
165
|
+
# Time interval you can reset your password with a reset password key
|
|
166
|
+
mattr_accessor :reset_password_within
|
|
167
|
+
@@reset_password_within = 6.hours
|
|
168
|
+
|
|
169
|
+
# The default scope which is used by warden.
|
|
170
|
+
mattr_accessor :default_scope
|
|
171
|
+
@@default_scope = nil
|
|
172
|
+
|
|
173
|
+
# Address which sends Devise e-mails.
|
|
174
|
+
mattr_accessor :mailer_sender
|
|
175
|
+
@@mailer_sender = nil
|
|
176
|
+
|
|
177
|
+
# Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
|
|
178
|
+
mattr_accessor :token_authentication_key
|
|
179
|
+
@@token_authentication_key = :auth_token
|
|
180
|
+
|
|
181
|
+
# Skip session storage for the following strategies
|
|
182
|
+
mattr_accessor :skip_session_storage
|
|
183
|
+
@@skip_session_storage = []
|
|
184
|
+
|
|
185
|
+
# Which formats should be treated as navigational.
|
|
186
|
+
mattr_accessor :navigational_formats
|
|
187
|
+
@@navigational_formats = ["*/*", :html]
|
|
188
|
+
|
|
189
|
+
# When set to true, signing out a user signs out all other scopes.
|
|
190
|
+
mattr_accessor :sign_out_all_scopes
|
|
191
|
+
@@sign_out_all_scopes = true
|
|
192
|
+
|
|
193
|
+
# The default method used while signing out
|
|
194
|
+
mattr_accessor :sign_out_via
|
|
195
|
+
@@sign_out_via = :get
|
|
196
|
+
|
|
197
|
+
# The parent controller all Devise controllers inherits from.
|
|
198
|
+
# Defaults to ApplicationController. This should be set early
|
|
199
|
+
# in the initialization process and should be set to a string.
|
|
200
|
+
mattr_accessor :parent_controller
|
|
201
|
+
@@parent_controller = "ApplicationController"
|
|
202
|
+
|
|
203
|
+
# The router Devise should use to generate routes. Defaults
|
|
204
|
+
# to :main_app. Should be overriden by engines in order
|
|
205
|
+
# to provide custom routes.
|
|
206
|
+
mattr_accessor :router_name
|
|
207
|
+
@@router_name = nil
|
|
208
|
+
|
|
209
|
+
# Set the omniauth path prefix so it can be overriden when
|
|
210
|
+
# Devise is used in a mountable engine
|
|
211
|
+
mattr_accessor :omniauth_path_prefix
|
|
212
|
+
@@omniauth_path_prefix = nil
|
|
213
|
+
|
|
214
|
+
def self.encryptor=(value)
|
|
215
|
+
warn "\n[DEVISE] To select a encryption which isn't bcrypt, you should use devise-encryptable gem.\n"
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def self.use_salt_as_remember_token=(value)
|
|
219
|
+
warn "\n[DEVISE] Devise.use_salt_as_remember_token is deprecated and has no effect. Please remove it.\n"
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def self.apply_schema=(value)
|
|
223
|
+
warn "\n[DEVISE] Devise.apply_schema is deprecated and has no effect. Please remove it.\n"
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# PRIVATE CONFIGURATION
|
|
227
|
+
|
|
228
|
+
# Store scopes mappings.
|
|
229
|
+
mattr_reader :mappings
|
|
230
|
+
@@mappings = ActiveSupport::OrderedHash.new
|
|
231
|
+
|
|
232
|
+
# Omniauth configurations.
|
|
233
|
+
mattr_reader :omniauth_configs
|
|
234
|
+
@@omniauth_configs = ActiveSupport::OrderedHash.new
|
|
235
|
+
|
|
236
|
+
# Define a set of modules that are called when a mapping is added.
|
|
237
|
+
mattr_reader :helpers
|
|
238
|
+
@@helpers = Set.new
|
|
239
|
+
@@helpers << Devise::Controllers::Helpers
|
|
240
|
+
|
|
241
|
+
# Private methods to interface with Warden.
|
|
242
|
+
mattr_accessor :warden_config
|
|
243
|
+
@@warden_config = nil
|
|
244
|
+
@@warden_config_block = nil
|
|
245
|
+
|
|
246
|
+
# When true, enter in paranoid mode to avoid user enumeration.
|
|
247
|
+
mattr_accessor :paranoid
|
|
248
|
+
@@paranoid = false
|
|
249
|
+
|
|
250
|
+
# Default way to setup Devise. Run rails generate devise_install to create
|
|
251
|
+
# a fresh initializer with all configuration values.
|
|
252
|
+
def self.setup
|
|
253
|
+
yield self
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
class Getter
|
|
257
|
+
def initialize name
|
|
258
|
+
@name = name
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def get
|
|
262
|
+
ActiveSupport::Dependencies.constantize(@name)
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def self.ref(arg)
|
|
267
|
+
if defined?(ActiveSupport::Dependencies::ClassCache)
|
|
268
|
+
ActiveSupport::Dependencies::reference(arg)
|
|
269
|
+
Getter.new(arg)
|
|
270
|
+
else
|
|
271
|
+
ActiveSupport::Dependencies.ref(arg)
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def self.available_router_name
|
|
276
|
+
router_name || :main_app
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def self.omniauth_providers
|
|
280
|
+
omniauth_configs.keys
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Get the mailer class from the mailer reference object.
|
|
284
|
+
def self.mailer
|
|
285
|
+
@@mailer_ref.get
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# Set the mailer reference object to access the mailer.
|
|
289
|
+
def self.mailer=(class_name)
|
|
290
|
+
@@mailer_ref = ref(class_name)
|
|
291
|
+
end
|
|
292
|
+
self.mailer = "Devise::Mailer"
|
|
293
|
+
|
|
294
|
+
# Small method that adds a mapping to Devise.
|
|
295
|
+
def self.add_mapping(resource, options)
|
|
296
|
+
mapping = Devise::Mapping.new(resource, options)
|
|
297
|
+
@@mappings[mapping.name] = mapping
|
|
298
|
+
@@default_scope ||= mapping.name
|
|
299
|
+
@@helpers.each { |h| h.define_helpers(mapping) }
|
|
300
|
+
mapping
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
# Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
|
|
304
|
+
#
|
|
305
|
+
# == Options:
|
|
306
|
+
#
|
|
307
|
+
# +model+ - String representing the load path to a custom *model* for this module (to autoload.)
|
|
308
|
+
# +controller+ - Symbol representing the name of an exisiting or custom *controller* for this module.
|
|
309
|
+
# +route+ - Symbol representing the named *route* helper for this module.
|
|
310
|
+
# +strategy+ - Symbol representing if this module got a custom *strategy*.
|
|
311
|
+
#
|
|
312
|
+
# All values, except :model, accept also a boolean and will have the same name as the given module
|
|
313
|
+
# name.
|
|
314
|
+
#
|
|
315
|
+
# == Examples:
|
|
316
|
+
#
|
|
317
|
+
# Devise.add_module(:party_module)
|
|
318
|
+
# Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
|
|
319
|
+
# Devise.add_module(:party_module, :model => 'party_module/model')
|
|
320
|
+
#
|
|
321
|
+
def self.add_module(module_name, options = {})
|
|
322
|
+
ALL << module_name
|
|
323
|
+
options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input)
|
|
324
|
+
|
|
325
|
+
if strategy = options[:strategy]
|
|
326
|
+
strategy = (strategy == true ? module_name : strategy)
|
|
327
|
+
STRATEGIES[module_name] = strategy
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
if controller = options[:controller]
|
|
331
|
+
controller = (controller == true ? module_name : controller)
|
|
332
|
+
CONTROLLERS[module_name] = controller
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
NO_INPUT << strategy if options[:no_input]
|
|
336
|
+
|
|
337
|
+
if route = options[:route]
|
|
338
|
+
case route
|
|
339
|
+
when TrueClass
|
|
340
|
+
key, value = module_name, []
|
|
341
|
+
when Symbol
|
|
342
|
+
key, value = route, []
|
|
343
|
+
when Hash
|
|
344
|
+
key, value = route.keys.first, route.values.flatten
|
|
345
|
+
else
|
|
346
|
+
raise ArgumentError, ":route should be true, a Symbol or a Hash"
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
URL_HELPERS[key] ||= []
|
|
350
|
+
URL_HELPERS[key].concat(value)
|
|
351
|
+
URL_HELPERS[key].uniq!
|
|
352
|
+
|
|
353
|
+
ROUTES[module_name] = key
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
if options[:model]
|
|
357
|
+
path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
|
|
358
|
+
camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
|
|
359
|
+
Devise::Models.send(:autoload, camelized.to_sym, path)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
Devise::Mapping.add_module module_name
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# Sets warden configuration using a block that will be invoked on warden
|
|
366
|
+
# initialization.
|
|
367
|
+
#
|
|
368
|
+
# Devise.initialize do |config|
|
|
369
|
+
# config.allow_unconfirmed_access_for = 2.days
|
|
370
|
+
#
|
|
371
|
+
# config.warden do |manager|
|
|
372
|
+
# # Configure warden to use other strategies, like oauth.
|
|
373
|
+
# manager.oauth(:twitter)
|
|
374
|
+
# end
|
|
375
|
+
# end
|
|
376
|
+
def self.warden(&block)
|
|
377
|
+
@@warden_config_block = block
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# Specify an omniauth provider.
|
|
381
|
+
#
|
|
382
|
+
# config.omniauth :github, APP_ID, APP_SECRET
|
|
383
|
+
#
|
|
384
|
+
def self.omniauth(provider, *args)
|
|
385
|
+
@@helpers << Devise::OmniAuth::UrlHelpers
|
|
386
|
+
config = Devise::OmniAuth::Config.new(provider, args)
|
|
387
|
+
@@omniauth_configs[config.strategy_name.to_sym] = config
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
# Include helpers in the given scope to AC and AV.
|
|
391
|
+
def self.include_helpers(scope)
|
|
392
|
+
ActiveSupport.on_load(:action_controller) do
|
|
393
|
+
include scope::Helpers if defined?(scope::Helpers)
|
|
394
|
+
include scope::UrlHelpers
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
ActiveSupport.on_load(:action_view) do
|
|
398
|
+
include scope::UrlHelpers
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
# Regenerates url helpers considering Devise.mapping
|
|
403
|
+
def self.regenerate_helpers!
|
|
404
|
+
Devise::Controllers::UrlHelpers.remove_helpers!
|
|
405
|
+
Devise::Controllers::UrlHelpers.generate_helpers!
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
# A method used internally to setup warden manager from the Rails initialize
|
|
409
|
+
# block.
|
|
410
|
+
def self.configure_warden! #:nodoc:
|
|
411
|
+
@@warden_configured ||= begin
|
|
412
|
+
warden_config.failure_app = Devise::Delegator.new
|
|
413
|
+
warden_config.default_scope = Devise.default_scope
|
|
414
|
+
warden_config.intercept_401 = false
|
|
415
|
+
|
|
416
|
+
Devise.mappings.each_value do |mapping|
|
|
417
|
+
warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
@@warden_config_block.try :call, Devise.warden_config
|
|
421
|
+
true
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
# Generate a friendly string randomically to be used as token.
|
|
426
|
+
def self.friendly_token
|
|
427
|
+
SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
# constant-time comparison algorithm to prevent timing attacks
|
|
431
|
+
def self.secure_compare(a, b)
|
|
432
|
+
return false if a.blank? || b.blank? || a.bytesize != b.bytesize
|
|
433
|
+
l = a.unpack "C#{a.bytesize}"
|
|
434
|
+
|
|
435
|
+
res = 0
|
|
436
|
+
b.each_byte { |byte| res |= byte ^ l.shift }
|
|
437
|
+
res == 0
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
require 'warden'
|
|
442
|
+
require 'devise/mapping'
|
|
443
|
+
require 'devise/models'
|
|
444
|
+
require 'devise/modules'
|
|
445
|
+
require 'devise/rails'
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'rails/generators/active_record'
|
|
3
|
+
require 'generators/devise/orm_helpers'
|
|
4
|
+
|
|
5
|
+
module ActiveRecord
|
|
6
|
+
module Generators
|
|
7
|
+
class DeviseGenerator < ActiveRecord::Generators::Base
|
|
8
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
|
9
|
+
|
|
10
|
+
include Devise::Generators::OrmHelpers
|
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
12
|
+
|
|
13
|
+
def copy_devise_migration
|
|
14
|
+
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
|
15
|
+
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}"
|
|
16
|
+
else
|
|
17
|
+
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def generate_model
|
|
22
|
+
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def inject_devise_content
|
|
26
|
+
content = model_contents + <<CONTENT
|
|
27
|
+
# Setup accessible (or protected) attributes for your model
|
|
28
|
+
attr_accessible :email, :password, :password_confirmation, :remember_me
|
|
29
|
+
CONTENT
|
|
30
|
+
|
|
31
|
+
class_path = if namespaced?
|
|
32
|
+
class_name.to_s.split("::")
|
|
33
|
+
else
|
|
34
|
+
[class_name]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
indent_depth = class_path.size - 1
|
|
38
|
+
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
|
|
39
|
+
|
|
40
|
+
inject_into_class(model_path, class_path.last, content) if model_exists?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def migration_data
|
|
44
|
+
<<RUBY
|
|
45
|
+
## Database authenticatable
|
|
46
|
+
t.string :email, :null => false, :default => ""
|
|
47
|
+
t.string :encrypted_password, :null => false, :default => ""
|
|
48
|
+
|
|
49
|
+
## Recoverable
|
|
50
|
+
t.string :reset_password_token
|
|
51
|
+
t.datetime :reset_password_sent_at
|
|
52
|
+
|
|
53
|
+
## Rememberable
|
|
54
|
+
t.datetime :remember_created_at
|
|
55
|
+
|
|
56
|
+
## Trackable
|
|
57
|
+
t.integer :sign_in_count, :default => 0
|
|
58
|
+
t.datetime :current_sign_in_at
|
|
59
|
+
t.datetime :last_sign_in_at
|
|
60
|
+
t.string :current_sign_in_ip
|
|
61
|
+
t.string :last_sign_in_ip
|
|
62
|
+
|
|
63
|
+
## Confirmable
|
|
64
|
+
# t.string :confirmation_token
|
|
65
|
+
# t.datetime :confirmed_at
|
|
66
|
+
# t.datetime :confirmation_sent_at
|
|
67
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
|
68
|
+
|
|
69
|
+
## Lockable
|
|
70
|
+
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
|
|
71
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
|
72
|
+
# t.datetime :locked_at
|
|
73
|
+
|
|
74
|
+
## Token authenticatable
|
|
75
|
+
# t.string :authentication_token
|
|
76
|
+
RUBY
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
3
|
+
def change
|
|
4
|
+
create_table(:<%= table_name %>) do |t|
|
|
5
|
+
<%= migration_data -%>
|
|
6
|
+
|
|
7
|
+
<% attributes.each do |attribute| -%>
|
|
8
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
|
9
|
+
<% end -%>
|
|
10
|
+
|
|
11
|
+
t.timestamps
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
add_index :<%= table_name %>, :email, :unique => true
|
|
15
|
+
add_index :<%= table_name %>, :reset_password_token, :unique => true
|
|
16
|
+
# add_index :<%= table_name %>, :confirmation_token, :unique => true
|
|
17
|
+
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
|
18
|
+
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
3
|
+
def self.up
|
|
4
|
+
change_table(:<%= table_name %>) do |t|
|
|
5
|
+
<%= migration_data -%>
|
|
6
|
+
|
|
7
|
+
<% attributes.each do |attribute| -%>
|
|
8
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
|
9
|
+
<% end -%>
|
|
10
|
+
|
|
11
|
+
# Uncomment below if timestamps were not included in your original model.
|
|
12
|
+
# t.timestamps
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
add_index :<%= table_name %>, :email, :unique => true
|
|
16
|
+
add_index :<%= table_name %>, :reset_password_token, :unique => true
|
|
17
|
+
# add_index :<%= table_name %>, :confirmation_token, :unique => true
|
|
18
|
+
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
|
19
|
+
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.down
|
|
23
|
+
# By default, we don't want to make any assumption about how to roll back a migration when your
|
|
24
|
+
# model already existed. Please edit below which fields you would like to remove in this migration.
|
|
25
|
+
raise ActiveRecord::IrreversibleMigration
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module Devise
|
|
3
|
+
module Generators
|
|
4
|
+
class DeviseGenerator < Rails::Generators::NamedBase
|
|
5
|
+
include Rails::Generators::ResourceHelpers
|
|
6
|
+
|
|
7
|
+
namespace "devise"
|
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
9
|
+
|
|
10
|
+
desc "Generates a model with the given NAME (if one does not exist) with devise " <<
|
|
11
|
+
"configuration plus a migration file and devise routes."
|
|
12
|
+
|
|
13
|
+
hook_for :orm
|
|
14
|
+
|
|
15
|
+
class_option :routes, :desc => "Generate routes", :type => :boolean, :default => true
|
|
16
|
+
|
|
17
|
+
def add_devise_routes
|
|
18
|
+
devise_route = "devise_for :#{plural_name}"
|
|
19
|
+
devise_route << %Q(, :class_name => "#{class_name}") if class_name.include?("::")
|
|
20
|
+
devise_route << %Q(, :skip => :all) unless options.routes?
|
|
21
|
+
route devise_route
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'securerandom'
|
|
3
|
+
|
|
4
|
+
module Devise
|
|
5
|
+
module Generators
|
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
|
7
|
+
source_root File.expand_path("../../templates", __FILE__)
|
|
8
|
+
|
|
9
|
+
desc "Creates a Devise initializer and copy locale files to your application."
|
|
10
|
+
class_option :orm
|
|
11
|
+
|
|
12
|
+
def copy_initializer
|
|
13
|
+
template "devise.rb", "config/initializers/devise.rb"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def copy_locale
|
|
17
|
+
copy_file "../../../config/locales/en.yml", "config/locales/devise.en.yml"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def show_readme
|
|
21
|
+
readme "README" if behavior == :invoke
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module Devise
|
|
3
|
+
module Generators
|
|
4
|
+
module OrmHelpers
|
|
5
|
+
def model_contents
|
|
6
|
+
<<-CONTENT
|
|
7
|
+
# Include default devise modules. Others available are:
|
|
8
|
+
# :token_authenticatable, :confirmable,
|
|
9
|
+
# :lockable, :timeoutable and :omniauthable
|
|
10
|
+
devise :database_authenticatable, :registerable,
|
|
11
|
+
:recoverable, :rememberable, :trackable, :validatable
|
|
12
|
+
|
|
13
|
+
CONTENT
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def model_exists?
|
|
17
|
+
File.exists?(File.join(destination_root, model_path))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def migration_exists?(table_name)
|
|
21
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def migration_path
|
|
25
|
+
@migration_path ||= File.join("db", "migrate")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def model_path
|
|
29
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|