mongoid-devise 1.0.1
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/CHANGELOG.rdoc +333 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +260 -0
- data/Rakefile +53 -0
- data/TODO +2 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +42 -0
- data/app/controllers/registrations_controller.rb +55 -0
- data/app/controllers/sessions_controller.rb +45 -0
- data/app/controllers/unlocks_controller.rb +33 -0
- data/app/models/devise_mailer.rb +68 -0
- data/app/views/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/passwords/edit.html.erb +16 -0
- data/app/views/passwords/new.html.erb +12 -0
- data/app/views/registrations/edit.html.erb +25 -0
- data/app/views/registrations/new.html.erb +17 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/app/views/shared/_devise_links.erb +19 -0
- data/app/views/unlocks/new.html.erb +12 -0
- data/generators/devise/USAGE +5 -0
- data/generators/devise/devise_generator.rb +15 -0
- data/generators/devise/lib/route_devise.rb +32 -0
- data/generators/devise/templates/migration.rb +23 -0
- data/generators/devise/templates/model.rb +9 -0
- data/generators/devise_install/USAGE +3 -0
- data/generators/devise_install/devise_install_generator.rb +15 -0
- data/generators/devise_install/templates/README +18 -0
- data/generators/devise_install/templates/devise.rb +102 -0
- data/generators/devise_views/USAGE +3 -0
- data/generators/devise_views/devise_views_generator.rb +21 -0
- data/init.rb +2 -0
- data/lib/devise.rb +253 -0
- data/lib/devise/controllers/helpers.rb +200 -0
- data/lib/devise/controllers/internal_helpers.rb +129 -0
- data/lib/devise/controllers/url_helpers.rb +41 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/bcrypt.rb +21 -0
- data/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +27 -0
- data/lib/devise/encryptors/sha512.rb +27 -0
- data/lib/devise/failure_app.rb +65 -0
- data/lib/devise/hooks/activatable.rb +15 -0
- data/lib/devise/hooks/rememberable.rb +30 -0
- data/lib/devise/hooks/timeoutable.rb +18 -0
- data/lib/devise/hooks/trackable.rb +18 -0
- data/lib/devise/locales/en.yml +35 -0
- data/lib/devise/mapping.rb +131 -0
- data/lib/devise/models.rb +112 -0
- data/lib/devise/models/activatable.rb +16 -0
- data/lib/devise/models/authenticatable.rb +146 -0
- data/lib/devise/models/confirmable.rb +172 -0
- data/lib/devise/models/http_authenticatable.rb +21 -0
- data/lib/devise/models/lockable.rb +160 -0
- data/lib/devise/models/recoverable.rb +80 -0
- data/lib/devise/models/registerable.rb +8 -0
- data/lib/devise/models/rememberable.rb +94 -0
- data/lib/devise/models/timeoutable.rb +28 -0
- data/lib/devise/models/token_authenticatable.rb +89 -0
- data/lib/devise/models/trackable.rb +16 -0
- data/lib/devise/models/validatable.rb +48 -0
- data/lib/devise/orm/active_record.rb +41 -0
- data/lib/devise/orm/data_mapper.rb +83 -0
- data/lib/devise/orm/mongo_mapper.rb +51 -0
- data/lib/devise/orm/mongoid.rb +60 -0
- data/lib/devise/rails.rb +14 -0
- data/lib/devise/rails/routes.rb +125 -0
- data/lib/devise/rails/warden_compat.rb +25 -0
- data/lib/devise/schema.rb +65 -0
- data/lib/devise/strategies/authenticatable.rb +36 -0
- data/lib/devise/strategies/base.rb +16 -0
- data/lib/devise/strategies/http_authenticatable.rb +49 -0
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/lib/devise/test_helpers.rb +86 -0
- data/lib/devise/version.rb +3 -0
- data/test/controllers/helpers_test.rb +177 -0
- data/test/controllers/internal_helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +69 -0
- data/test/encryptors_test.rb +31 -0
- data/test/failure_app_test.rb +44 -0
- data/test/integration/authenticatable_test.rb +271 -0
- data/test/integration/confirmable_test.rb +97 -0
- data/test/integration/http_authenticatable_test.rb +44 -0
- data/test/integration/lockable_test.rb +83 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +130 -0
- data/test/integration/rememberable_test.rb +63 -0
- data/test/integration/timeoutable_test.rb +68 -0
- data/test/integration/token_authenticatable_test.rb +55 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +80 -0
- data/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/mapping_test.rb +153 -0
- data/test/models/authenticatable_test.rb +180 -0
- data/test/models/confirmable_test.rb +228 -0
- data/test/models/lockable_test.rb +202 -0
- data/test/models/recoverable_test.rb +138 -0
- data/test/models/rememberable_test.rb +135 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +51 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +106 -0
- data/test/models_test.rb +56 -0
- data/test/orm/active_record.rb +31 -0
- data/test/orm/mongo_mapper.rb +20 -0
- data/test/orm/mongoid.rb +22 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
- data/test/rails_app/app/mongo_mapper/user.rb +8 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/user.rb +8 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/devise.rb +79 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +21 -0
- data/test/routes_test.rb +110 -0
- data/test/support/assertions_helper.rb +37 -0
- data/test/support/integration_tests_helper.rb +71 -0
- data/test/support/test_silencer.rb +5 -0
- data/test/support/tests_helper.rb +39 -0
- data/test/test_helper.rb +21 -0
- data/test/test_helpers_test.rb +57 -0
- metadata +216 -0
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
<%= render :partial => "shared/devise_links" %>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<%- if controller_name != 'sessions' %>
|
|
2
|
+
<%= link_to t('devise.sessions.link'), new_session_path(resource_name) %><br />
|
|
3
|
+
<% end -%>
|
|
4
|
+
|
|
5
|
+
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
|
|
6
|
+
<%= link_to t('devise.registrations.link'), new_registration_path(resource_name) %><br />
|
|
7
|
+
<% end -%>
|
|
8
|
+
|
|
9
|
+
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
|
|
10
|
+
<%= link_to t('devise.passwords.link'), new_password_path(resource_name) %><br />
|
|
11
|
+
<% end -%>
|
|
12
|
+
|
|
13
|
+
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
|
|
14
|
+
<%= link_to t('devise.confirmations.link'), new_confirmation_path(resource_name) %><br />
|
|
15
|
+
<% end -%>
|
|
16
|
+
|
|
17
|
+
<%- if devise_mapping.lockable? && controller_name != 'unlocks' %>
|
|
18
|
+
<%= link_to t('devise.unlocks.link'), new_unlock_path(resource_name) %><br />
|
|
19
|
+
<% end -%>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<h2>Resend unlock instructions</h2>
|
|
2
|
+
|
|
3
|
+
<% form_for resource_name, resource, :url => unlock_path(resource_name) do |f| %>
|
|
4
|
+
<%= f.error_messages %>
|
|
5
|
+
|
|
6
|
+
<p><%= f.label :email %></p>
|
|
7
|
+
<p><%= f.text_field :email %></p>
|
|
8
|
+
|
|
9
|
+
<p><%= f.submit "Resend unlock instructions" %></p>
|
|
10
|
+
<% end %>
|
|
11
|
+
|
|
12
|
+
<%= render :partial => "shared/devise_links" %>
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
m.directory(File.join('app', 'models', class_path))
|
|
8
|
+
m.template 'model.rb', File.join('app', 'models', "#{file_path}.rb")
|
|
9
|
+
|
|
10
|
+
m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "devise_create_#{table_name}"
|
|
11
|
+
m.route_devise table_name
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
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,23 @@
|
|
|
1
|
+
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
|
4
|
+
t.authenticatable :encryptor => :sha1, :null => false
|
|
5
|
+
t.confirmable
|
|
6
|
+
t.recoverable
|
|
7
|
+
t.rememberable
|
|
8
|
+
t.trackable
|
|
9
|
+
# t.lockable
|
|
10
|
+
|
|
11
|
+
t.timestamps
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
add_index :<%= table_name %>, :email, :unique => true
|
|
15
|
+
add_index :<%= table_name %>, :confirmation_token, :unique => true
|
|
16
|
+
add_index :<%= table_name %>, :reset_password_token, :unique => true
|
|
17
|
+
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.down
|
|
21
|
+
drop_table :<%= table_name %>
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class <%= class_name %> < ActiveRecord::Base
|
|
2
|
+
# Include default devise modules. Others available are:
|
|
3
|
+
# :http_authenticatable, :token_authenticatable, :lockable, :timeoutable and :activatable
|
|
4
|
+
devise :registerable, :authenticatable, :confirmable, :recoverable,
|
|
5
|
+
:rememberable, :trackable, :validatable
|
|
6
|
+
|
|
7
|
+
# Setup accessible (or protected) attributes for your model
|
|
8
|
+
attr_accessible :email, :password, :password_confirmation
|
|
9
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class DeviseInstallGenerator < Rails::Generator::Base
|
|
2
|
+
|
|
3
|
+
def manifest
|
|
4
|
+
record do |m|
|
|
5
|
+
m.directory "config/initializers"
|
|
6
|
+
m.template "devise.rb", "config/initializers/devise.rb"
|
|
7
|
+
|
|
8
|
+
m.directory "config/locales"
|
|
9
|
+
m.file "../../../lib/devise/locales/en.yml", "config/locales/devise.en.yml"
|
|
10
|
+
|
|
11
|
+
m.readme "README"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
===============================================================================
|
|
3
|
+
|
|
4
|
+
Some setup you must do manually if you haven't yet:
|
|
5
|
+
|
|
6
|
+
1. Setup default url options for your specific environment. Here is an
|
|
7
|
+
example of development environment:
|
|
8
|
+
|
|
9
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
|
10
|
+
|
|
11
|
+
This is a required Rails configuration. In production is must be the
|
|
12
|
+
actual host of your application
|
|
13
|
+
|
|
14
|
+
2. Ensure you have defined root_url to *something* in your config/routes.rb:
|
|
15
|
+
|
|
16
|
+
map.root :controller => 'home'
|
|
17
|
+
|
|
18
|
+
===============================================================================
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
# Configure the e-mail address which will be shown in DeviseMailer.
|
|
5
|
+
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
|
6
|
+
|
|
7
|
+
# ==> Configuration for :authenticatable
|
|
8
|
+
# Invoke `rake secret` and use the printed value to setup a pepper to generate
|
|
9
|
+
# the encrypted password. By default no pepper is used.
|
|
10
|
+
# config.pepper = "rake secret output"
|
|
11
|
+
|
|
12
|
+
# Configure how many times you want the password is reencrypted. Default is 10.
|
|
13
|
+
# config.stretches = 10
|
|
14
|
+
|
|
15
|
+
# Define which will be the encryption algorithm. Supported algorithms are :sha1
|
|
16
|
+
# (default), :sha512 and :bcrypt. Devise also supports encryptors from others
|
|
17
|
+
# authentication tools as :clearance_sha1, :authlogic_sha512 (then you should set
|
|
18
|
+
# stretches above to 20 for default behavior) and :restful_authentication_sha1
|
|
19
|
+
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
|
|
20
|
+
# config.encryptor = :sha1
|
|
21
|
+
|
|
22
|
+
# Configure which keys are used when authenticating an user. By default is
|
|
23
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
|
24
|
+
# authenticating an user, both parameters are required. Remember that those
|
|
25
|
+
# parameters are used only when authenticating and not when retrieving from
|
|
26
|
+
# session. If you need permissions, you should implement that in a before filter.
|
|
27
|
+
# config.authentication_keys = [ :email ]
|
|
28
|
+
|
|
29
|
+
# The realm used in Http Basic Authentication
|
|
30
|
+
# config.http_authentication_realm = "Application"
|
|
31
|
+
|
|
32
|
+
# ==> Configuration for :confirmable
|
|
33
|
+
# The time you want give to your user to confirm his account. During this time
|
|
34
|
+
# he will be able to access your application without confirming. Default is nil.
|
|
35
|
+
# config.confirm_within = 2.days
|
|
36
|
+
|
|
37
|
+
# ==> Configuration for :rememberable
|
|
38
|
+
# The time the user will be remembered without asking for credentials again.
|
|
39
|
+
# config.remember_for = 2.weeks
|
|
40
|
+
|
|
41
|
+
# ==> Configuration for :timeoutable
|
|
42
|
+
# The time you want to timeout the user session without activity. After this
|
|
43
|
+
# time the user will be asked for credentials again.
|
|
44
|
+
# config.timeout_in = 10.minutes
|
|
45
|
+
|
|
46
|
+
# ==> Configuration for :lockable
|
|
47
|
+
# Number of authentication tries before locking an account.
|
|
48
|
+
# config.maximum_attempts = 20
|
|
49
|
+
|
|
50
|
+
# Defines which strategy will be used to unlock an account.
|
|
51
|
+
# :email = Sends an unlock link to the user email
|
|
52
|
+
# :time = Reanables login after a certain ammount of time (see :unlock_in below)
|
|
53
|
+
# :both = enables both strategies
|
|
54
|
+
# config.unlock_strategy = :both
|
|
55
|
+
|
|
56
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
|
57
|
+
# config.unlock_in = 1.hour
|
|
58
|
+
|
|
59
|
+
# ==> Configuration for :token_authenticatable
|
|
60
|
+
# Defines name of the authentication token params key
|
|
61
|
+
# config.token_authentication_key = :auth_token
|
|
62
|
+
|
|
63
|
+
# ==> General configuration
|
|
64
|
+
# Load and configure the ORM. Supports :active_record (default), :mongo_mapper
|
|
65
|
+
# (requires mongo_ext installed) and :data_mapper (experimental).
|
|
66
|
+
# require 'devise/orm/mongo_mapper'
|
|
67
|
+
# config.orm = :mongo_mapper
|
|
68
|
+
|
|
69
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
|
70
|
+
# "sessions/users/new". It's turned off by default because it's slower if you
|
|
71
|
+
# are using only default views.
|
|
72
|
+
# config.scoped_views = true
|
|
73
|
+
|
|
74
|
+
# By default, devise detects the role accessed based on the url. So whenever
|
|
75
|
+
# accessing "/users/sign_in", it knows you are accessing an User. This makes
|
|
76
|
+
# routes as "/sign_in" not possible, unless you tell Devise to use the default
|
|
77
|
+
# scope, setting true below.
|
|
78
|
+
# config.use_default_scope = true
|
|
79
|
+
|
|
80
|
+
# Configure the default scope used by Devise. By default it's the first devise
|
|
81
|
+
# role declared in your routes.
|
|
82
|
+
# config.default_scope = :user
|
|
83
|
+
|
|
84
|
+
# If you want to use other strategies, that are not (yet) supported by Devise,
|
|
85
|
+
# you can configure them inside the config.warden block. The example below
|
|
86
|
+
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
|
87
|
+
#
|
|
88
|
+
# config.warden do |manager|
|
|
89
|
+
# manager.oauth(:twitter) do |twitter|
|
|
90
|
+
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
|
|
91
|
+
# twitter.consumer_key = <YOUR CONSUMER KEY>
|
|
92
|
+
# twitter.options :site => 'http://twitter.com'
|
|
93
|
+
# end
|
|
94
|
+
# manager.default_strategies.unshift :twitter_oauth
|
|
95
|
+
# end
|
|
96
|
+
|
|
97
|
+
# Configure default_url_options if you are using dynamic segments in :path_prefix
|
|
98
|
+
# for devise_for.
|
|
99
|
+
# config.default_url_options do
|
|
100
|
+
# { :locale => I18n.locale }
|
|
101
|
+
# end
|
|
102
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
data/init.rb
ADDED
data/lib/devise.rb
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
autoload :FailureApp, 'devise/failure_app'
|
|
3
|
+
autoload :Schema, 'devise/schema'
|
|
4
|
+
autoload :TestHelpers, 'devise/test_helpers'
|
|
5
|
+
|
|
6
|
+
module Controllers
|
|
7
|
+
autoload :Helpers, 'devise/controllers/helpers'
|
|
8
|
+
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
|
9
|
+
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module Encryptors
|
|
13
|
+
autoload :Base, 'devise/encryptors/base'
|
|
14
|
+
autoload :Bcrypt, 'devise/encryptors/bcrypt'
|
|
15
|
+
autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
|
|
16
|
+
autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
|
|
17
|
+
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
|
|
18
|
+
autoload :Sha512, 'devise/encryptors/sha512'
|
|
19
|
+
autoload :Sha1, 'devise/encryptors/sha1'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module Orm
|
|
23
|
+
autoload :ActiveRecord, 'devise/orm/active_record'
|
|
24
|
+
autoload :DataMapper, 'devise/orm/data_mapper'
|
|
25
|
+
autoload :MongoMapper, 'devise/orm/mongo_mapper'
|
|
26
|
+
autoload :Mongoid, 'devise/orm/mongoid'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
ALL = []
|
|
30
|
+
|
|
31
|
+
# Authentication ones first
|
|
32
|
+
ALL.push :authenticatable, :http_authenticatable, :token_authenticatable, :rememberable
|
|
33
|
+
|
|
34
|
+
# Misc after
|
|
35
|
+
ALL.push :recoverable, :registerable, :validatable
|
|
36
|
+
|
|
37
|
+
# The ones which can sign out after
|
|
38
|
+
ALL.push :activatable, :confirmable, :lockable, :timeoutable
|
|
39
|
+
|
|
40
|
+
# Stats for last, so we make sure the user is really signed in
|
|
41
|
+
ALL.push :trackable
|
|
42
|
+
|
|
43
|
+
# Maps controller names to devise modules.
|
|
44
|
+
CONTROLLERS = {
|
|
45
|
+
:sessions => [:authenticatable, :token_authenticatable],
|
|
46
|
+
:passwords => [:recoverable],
|
|
47
|
+
:confirmations => [:confirmable],
|
|
48
|
+
:registrations => [:registerable],
|
|
49
|
+
:unlocks => [:lockable]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Routes for generating url helpers.
|
|
53
|
+
ROUTES = [:session, :password, :confirmation, :registration, :unlock]
|
|
54
|
+
|
|
55
|
+
STRATEGIES = [:rememberable, :http_authenticatable, :token_authenticatable, :authenticatable]
|
|
56
|
+
|
|
57
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
|
58
|
+
|
|
59
|
+
# Maps the messages types that are used in flash message.
|
|
60
|
+
FLASH_MESSAGES = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
|
|
61
|
+
|
|
62
|
+
# Declare encryptors length which are used in migrations.
|
|
63
|
+
ENCRYPTORS_LENGTH = {
|
|
64
|
+
:sha1 => 40,
|
|
65
|
+
:sha512 => 128,
|
|
66
|
+
:clearance_sha1 => 40,
|
|
67
|
+
:restful_authentication_sha1 => 40,
|
|
68
|
+
:authlogic_sha512 => 128,
|
|
69
|
+
:bcrypt => 60
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# Email regex used to validate email formats. Adapted from authlogic.
|
|
73
|
+
EMAIL_REGEX = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
|
74
|
+
|
|
75
|
+
# Used to encrypt password. Please generate one with rake secret.
|
|
76
|
+
mattr_accessor :pepper
|
|
77
|
+
@@pepper = nil
|
|
78
|
+
|
|
79
|
+
# The number of times to encrypt password.
|
|
80
|
+
mattr_accessor :stretches
|
|
81
|
+
@@stretches = 10
|
|
82
|
+
|
|
83
|
+
# Keys used when authenticating an user.
|
|
84
|
+
mattr_accessor :authentication_keys
|
|
85
|
+
@@authentication_keys = [ :email ]
|
|
86
|
+
|
|
87
|
+
# Time interval where the remember me token is valid.
|
|
88
|
+
mattr_accessor :remember_for
|
|
89
|
+
@@remember_for = 2.weeks
|
|
90
|
+
|
|
91
|
+
# Time interval you can access your account before confirming your account.
|
|
92
|
+
mattr_accessor :confirm_within
|
|
93
|
+
@@confirm_within = 0.days
|
|
94
|
+
|
|
95
|
+
# Time interval to timeout the user session without activity.
|
|
96
|
+
mattr_accessor :timeout_in
|
|
97
|
+
@@timeout_in = 30.minutes
|
|
98
|
+
|
|
99
|
+
# Used to define the password encryption algorithm.
|
|
100
|
+
mattr_accessor :encryptor
|
|
101
|
+
@@encryptor = :sha1
|
|
102
|
+
|
|
103
|
+
# Store scopes mappings.
|
|
104
|
+
mattr_accessor :mappings
|
|
105
|
+
@@mappings = ActiveSupport::OrderedHash.new
|
|
106
|
+
|
|
107
|
+
# Stores the chosen ORM.
|
|
108
|
+
mattr_accessor :orm
|
|
109
|
+
@@orm = :active_record
|
|
110
|
+
|
|
111
|
+
# TODO Remove
|
|
112
|
+
mattr_accessor :all
|
|
113
|
+
@@all = []
|
|
114
|
+
|
|
115
|
+
# Tells if devise should apply the schema in ORMs where devise declaration
|
|
116
|
+
# and schema belongs to the same class (as Datamapper and MongoMapper).
|
|
117
|
+
mattr_accessor :apply_schema
|
|
118
|
+
@@apply_schema = true
|
|
119
|
+
|
|
120
|
+
# Scoped views. Since it relies on fallbacks to render default views, it's
|
|
121
|
+
# turned off by default.
|
|
122
|
+
mattr_accessor :scoped_views
|
|
123
|
+
@@scoped_views = false
|
|
124
|
+
|
|
125
|
+
# Number of authentication tries before locking an account
|
|
126
|
+
mattr_accessor :maximum_attempts
|
|
127
|
+
@@maximum_attempts = 20
|
|
128
|
+
|
|
129
|
+
# Defines which strategy can be used to unlock an account.
|
|
130
|
+
# Values: :email, :time, :both
|
|
131
|
+
mattr_accessor :unlock_strategy
|
|
132
|
+
@@unlock_strategy = :both
|
|
133
|
+
|
|
134
|
+
# Time interval to unlock the account if :time is defined as unlock_strategy.
|
|
135
|
+
mattr_accessor :unlock_in
|
|
136
|
+
@@unlock_in = 1.hour
|
|
137
|
+
|
|
138
|
+
# Tell when to use the default scope, if one cannot be found from routes.
|
|
139
|
+
mattr_accessor :use_default_scope
|
|
140
|
+
@@use_default_scope = false
|
|
141
|
+
|
|
142
|
+
# The default scope which is used by warden.
|
|
143
|
+
mattr_accessor :default_scope
|
|
144
|
+
@@default_scope = nil
|
|
145
|
+
|
|
146
|
+
# Address which sends Devise e-mails.
|
|
147
|
+
mattr_accessor :mailer_sender
|
|
148
|
+
@@mailer_sender = nil
|
|
149
|
+
|
|
150
|
+
# Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
|
|
151
|
+
mattr_accessor :token_authentication_key
|
|
152
|
+
@@token_authentication_key = :auth_token
|
|
153
|
+
|
|
154
|
+
# The realm used in Http Basic Authentication
|
|
155
|
+
mattr_accessor :http_authentication_realm
|
|
156
|
+
@@http_authentication_realm = "Application"
|
|
157
|
+
|
|
158
|
+
class << self
|
|
159
|
+
# Default way to setup Devise. Run script/generate devise_install to create
|
|
160
|
+
# a fresh initializer with all configuration values.
|
|
161
|
+
def setup
|
|
162
|
+
yield self
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Sets warden configuration using a block that will be invoked on warden
|
|
166
|
+
# initialization.
|
|
167
|
+
#
|
|
168
|
+
# Devise.initialize do |config|
|
|
169
|
+
# config.confirm_within = 2.days
|
|
170
|
+
#
|
|
171
|
+
# config.warden do |manager|
|
|
172
|
+
# # Configure warden to use other strategies, like oauth.
|
|
173
|
+
# manager.oauth(:twitter)
|
|
174
|
+
# end
|
|
175
|
+
# end
|
|
176
|
+
def warden(&block)
|
|
177
|
+
@warden_config = block
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Configure default url options to be used within Devise and ActionController.
|
|
181
|
+
def default_url_options(&block)
|
|
182
|
+
Devise::Mapping.metaclass.send :define_method, :default_url_options, &block
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# A method used internally to setup warden manager from the Rails initialize
|
|
186
|
+
# block.
|
|
187
|
+
def configure_warden(config) #:nodoc:
|
|
188
|
+
config.default_strategies *Devise::STRATEGIES
|
|
189
|
+
config.failure_app = Devise::FailureApp
|
|
190
|
+
config.silence_missing_strategies!
|
|
191
|
+
config.default_scope = Devise.default_scope
|
|
192
|
+
|
|
193
|
+
# If the user provided a warden hook, call it now.
|
|
194
|
+
@warden_config.try :call, config
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# The class of the configured ORM
|
|
198
|
+
def orm_class
|
|
199
|
+
Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Generate a friendly string randomically to be used as token.
|
|
203
|
+
def friendly_token
|
|
204
|
+
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Make Devise aware of an 3rd party Devise-module. For convenience.
|
|
208
|
+
#
|
|
209
|
+
# == Options:
|
|
210
|
+
#
|
|
211
|
+
# +strategy+ - Boolean value representing if this module got a custom *strategy*.
|
|
212
|
+
# Default is +false+. Note: Devise will auto-detect this in such case if this is true.
|
|
213
|
+
# +model+ - String representing a load path to a custom *model* for this module (to autoload).
|
|
214
|
+
# Default is +nil+ (i.e. +false+).
|
|
215
|
+
# +controller+ - Symbol representing a name of an exisiting or custom *controller* for this module.
|
|
216
|
+
# Default is +nil+ (i.e. +false+).
|
|
217
|
+
#
|
|
218
|
+
# == Examples:
|
|
219
|
+
#
|
|
220
|
+
# Devise.add_module(:party_module)
|
|
221
|
+
# Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
|
|
222
|
+
# Devise.add_module(:party_module, :model => 'party_module/model')
|
|
223
|
+
#
|
|
224
|
+
def add_module(module_name, options = {})
|
|
225
|
+
Devise::ALL.unshift module_name unless Devise::ALL.include?(module_name)
|
|
226
|
+
Devise::STRATEGIES.unshift module_name if options[:strategy] && !Devise::STRATEGIES.include?(module_name)
|
|
227
|
+
|
|
228
|
+
if options[:controller]
|
|
229
|
+
controller = options[:controller].to_sym
|
|
230
|
+
Devise::CONTROLLERS[controller] ||= []
|
|
231
|
+
Devise::CONTROLLERS[controller].unshift module_name unless Devise::CONTROLLERS[controller].include?(module_name)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
if options[:model]
|
|
235
|
+
Devise::Models.module_eval do
|
|
236
|
+
autoload :"#{module_name.to_s.classify}", options[:model]
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
Devise::Mapping.register module_name
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
begin
|
|
246
|
+
require 'warden'
|
|
247
|
+
rescue
|
|
248
|
+
gem 'warden'
|
|
249
|
+
require 'warden'
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
require 'devise/mapping'
|
|
253
|
+
require 'devise/rails'
|