devise 1.0.11 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +59 -13
- data/Gemfile +23 -0
- data/Gemfile.lock +118 -0
- data/README.rdoc +116 -77
- data/Rakefile +4 -2
- data/TODO +3 -2
- data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +1 -1
- data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +1 -1
- data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +12 -8
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +1 -8
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +71 -0
- data/app/views/devise/confirmations/new.html.erb +12 -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 +19 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/{lib/devise → config}/locales/en.yml +16 -12
- data/lib/devise/controllers/helpers.rb +57 -52
- data/lib/devise/controllers/internal_helpers.rb +19 -50
- data/lib/devise/controllers/scoped_views.rb +35 -0
- data/lib/devise/controllers/url_helpers.rb +1 -1
- data/lib/devise/encryptors/authlogic_sha512.rb +0 -2
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/bcrypt.rb +2 -4
- data/lib/devise/encryptors/clearance_sha1.rb +0 -2
- data/lib/devise/encryptors/sha1.rb +6 -8
- data/lib/devise/encryptors/sha512.rb +6 -8
- data/lib/devise/failure_app.rb +76 -41
- data/lib/devise/hooks/activatable.rb +6 -10
- data/lib/devise/hooks/forgetable.rb +11 -0
- data/lib/devise/hooks/rememberable.rb +40 -30
- data/lib/devise/hooks/timeoutable.rb +7 -3
- data/lib/devise/hooks/trackable.rb +5 -14
- data/lib/devise/mapping.rb +35 -62
- data/lib/devise/models/authenticatable.rb +126 -0
- data/lib/devise/models/confirmable.rb +19 -22
- data/lib/devise/models/database_authenticatable.rb +26 -60
- data/lib/devise/models/lockable.rb +43 -28
- data/lib/devise/models/recoverable.rb +11 -10
- data/lib/devise/models/rememberable.rb +56 -26
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +14 -43
- data/lib/devise/models/trackable.rb +14 -0
- data/lib/devise/models/validatable.rb +16 -2
- data/lib/devise/models.rb +16 -53
- data/lib/devise/modules.rb +23 -0
- data/lib/devise/orm/active_record.rb +10 -15
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails/routes.rb +232 -117
- data/lib/devise/rails/warden_compat.rb +17 -41
- data/lib/devise/rails.rb +64 -9
- data/lib/devise/schema.rb +47 -23
- data/lib/devise/strategies/authenticatable.rb +123 -0
- data/lib/devise/strategies/base.rb +2 -3
- data/lib/devise/strategies/database_authenticatable.rb +7 -22
- data/lib/devise/strategies/rememberable.rb +21 -7
- data/lib/devise/strategies/token_authenticatable.rb +31 -19
- data/lib/devise/test_helpers.rb +6 -6
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +174 -157
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/{generators/devise → lib/generators/active_record}/templates/migration.rb +9 -3
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +23 -0
- data/{generators/devise_install → lib/generators/devise}/templates/README +9 -7
- data/lib/generators/devise/templates/devise.rb +142 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/devise_install_generator.rb +4 -0
- data/lib/generators/devise_views_generator.rb +4 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/test/controllers/helpers_test.rb +48 -19
- data/test/controllers/internal_helpers_test.rb +12 -16
- data/test/controllers/url_helpers_test.rb +21 -10
- data/test/devise_test.rb +16 -25
- data/test/encryptors_test.rb +2 -3
- data/test/failure_app_test.rb +106 -27
- data/test/integration/authenticatable_test.rb +135 -131
- data/test/integration/confirmable_test.rb +22 -15
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +9 -12
- data/test/integration/lockable_test.rb +22 -15
- data/test/integration/recoverable_test.rb +6 -6
- data/test/integration/registerable_test.rb +42 -33
- data/test/integration/rememberable_test.rb +84 -22
- data/test/integration/timeoutable_test.rb +16 -4
- data/test/integration/token_authenticatable_test.rb +45 -12
- data/test/integration/trackable_test.rb +1 -1
- data/test/mailers/confirmation_instructions_test.rb +11 -17
- data/test/mailers/reset_password_instructions_test.rb +7 -7
- data/test/mailers/unlock_instructions_test.rb +7 -7
- data/test/mapping_test.rb +22 -95
- data/test/models/confirmable_test.rb +12 -19
- data/test/models/{authenticatable_test.rb → database_authenticatable_test.rb} +24 -56
- data/test/models/lockable_test.rb +32 -46
- data/test/models/recoverable_test.rb +7 -7
- data/test/models/rememberable_test.rb +118 -35
- data/test/models/timeoutable_test.rb +1 -1
- data/test/models/token_authenticatable_test.rb +5 -19
- data/test/models/trackable_test.rb +1 -1
- data/test/models/validatable_test.rb +20 -27
- data/test/models_test.rb +12 -5
- data/test/orm/active_record.rb +1 -23
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +1 -5
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +3 -3
- data/test/rails_app/app/controllers/application_controller.rb +2 -5
- data/test/rails_app/app/controllers/home_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/users_controller.rb +7 -5
- data/test/rails_app/app/mongoid/admin.rb +6 -0
- data/test/rails_app/app/mongoid/shim.rb +16 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/config/application.rb +35 -0
- data/test/rails_app/config/boot.rb +10 -107
- data/test/rails_app/config/environment.rb +4 -41
- data/test/rails_app/config/environments/development.rb +15 -13
- data/test/rails_app/config/environments/production.rb +25 -20
- data/test/rails_app/config/environments/test.rb +33 -28
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +95 -38
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +47 -25
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
- data/test/rails_app/db/schema.rb +86 -0
- data/test/routes_test.rb +62 -47
- data/test/support/{assertions_helper.rb → assertions.rb} +2 -15
- data/test/support/{tests_helper.rb → helpers.rb} +18 -3
- data/test/support/{integration_tests_helper.rb → integration.rb} +24 -7
- data/test/support/webrat/integrations/rails.rb +32 -0
- data/test/test_helper.rb +11 -11
- data/test/test_helpers_test.rb +30 -15
- metadata +107 -66
- data/app/controllers/sessions_controller.rb +0 -42
- data/app/models/devise_mailer.rb +0 -68
- data/app/views/confirmations/new.html.erb +0 -12
- data/app/views/passwords/edit.html.erb +0 -16
- data/app/views/passwords/new.html.erb +0 -12
- data/app/views/registrations/edit.html.erb +0 -25
- data/app/views/registrations/new.html.erb +0 -17
- data/app/views/sessions/new.html.erb +0 -17
- data/app/views/shared/_devise_links.erb +0 -19
- data/app/views/unlocks/new.html.erb +0 -12
- data/generators/devise/USAGE +0 -5
- data/generators/devise/devise_generator.rb +0 -15
- data/generators/devise/lib/route_devise.rb +0 -32
- data/generators/devise/templates/model.rb +0 -9
- data/generators/devise_install/USAGE +0 -3
- data/generators/devise_install/devise_install_generator.rb +0 -15
- data/generators/devise_install/templates/devise.rb +0 -105
- data/generators/devise_views/USAGE +0 -3
- data/generators/devise_views/devise_views_generator.rb +0 -21
- data/lib/devise/models/activatable.rb +0 -16
- data/lib/devise/models/http_authenticatable.rb +0 -23
- data/lib/devise/orm/data_mapper.rb +0 -83
- data/lib/devise/orm/mongo_mapper.rb +0 -52
- data/lib/devise/strategies/http_authenticatable.rb +0 -59
- data/rails/init.rb +0 -2
- data/test/integration/rack_middleware_test.rb +0 -47
- data/test/orm/mongo_mapper.rb +0 -20
- data/test/rails_app/app/mongo_mapper/admin.rb +0 -13
- data/test/rails_app/app/mongo_mapper/user.rb +0 -14
- data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
- data/test/rails_app/config/initializers/session_store.rb +0 -15
- /data/app/views/{devise_mailer → devise/mailer}/confirmation_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/reset_password_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/unlock_instructions.html.erb +0 -0
|
@@ -1,12 +0,0 @@
|
|
|
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" %>
|
data/generators/devise/USAGE
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
class <%= class_name %> < ActiveRecord::Base
|
|
2
|
-
# Include default devise modules. Others available are:
|
|
3
|
-
# :http_authenticatable, :token_authenticatable, :confirmable, :lockable, :timeoutable and :activatable
|
|
4
|
-
devise :registerable, :database_authenticatable, :recoverable,
|
|
5
|
-
:rememberable, :trackable, :validatable
|
|
6
|
-
|
|
7
|
-
# Setup accessible (or protected) attributes for your model
|
|
8
|
-
attr_accessible :email, :password, :password_confirmation
|
|
9
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1,105 +0,0 @@
|
|
|
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
|
-
# Configure the content type of DeviseMailer mails (defaults to text/html")
|
|
8
|
-
# config.mailer_content_type = "text/plain"
|
|
9
|
-
|
|
10
|
-
# ==> Configuration for :authenticatable
|
|
11
|
-
# Invoke `rake secret` and use the printed value to setup a pepper to generate
|
|
12
|
-
# the encrypted password. By default no pepper is used.
|
|
13
|
-
# config.pepper = "rake secret output"
|
|
14
|
-
|
|
15
|
-
# Configure how many times you want the password is reencrypted. Default is 10.
|
|
16
|
-
# config.stretches = 10
|
|
17
|
-
|
|
18
|
-
# Define which will be the encryption algorithm. Supported algorithms are :sha1
|
|
19
|
-
# (default), :sha512 and :bcrypt. Devise also supports encryptors from others
|
|
20
|
-
# authentication tools as :clearance_sha1, :authlogic_sha512 (then you should set
|
|
21
|
-
# stretches above to 20 for default behavior) and :restful_authentication_sha1
|
|
22
|
-
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
|
|
23
|
-
# config.encryptor = :sha1
|
|
24
|
-
|
|
25
|
-
# Configure which keys are used when authenticating an user. By default is
|
|
26
|
-
# just :email. You can configure it to use [:username, :subdomain], so for
|
|
27
|
-
# authenticating an user, both parameters are required. Remember that those
|
|
28
|
-
# parameters are used only when authenticating and not when retrieving from
|
|
29
|
-
# session. If you need permissions, you should implement that in a before filter.
|
|
30
|
-
# config.authentication_keys = [ :email ]
|
|
31
|
-
|
|
32
|
-
# The realm used in Http Basic Authentication
|
|
33
|
-
# config.http_authentication_realm = "Application"
|
|
34
|
-
|
|
35
|
-
# ==> Configuration for :confirmable
|
|
36
|
-
# The time you want give to your user to confirm his account. During this time
|
|
37
|
-
# he will be able to access your application without confirming. Default is nil.
|
|
38
|
-
# config.confirm_within = 2.days
|
|
39
|
-
|
|
40
|
-
# ==> Configuration for :rememberable
|
|
41
|
-
# The time the user will be remembered without asking for credentials again.
|
|
42
|
-
# config.remember_for = 2.weeks
|
|
43
|
-
|
|
44
|
-
# ==> Configuration for :timeoutable
|
|
45
|
-
# The time you want to timeout the user session without activity. After this
|
|
46
|
-
# time the user will be asked for credentials again.
|
|
47
|
-
# config.timeout_in = 10.minutes
|
|
48
|
-
|
|
49
|
-
# ==> Configuration for :lockable
|
|
50
|
-
# Number of authentication tries before locking an account.
|
|
51
|
-
# config.maximum_attempts = 20
|
|
52
|
-
|
|
53
|
-
# Defines which strategy will be used to unlock an account.
|
|
54
|
-
# :email = Sends an unlock link to the user email
|
|
55
|
-
# :time = Reanables login after a certain ammount of time (see :unlock_in below)
|
|
56
|
-
# :both = enables both strategies
|
|
57
|
-
# config.unlock_strategy = :both
|
|
58
|
-
|
|
59
|
-
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
|
60
|
-
# config.unlock_in = 1.hour
|
|
61
|
-
|
|
62
|
-
# ==> Configuration for :token_authenticatable
|
|
63
|
-
# Defines name of the authentication token params key
|
|
64
|
-
# config.token_authentication_key = :auth_token
|
|
65
|
-
|
|
66
|
-
# ==> General configuration
|
|
67
|
-
# Load and configure the ORM. Supports :active_record (default), :mongo_mapper
|
|
68
|
-
# (requires mongo_ext installed) and :data_mapper (experimental).
|
|
69
|
-
# require 'devise/orm/mongo_mapper'
|
|
70
|
-
# config.orm = :mongo_mapper
|
|
71
|
-
|
|
72
|
-
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
|
73
|
-
# "sessions/users/new". It's turned off by default because it's slower if you
|
|
74
|
-
# are using only default views.
|
|
75
|
-
# config.scoped_views = true
|
|
76
|
-
|
|
77
|
-
# By default, devise detects the role accessed based on the url. So whenever
|
|
78
|
-
# accessing "/users/sign_in", it knows you are accessing an User. This makes
|
|
79
|
-
# routes as "/sign_in" not possible, unless you tell Devise to use the default
|
|
80
|
-
# scope, setting true below.
|
|
81
|
-
# config.use_default_scope = true
|
|
82
|
-
|
|
83
|
-
# Configure the default scope used by Devise. By default it's the first devise
|
|
84
|
-
# role declared in your routes.
|
|
85
|
-
# config.default_scope = :user
|
|
86
|
-
|
|
87
|
-
# If you want to use other strategies, that are not (yet) supported by Devise,
|
|
88
|
-
# you can configure them inside the config.warden block. The example below
|
|
89
|
-
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
|
90
|
-
#
|
|
91
|
-
# config.warden do |manager|
|
|
92
|
-
# manager.oauth(:twitter) do |twitter|
|
|
93
|
-
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
|
|
94
|
-
# twitter.consumer_key = <YOUR CONSUMER KEY>
|
|
95
|
-
# twitter.options :site => 'http://twitter.com'
|
|
96
|
-
# end
|
|
97
|
-
# manager.default_strategies.unshift :twitter_oauth
|
|
98
|
-
# end
|
|
99
|
-
|
|
100
|
-
# Configure default_url_options if you are using dynamic segments in :path_prefix
|
|
101
|
-
# for devise_for.
|
|
102
|
-
# config.default_url_options do
|
|
103
|
-
# { :locale => I18n.locale }
|
|
104
|
-
# end
|
|
105
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require 'devise/hooks/activatable'
|
|
2
|
-
|
|
3
|
-
module Devise
|
|
4
|
-
module Models
|
|
5
|
-
# This module implements the default API required in activatable hook.
|
|
6
|
-
module Activatable
|
|
7
|
-
def active?
|
|
8
|
-
true
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def inactive_message
|
|
12
|
-
:inactive
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require 'devise/strategies/http_authenticatable'
|
|
2
|
-
|
|
3
|
-
module Devise
|
|
4
|
-
module Models
|
|
5
|
-
# Adds HttpAuthenticatable behavior to your model. It expects that your
|
|
6
|
-
# model class responds to authenticate method
|
|
7
|
-
# (which for example is defined in authenticatable).
|
|
8
|
-
module HttpAuthenticatable
|
|
9
|
-
def self.included(base)
|
|
10
|
-
base.extend ClassMethods
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
module ClassMethods
|
|
14
|
-
Devise::Models.config(self, :authentication_keys)
|
|
15
|
-
|
|
16
|
-
# Authenticate an user using http.
|
|
17
|
-
def authenticate_with_http(username, password)
|
|
18
|
-
authenticate(authentication_keys.first => username, :password => password)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
module Devise
|
|
2
|
-
module Orm
|
|
3
|
-
module DataMapper
|
|
4
|
-
module InstanceMethods
|
|
5
|
-
def save(flag=nil)
|
|
6
|
-
if flag == false
|
|
7
|
-
save!
|
|
8
|
-
else
|
|
9
|
-
super()
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def self.included_modules_hook(klass)
|
|
15
|
-
klass.send :extend, self
|
|
16
|
-
klass.send :include, InstanceMethods
|
|
17
|
-
|
|
18
|
-
yield
|
|
19
|
-
|
|
20
|
-
klass.devise_modules.each do |mod|
|
|
21
|
-
klass.send(mod) if klass.respond_to?(mod)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
include Devise::Schema
|
|
26
|
-
|
|
27
|
-
SCHEMA_OPTIONS = {
|
|
28
|
-
:null => :nullable,
|
|
29
|
-
:limit => :length
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
# Hooks for confirmable
|
|
33
|
-
def before_create(*args)
|
|
34
|
-
wrap_hook(:before, *args)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def after_create(*args)
|
|
38
|
-
wrap_hook(:after, *args)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def wrap_hook(action, *args)
|
|
42
|
-
options = args.extract_options!
|
|
43
|
-
|
|
44
|
-
args.each do |callback|
|
|
45
|
-
send action, :create, callback
|
|
46
|
-
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
|
47
|
-
def #{callback}
|
|
48
|
-
super if #{options[:if] || true}
|
|
49
|
-
end
|
|
50
|
-
METHOD
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Add ActiveRecord like finder
|
|
55
|
-
def find(*args)
|
|
56
|
-
options = args.extract_options!
|
|
57
|
-
case args.first
|
|
58
|
-
when :first
|
|
59
|
-
first(options)
|
|
60
|
-
when :all
|
|
61
|
-
all(options)
|
|
62
|
-
else
|
|
63
|
-
get(*args)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Tell how to apply schema methods. This automatically maps :limit to
|
|
68
|
-
# :length and :null to :nullable.
|
|
69
|
-
def apply_schema(name, type, options={})
|
|
70
|
-
return unless Devise.apply_schema
|
|
71
|
-
|
|
72
|
-
SCHEMA_OPTIONS.each do |old_key, new_key|
|
|
73
|
-
next unless options.key?(old_key)
|
|
74
|
-
options[new_key] = options.delete(old_key)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
property name, type, options
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
DataMapper::Model.send(:include, Devise::Models)
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
module Devise
|
|
2
|
-
module Orm
|
|
3
|
-
module MongoMapper
|
|
4
|
-
module InstanceMethods
|
|
5
|
-
def save(options={})
|
|
6
|
-
if options == false
|
|
7
|
-
super(:validate => false)
|
|
8
|
-
else
|
|
9
|
-
super
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def self.included_modules_hook(klass)
|
|
15
|
-
klass.send :extend, self
|
|
16
|
-
klass.send :include, InstanceMethods
|
|
17
|
-
yield
|
|
18
|
-
|
|
19
|
-
klass.devise_modules.each do |mod|
|
|
20
|
-
klass.send(mod) if klass.respond_to?(mod)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def find(*args)
|
|
25
|
-
case args.first
|
|
26
|
-
when :first, :all
|
|
27
|
-
send(args.shift, *args)
|
|
28
|
-
else
|
|
29
|
-
super
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
include Devise::Schema
|
|
34
|
-
|
|
35
|
-
# Tell how to apply schema methods. This automatically converts DateTime
|
|
36
|
-
# to Time, since MongoMapper does not recognize the former.
|
|
37
|
-
def apply_schema(name, type, options={})
|
|
38
|
-
return unless Devise.apply_schema
|
|
39
|
-
type = Time if type == DateTime
|
|
40
|
-
key name, type, options
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
if MongoMapper::Version >= "0.8.0"
|
|
47
|
-
MongoMapper::Plugins::Document::ClassMethods.send(:include, Devise::Models)
|
|
48
|
-
MongoMapper::Plugins::EmbeddedDocument::ClassMethods.send(:include, Devise::Models)
|
|
49
|
-
else
|
|
50
|
-
MongoMapper::Document::ClassMethods.send(:include, Devise::Models)
|
|
51
|
-
MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Devise::Models)
|
|
52
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require 'devise/strategies/base'
|
|
2
|
-
|
|
3
|
-
module Devise
|
|
4
|
-
module Strategies
|
|
5
|
-
# Sign in an user using HTTP authentication.
|
|
6
|
-
class HttpAuthenticatable < Base
|
|
7
|
-
def valid?
|
|
8
|
-
http_authentication? && mapping.to.respond_to?(:authenticate_with_http)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def authenticate!
|
|
12
|
-
username, password = username_and_password
|
|
13
|
-
|
|
14
|
-
if resource = mapping.to.authenticate_with_http(username, password)
|
|
15
|
-
success!(resource)
|
|
16
|
-
else
|
|
17
|
-
custom!([401, custom_headers, [response_body]])
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
def username_and_password
|
|
24
|
-
decode_credentials(request).split(/:/, 2)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def response_body
|
|
28
|
-
body = "HTTP Basic: Access denied."
|
|
29
|
-
method = :"to_#{request_format.to_sym}"
|
|
30
|
-
{}.respond_to?(method) ? { :error => body }.send(method) : body
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def http_authentication
|
|
34
|
-
request.env['HTTP_AUTHORIZATION'] ||
|
|
35
|
-
request.env['X-HTTP_AUTHORIZATION'] ||
|
|
36
|
-
request.env['X_HTTP_AUTHORIZATION'] ||
|
|
37
|
-
request.env['REDIRECT_X_HTTP_AUTHORIZATION']
|
|
38
|
-
end
|
|
39
|
-
alias :http_authentication? :http_authentication
|
|
40
|
-
|
|
41
|
-
def decode_credentials(request)
|
|
42
|
-
ActiveSupport::Base64.decode64(http_authentication.split(' ', 2).last || '')
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def custom_headers
|
|
46
|
-
{
|
|
47
|
-
"Content-Type" => request_format.to_s,
|
|
48
|
-
"WWW-Authenticate" => %(Basic realm="#{Devise.http_authentication_realm.gsub(/"/, "")}")
|
|
49
|
-
}
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def request_format
|
|
53
|
-
@request_format ||= Mime::Type.lookup_by_extension(request.template_format.to_s)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
Warden::Strategies.add(:http_authenticatable, Devise::Strategies::HttpAuthenticatable)
|
data/rails/init.rb
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
require "test/test_helper"
|
|
2
|
-
require "rack/test"
|
|
3
|
-
|
|
4
|
-
class RackMiddlewareTest < Test::Unit::TestCase
|
|
5
|
-
include Rack::Test::Methods
|
|
6
|
-
|
|
7
|
-
def app
|
|
8
|
-
ActionController::Dispatcher.new
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def warden
|
|
12
|
-
last_request.env['warden']
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def with_custom_strategy
|
|
16
|
-
get '/'
|
|
17
|
-
|
|
18
|
-
Warden::Strategies.add(:custom_test) do
|
|
19
|
-
def valid?
|
|
20
|
-
true
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def authenticate!
|
|
24
|
-
custom! [599, {
|
|
25
|
-
"X-Custom-Response" => "Custom response test",
|
|
26
|
-
"Content-type" => "text/plain"
|
|
27
|
-
}, "Custom response test"]
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
#ActionController::Dispatcher.middleware.use CustomStrategyInterceptor
|
|
32
|
-
default_strategies = warden.manager.config.default_strategies
|
|
33
|
-
warden.manager.config.default_strategies :custom_test
|
|
34
|
-
yield
|
|
35
|
-
warden.manager.config.default_strategies default_strategies
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_custom_strategy_response
|
|
39
|
-
with_custom_strategy do
|
|
40
|
-
post('/users/sign_in')
|
|
41
|
-
|
|
42
|
-
assert_equal 599, last_response.status
|
|
43
|
-
assert_equal "Custom response test", last_response.body
|
|
44
|
-
assert_equal "Custom response test", last_response.headers["X-Custom-Response"]
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
data/test/orm/mongo_mapper.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
require 'mongo_mapper'
|
|
2
|
-
MongoMapper.database = "devise-test-suite"
|
|
3
|
-
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
|
|
4
|
-
|
|
5
|
-
require File.join(File.dirname(__FILE__), '..', 'rails_app', 'config', 'environment')
|
|
6
|
-
require 'test_help'
|
|
7
|
-
|
|
8
|
-
module MongoMapper::Document
|
|
9
|
-
# TODO This should not be required
|
|
10
|
-
def invalid?
|
|
11
|
-
!valid?
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
class ActiveSupport::TestCase
|
|
16
|
-
setup do
|
|
17
|
-
User.delete_all
|
|
18
|
-
Admin.delete_all
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class Admin
|
|
2
|
-
include MongoMapper::Document
|
|
3
|
-
devise :authenticatable, :registerable, :timeoutable
|
|
4
|
-
|
|
5
|
-
def self.find_for_authentication(conditions)
|
|
6
|
-
last(:conditions => conditions)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def self.last(options={})
|
|
10
|
-
options.merge!(:order => 'email')
|
|
11
|
-
super options
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class User
|
|
2
|
-
include MongoMapper::Document
|
|
3
|
-
key :created_at, DateTime
|
|
4
|
-
devise :authenticatable, :http_authenticatable, :confirmable, :lockable, :recoverable,
|
|
5
|
-
:registerable, :rememberable, :timeoutable, :token_authenticatable,
|
|
6
|
-
:trackable, :validatable
|
|
7
|
-
# attr_accessible :username, :email, :password, :password_confirmation
|
|
8
|
-
|
|
9
|
-
def self.last(options={})
|
|
10
|
-
options.merge!(:order => 'email')
|
|
11
|
-
super options
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
|
2
|
-
|
|
3
|
-
# These settings change the behavior of Rails 2 apps and will be defaults
|
|
4
|
-
# for Rails 3. You can remove this initializer when Rails 3 is released.
|
|
5
|
-
|
|
6
|
-
if defined?(ActiveRecord)
|
|
7
|
-
# Include Active Record class name as root for JSON serialized output.
|
|
8
|
-
ActiveRecord::Base.include_root_in_json = true
|
|
9
|
-
|
|
10
|
-
# Store the full class name (including module namespace) in STI type column.
|
|
11
|
-
ActiveRecord::Base.store_full_sti_class = true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
ActionController::Routing.generate_best_match = false
|
|
15
|
-
|
|
16
|
-
# Use ISO 8601 format for JSON serialized times and dates.
|
|
17
|
-
ActiveSupport.use_standard_json_time_format = true
|
|
18
|
-
|
|
19
|
-
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
|
20
|
-
# if you're including raw json in an HTML page.
|
|
21
|
-
ActiveSupport.escape_html_entities_in_json = false
|
|
22
|
-
|
|
23
|
-
# Clean up silencers
|
|
24
|
-
Rails.backtrace_cleaner.remove_silencers!
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
|
2
|
-
|
|
3
|
-
# Your secret key for verifying cookie session data integrity.
|
|
4
|
-
# If you change this key, all old sessions will become invalid!
|
|
5
|
-
# Make sure the secret is at least 30 characters and all random,
|
|
6
|
-
# no regular words or you'll be exposed to dictionary attacks.
|
|
7
|
-
ActionController::Base.session = {
|
|
8
|
-
:key => '_rails_app_session',
|
|
9
|
-
:secret => '89e8147901a0d7c221ac130e0ded3eeab6dab4a97127255909f08fedaae371918b41dec9d4d75c5b27a55c3772d43c2b6a3cbac232c5cc2ce4b8ec22242f5e60'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
# Use the database for sessions instead of the cookie-based default,
|
|
13
|
-
# which shouldn't be used to store highly confidential information
|
|
14
|
-
# (create the session table with "rake db:sessions:create")
|
|
15
|
-
# ActionController::Base.session_store = :active_record_store
|
|
File without changes
|
|
File without changes
|
|
File without changes
|