devise-edge 1.2.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +500 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +335 -0
- data/app/controllers/devise/confirmations_controller.rb +33 -0
- data/app/controllers/devise/oauth_callbacks_controller.rb +4 -0
- data/app/controllers/devise/passwords_controller.rb +41 -0
- data/app/controllers/devise/registrations_controller.rb +75 -0
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +88 -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 +42 -0
- data/lib/devise.rb +371 -0
- data/lib/devise/controllers/helpers.rb +261 -0
- data/lib/devise/controllers/internal_helpers.rb +113 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/url_helpers.rb +39 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/clearance_sha1.rb +17 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +25 -0
- data/lib/devise/encryptors/sha512.rb +25 -0
- data/lib/devise/failure_app.rb +126 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +12 -0
- data/lib/devise/hooks/rememberable.rb +45 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mapping.rb +105 -0
- data/lib/devise/models.rb +66 -0
- data/lib/devise/models/authenticatable.rb +143 -0
- data/lib/devise/models/confirmable.rb +160 -0
- data/lib/devise/models/database_authenticatable.rb +94 -0
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +168 -0
- data/lib/devise/models/oauthable.rb +49 -0
- data/lib/devise/models/recoverable.rb +83 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +122 -0
- data/lib/devise/models/timeoutable.rb +33 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +60 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/oauth.rb +41 -0
- data/lib/devise/oauth/config.rb +33 -0
- data/lib/devise/oauth/helpers.rb +18 -0
- data/lib/devise/oauth/internal_helpers.rb +182 -0
- data/lib/devise/oauth/test_helpers.rb +29 -0
- data/lib/devise/oauth/url_helpers.rb +35 -0
- data/lib/devise/orm/active_record.rb +36 -0
- data/lib/devise/orm/mongo_mapper.rb +46 -0
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails.rb +67 -0
- data/lib/devise/rails/routes.rb +260 -0
- data/lib/devise/rails/warden_compat.rb +42 -0
- data/lib/devise/schema.rb +96 -0
- data/lib/devise/strategies/authenticatable.rb +150 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +51 -0
- data/lib/devise/strategies/token_authenticatable.rb +53 -0
- data/lib/devise/test_helpers.rb +100 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +30 -0
- 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 +24 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/lib/generators/templates/README +25 -0
- data/lib/generators/templates/devise.rb +168 -0
- data/test/controllers/helpers_test.rb +220 -0
- data/test/controllers/internal_helpers_test.rb +56 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/devise_test.rb +65 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +148 -0
- data/test/integration/authenticatable_test.rb +424 -0
- data/test/integration/confirmable_test.rb +104 -0
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +64 -0
- data/test/integration/lockable_test.rb +109 -0
- data/test/integration/oauthable_test.rb +258 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +179 -0
- data/test/integration/rememberable_test.rb +179 -0
- data/test/integration/timeoutable_test.rb +80 -0
- data/test/integration/token_authenticatable_test.rb +99 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +84 -0
- data/test/mailers/reset_password_instructions_test.rb +72 -0
- data/test/mailers/unlock_instructions_test.rb +66 -0
- data/test/mapping_test.rb +95 -0
- data/test/models/confirmable_test.rb +221 -0
- data/test/models/database_authenticatable_test.rb +82 -0
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +204 -0
- data/test/models/oauthable_test.rb +21 -0
- data/test/models/recoverable_test.rb +155 -0
- data/test/models/rememberable_test.rb +271 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +37 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +77 -0
- data/test/oauth/config_test.rb +44 -0
- data/test/oauth/url_helpers_test.rb +47 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +12 -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/users_controller.rb +18 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -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 +13 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +172 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +54 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +48 -0
- data/test/routes_test.rb +189 -0
- data/test/support/assertions.rb +24 -0
- data/test/support/helpers.rb +60 -0
- data/test/support/integration.rb +88 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +23 -0
- data/test/test_helpers_test.rb +101 -0
- metadata +335 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
class Devise::SessionsController < ApplicationController
|
2
|
+
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
|
3
|
+
include Devise::Controllers::InternalHelpers
|
4
|
+
|
5
|
+
# GET /resource/sign_in
|
6
|
+
def new
|
7
|
+
clean_up_passwords(build_resource)
|
8
|
+
render_with_scope :new
|
9
|
+
end
|
10
|
+
|
11
|
+
# POST /resource/sign_in
|
12
|
+
def create
|
13
|
+
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
|
14
|
+
set_flash_message :notice, :signed_in
|
15
|
+
sign_in_and_redirect(resource_name, resource)
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /resource/sign_out
|
19
|
+
def destroy
|
20
|
+
set_flash_message :notice, :signed_out if signed_in?(resource_name)
|
21
|
+
sign_out_and_redirect(resource_name)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Devise::UnlocksController < ApplicationController
|
2
|
+
prepend_before_filter :require_no_authentication
|
3
|
+
include Devise::Controllers::InternalHelpers
|
4
|
+
|
5
|
+
# GET /resource/unlock/new
|
6
|
+
def new
|
7
|
+
build_resource({})
|
8
|
+
render_with_scope :new
|
9
|
+
end
|
10
|
+
|
11
|
+
# POST /resource/unlock
|
12
|
+
def create
|
13
|
+
self.resource = resource_class.send_unlock_instructions(params[resource_name])
|
14
|
+
|
15
|
+
if resource.errors.empty?
|
16
|
+
set_flash_message :notice, :send_instructions
|
17
|
+
redirect_to new_session_path(resource_name)
|
18
|
+
else
|
19
|
+
render_with_scope :new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# GET /resource/unlock?unlock_token=abcdef
|
24
|
+
def show
|
25
|
+
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
|
26
|
+
|
27
|
+
if resource.errors.empty?
|
28
|
+
set_flash_message :notice, :unlocked
|
29
|
+
sign_in_and_redirect(resource_name, resource)
|
30
|
+
else
|
31
|
+
render_with_scope :new
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DeviseHelper
|
2
|
+
def devise_error_messages!
|
3
|
+
return "" if resource.errors.empty?
|
4
|
+
|
5
|
+
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
|
6
|
+
sentence = "#{pluralize(resource.errors.count, "error")} prohibited this #{resource_name} from being saved:"
|
7
|
+
|
8
|
+
html = <<-HTML
|
9
|
+
<div id="error_explanation">
|
10
|
+
<h2>#{sentence}</h2>
|
11
|
+
<ul>#{messages}</ul>
|
12
|
+
</div>
|
13
|
+
HTML
|
14
|
+
|
15
|
+
html.html_safe
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
class Devise::Mailer < ::ActionMailer::Base
|
2
|
+
include Devise::Controllers::ScopedViews
|
3
|
+
attr_reader :scope_name, :resource
|
4
|
+
|
5
|
+
def confirmation_instructions(record)
|
6
|
+
setup_mail(record, :confirmation_instructions)
|
7
|
+
end
|
8
|
+
|
9
|
+
def reset_password_instructions(record)
|
10
|
+
setup_mail(record, :reset_password_instructions)
|
11
|
+
end
|
12
|
+
|
13
|
+
def unlock_instructions(record)
|
14
|
+
setup_mail(record, :unlock_instructions)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Configure default email options
|
20
|
+
def setup_mail(record, action)
|
21
|
+
initialize_from_record(record)
|
22
|
+
mail headers_for(action)
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize_from_record(record)
|
26
|
+
@scope_name = Devise::Mapping.find_scope!(record)
|
27
|
+
@resource = instance_variable_set("@#{devise_mapping.name}", record)
|
28
|
+
end
|
29
|
+
|
30
|
+
def devise_mapping
|
31
|
+
@devise_mapping ||= Devise.mappings[scope_name]
|
32
|
+
end
|
33
|
+
|
34
|
+
def headers_for(action)
|
35
|
+
headers = {
|
36
|
+
:subject => translate(devise_mapping, action),
|
37
|
+
:from => mailer_sender(devise_mapping),
|
38
|
+
:to => resource.email,
|
39
|
+
:template_path => template_paths
|
40
|
+
}
|
41
|
+
|
42
|
+
if resource.respond_to?(:headers_for)
|
43
|
+
headers.merge!(resource.headers_for(action))
|
44
|
+
end
|
45
|
+
|
46
|
+
unless headers.key?(:reply_to)
|
47
|
+
headers[:reply_to] = headers[:from]
|
48
|
+
end
|
49
|
+
|
50
|
+
headers
|
51
|
+
end
|
52
|
+
|
53
|
+
def mailer_sender(mapping)
|
54
|
+
if Devise.mailer_sender.is_a?(Proc)
|
55
|
+
Devise.mailer_sender.call(mapping.name)
|
56
|
+
else
|
57
|
+
Devise.mailer_sender
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def template_paths
|
62
|
+
template_path = [self.class.mailer_name]
|
63
|
+
template_path.unshift "#{@devise_mapping.plural}/mailer" if self.class.scoped_views?
|
64
|
+
template_path
|
65
|
+
end
|
66
|
+
|
67
|
+
# Setup a subject doing an I18n lookup. At first, it attemps to set a subject
|
68
|
+
# based on the current mapping:
|
69
|
+
#
|
70
|
+
# en:
|
71
|
+
# devise:
|
72
|
+
# mailer:
|
73
|
+
# confirmation_instructions:
|
74
|
+
# user_subject: '...'
|
75
|
+
#
|
76
|
+
# If one does not exist, it fallbacks to ActionMailer default:
|
77
|
+
#
|
78
|
+
# en:
|
79
|
+
# devise:
|
80
|
+
# mailer:
|
81
|
+
# confirmation_instructions:
|
82
|
+
# subject: '...'
|
83
|
+
#
|
84
|
+
def translate(mapping, key)
|
85
|
+
I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
|
86
|
+
:default => [:subject, key.to_s.humanize])
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2>Resend confirmation instructions</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %><br />
|
7
|
+
<%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.submit "Resend confirmation instructions" %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= render :partial => "devise/shared/links" %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<p>Hello <%= @resource.email %>!</p>
|
2
|
+
|
3
|
+
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
|
4
|
+
|
5
|
+
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
|
6
|
+
|
7
|
+
<p>If you didn't request this, please ignore this email.</p>
|
8
|
+
<p>Your password won't change until you access the link above and create a new one.</p>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<p>Hello <%= @resource.email %>!</p>
|
2
|
+
|
3
|
+
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
|
4
|
+
|
5
|
+
<p>Click the link below to unlock your account:</p>
|
6
|
+
|
7
|
+
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<h2>Change your password</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
<%= f.hidden_field :reset_password_token %>
|
6
|
+
|
7
|
+
<p><%= f.label :password %><br />
|
8
|
+
<%= f.password_field :password %></p>
|
9
|
+
|
10
|
+
<p><%= f.label :password_confirmation %><br />
|
11
|
+
<%= f.password_field :password_confirmation %></p>
|
12
|
+
|
13
|
+
<p><%= f.submit "Change my password" %></p>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<%= render :partial => "devise/shared/links" %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2>Forgot your password?</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %><br />
|
7
|
+
<%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.submit "Send me reset password instructions" %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= render :partial => "devise/shared/links" %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %><br />
|
7
|
+
<%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
10
|
+
<%= f.password_field :password %></p>
|
11
|
+
|
12
|
+
<p><%= f.label :password_confirmation %><br />
|
13
|
+
<%= f.password_field :password_confirmation %></p>
|
14
|
+
|
15
|
+
<p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
16
|
+
<%= f.password_field :current_password %></p>
|
17
|
+
|
18
|
+
<p><%= f.submit "Update" %></p>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<h3>Cancel my account</h3>
|
22
|
+
|
23
|
+
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
|
24
|
+
|
25
|
+
<%= link_to "Back", :back %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<h2>Sign up</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %><br />
|
7
|
+
<%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.label :password %><br />
|
10
|
+
<%= f.password_field :password %></p>
|
11
|
+
|
12
|
+
<p><%= f.label :password_confirmation %><br />
|
13
|
+
<%= f.password_field :password_confirmation %></p>
|
14
|
+
|
15
|
+
<p><%= f.submit "Sign up" %></p>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<%= render :partial => "devise/shared/links" %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<h2>Sign in</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
4
|
+
<p><%= f.label :email %><br />
|
5
|
+
<%= f.text_field :email %></p>
|
6
|
+
|
7
|
+
<p><%= f.label :password %><br />
|
8
|
+
<%= 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 => "devise/shared/links" %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%- if controller_name != 'sessions' %>
|
2
|
+
<%= link_to "Sign in", new_session_path(resource_name) %><br />
|
3
|
+
<% end -%>
|
4
|
+
|
5
|
+
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
|
6
|
+
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
|
10
|
+
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
|
11
|
+
<% end -%>
|
12
|
+
|
13
|
+
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
|
14
|
+
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
|
15
|
+
<% end -%>
|
16
|
+
|
17
|
+
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
|
18
|
+
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
|
19
|
+
<% end -%>
|
20
|
+
|
21
|
+
<%- if devise_mapping.oauthable? %>
|
22
|
+
<%- resource_class.oauth_providers.each do |provider| %>
|
23
|
+
<%= link_to "Sign in with #{provider.to_s.titleize}", oauth_authorize_url(resource_name, provider) %><br />
|
24
|
+
<% end =%>
|
25
|
+
<% end -%>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2>Resend unlock instructions</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %><br />
|
7
|
+
<%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.submit "Resend unlock instructions" %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= render :partial => "devise/shared/links" %>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
en:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
not_found: "not found"
|
5
|
+
already_confirmed: "was already confirmed"
|
6
|
+
not_locked: "was not locked"
|
7
|
+
|
8
|
+
devise:
|
9
|
+
failure:
|
10
|
+
unauthenticated: 'You need to sign in or sign up before continuing.'
|
11
|
+
unconfirmed: 'You have to confirm your account before continuing.'
|
12
|
+
locked: 'Your account is locked.'
|
13
|
+
invalid: 'Invalid email or password.'
|
14
|
+
invalid_token: 'Invalid authentication token.'
|
15
|
+
timeout: 'Your session expired, please sign in again to continue.'
|
16
|
+
inactive: 'Your account was not activated yet.'
|
17
|
+
sessions:
|
18
|
+
signed_in: 'Signed in successfully.'
|
19
|
+
signed_out: 'Signed out successfully.'
|
20
|
+
passwords:
|
21
|
+
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
22
|
+
updated: 'Your password was changed successfully. You are now signed in.'
|
23
|
+
confirmations:
|
24
|
+
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
|
25
|
+
confirmed: 'Your account was successfully confirmed. You are now signed in.'
|
26
|
+
registrations:
|
27
|
+
signed_up: 'You have signed up successfully. If enabled, a confirmation was sent to your e-mail.'
|
28
|
+
updated: 'You updated your account successfully.'
|
29
|
+
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
30
|
+
unlocks:
|
31
|
+
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
|
32
|
+
unlocked: 'Your account was successfully unlocked. You are now signed in.'
|
33
|
+
oauth_callbacks:
|
34
|
+
success: 'Successfully authorized from %{kind} account.'
|
35
|
+
failure: 'Could not authorize you from %{kind} because "%{reason}".'
|
36
|
+
mailer:
|
37
|
+
confirmation_instructions:
|
38
|
+
subject: 'Confirmation instructions'
|
39
|
+
reset_password_instructions:
|
40
|
+
subject: 'Reset password instructions'
|
41
|
+
unlock_instructions:
|
42
|
+
subject: 'Unlock Instructions'
|
data/lib/devise.rb
ADDED
@@ -0,0 +1,371 @@
|
|
1
|
+
require 'active_support/core_ext/numeric/time'
|
2
|
+
require 'active_support/dependencies'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module Devise
|
6
|
+
autoload :FailureApp, 'devise/failure_app'
|
7
|
+
autoload :Oauth, 'devise/oauth'
|
8
|
+
autoload :PathChecker, 'devise/path_checker'
|
9
|
+
autoload :Schema, 'devise/schema'
|
10
|
+
autoload :TestHelpers, 'devise/test_helpers'
|
11
|
+
|
12
|
+
module Controllers
|
13
|
+
autoload :Helpers, 'devise/controllers/helpers'
|
14
|
+
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
15
|
+
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
16
|
+
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
17
|
+
end
|
18
|
+
|
19
|
+
module Encryptors
|
20
|
+
autoload :Base, 'devise/encryptors/base'
|
21
|
+
autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
|
22
|
+
autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
|
23
|
+
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
|
24
|
+
autoload :Sha512, 'devise/encryptors/sha512'
|
25
|
+
autoload :Sha1, 'devise/encryptors/sha1'
|
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
|
+
# True values used to check params
|
42
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
43
|
+
|
44
|
+
# Declare encryptors length which are used in migrations.
|
45
|
+
ENCRYPTORS_LENGTH = {
|
46
|
+
:sha1 => 40,
|
47
|
+
:sha512 => 128,
|
48
|
+
:clearance_sha1 => 40,
|
49
|
+
:restful_authentication_sha1 => 40,
|
50
|
+
:authlogic_sha512 => 128
|
51
|
+
}
|
52
|
+
|
53
|
+
# Custom domain for cookies. Not set by default
|
54
|
+
mattr_accessor :cookie_options
|
55
|
+
@@cookie_options = {}
|
56
|
+
|
57
|
+
# The number of times to encrypt password.
|
58
|
+
mattr_accessor :stretches
|
59
|
+
@@stretches = 10
|
60
|
+
|
61
|
+
# Keys used when authenticating an user.
|
62
|
+
mattr_accessor :authentication_keys
|
63
|
+
@@authentication_keys = [ :email ]
|
64
|
+
|
65
|
+
# Request keys used when authenticating an user.
|
66
|
+
mattr_accessor :request_keys
|
67
|
+
@@request_keys = []
|
68
|
+
|
69
|
+
# If http authentication is enabled by default.
|
70
|
+
mattr_accessor :http_authenticatable
|
71
|
+
@@http_authenticatable = false
|
72
|
+
|
73
|
+
# If http headers should be returned for ajax requests. True by default.
|
74
|
+
mattr_accessor :http_authenticatable_on_xhr
|
75
|
+
@@http_authenticatable_on_xhr = true
|
76
|
+
|
77
|
+
# If params authenticatable is enabled by default.
|
78
|
+
mattr_accessor :params_authenticatable
|
79
|
+
@@params_authenticatable = true
|
80
|
+
|
81
|
+
# The realm used in Http Basic Authentication.
|
82
|
+
mattr_accessor :http_authentication_realm
|
83
|
+
@@http_authentication_realm = "Application"
|
84
|
+
|
85
|
+
# Email regex used to validate email formats. Adapted from authlogic.
|
86
|
+
mattr_accessor :email_regexp
|
87
|
+
@@email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
88
|
+
|
89
|
+
# Range validation for password length
|
90
|
+
mattr_accessor :password_length
|
91
|
+
@@password_length = 6..20
|
92
|
+
|
93
|
+
# The time the user will be remembered without asking for credentials again.
|
94
|
+
mattr_accessor :remember_for
|
95
|
+
@@remember_for = 2.weeks
|
96
|
+
|
97
|
+
# If true, a valid remember token can be re-used between multiple browsers.
|
98
|
+
mattr_accessor :remember_across_browsers
|
99
|
+
@@remember_across_browsers = true
|
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
|
+
# If true, uses salt as remember token and does not create it in the database.
|
106
|
+
# By default is false for backwards compatibility.
|
107
|
+
mattr_accessor :use_salt_as_remember_token
|
108
|
+
@@use_salt_as_remember_token = false
|
109
|
+
|
110
|
+
# Time interval you can access your account before confirming your account.
|
111
|
+
mattr_accessor :confirm_within
|
112
|
+
@@confirm_within = 0.days
|
113
|
+
|
114
|
+
# Time interval to timeout the user session without activity.
|
115
|
+
mattr_accessor :timeout_in
|
116
|
+
@@timeout_in = 30.minutes
|
117
|
+
|
118
|
+
# Used to encrypt password. Please generate one with rake secret.
|
119
|
+
mattr_accessor :pepper
|
120
|
+
@@pepper = nil
|
121
|
+
|
122
|
+
# Used to define the password encryption algorithm.
|
123
|
+
mattr_accessor :encryptor
|
124
|
+
@@encryptor = nil
|
125
|
+
|
126
|
+
# Tells if devise should apply the schema in ORMs where devise declaration
|
127
|
+
# and schema belongs to the same class (as Datamapper and Mongoid).
|
128
|
+
mattr_accessor :apply_schema
|
129
|
+
@@apply_schema = true
|
130
|
+
|
131
|
+
# Scoped views. Since it relies on fallbacks to render default views, it's
|
132
|
+
# turned off by default.
|
133
|
+
mattr_accessor :scoped_views
|
134
|
+
@@scoped_views = false
|
135
|
+
|
136
|
+
# Defines which strategy can be used to lock an account.
|
137
|
+
# Values: :failed_attempts, :none
|
138
|
+
mattr_accessor :lock_strategy
|
139
|
+
@@lock_strategy = :failed_attempts
|
140
|
+
|
141
|
+
# Defines which strategy can be used to unlock an account.
|
142
|
+
# Values: :email, :time, :both
|
143
|
+
mattr_accessor :unlock_strategy
|
144
|
+
@@unlock_strategy = :both
|
145
|
+
|
146
|
+
# Number of authentication tries before locking an account
|
147
|
+
mattr_accessor :maximum_attempts
|
148
|
+
@@maximum_attempts = 20
|
149
|
+
|
150
|
+
# Time interval to unlock the account if :time is defined as unlock_strategy.
|
151
|
+
mattr_accessor :unlock_in
|
152
|
+
@@unlock_in = 1.hour
|
153
|
+
|
154
|
+
# The default scope which is used by warden.
|
155
|
+
mattr_accessor :default_scope
|
156
|
+
@@default_scope = nil
|
157
|
+
|
158
|
+
# Address which sends Devise e-mails.
|
159
|
+
mattr_accessor :mailer_sender
|
160
|
+
@@mailer_sender = nil
|
161
|
+
|
162
|
+
# Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
|
163
|
+
mattr_accessor :token_authentication_key
|
164
|
+
@@token_authentication_key = :auth_token
|
165
|
+
|
166
|
+
# If true, authentication through token does not store user in session
|
167
|
+
mattr_accessor :stateless_token
|
168
|
+
@@stateless_token = false
|
169
|
+
|
170
|
+
# Which formats should be treated as navigational.
|
171
|
+
mattr_accessor :navigational_formats
|
172
|
+
@@navigational_formats = [:html]
|
173
|
+
|
174
|
+
# When set to true, signing out an user signs out all other scopes.
|
175
|
+
mattr_accessor :sign_out_all_scopes
|
176
|
+
@@sign_out_all_scopes = true
|
177
|
+
|
178
|
+
# The default method used while signing out
|
179
|
+
mattr_accessor :sign_out_via
|
180
|
+
@@sign_out_via = :get
|
181
|
+
|
182
|
+
# Oauth providers
|
183
|
+
mattr_accessor :oauth_providers
|
184
|
+
@@oauth_providers = []
|
185
|
+
|
186
|
+
# PRIVATE CONFIGURATION
|
187
|
+
|
188
|
+
# Store scopes mappings.
|
189
|
+
mattr_reader :mappings
|
190
|
+
@@mappings = ActiveSupport::OrderedHash.new
|
191
|
+
|
192
|
+
# Oauth configurations.
|
193
|
+
mattr_reader :oauth_configs
|
194
|
+
@@oauth_configs = ActiveSupport::OrderedHash.new
|
195
|
+
|
196
|
+
# Define a set of modules that are called when a mapping is added.
|
197
|
+
mattr_reader :helpers
|
198
|
+
@@helpers = Set.new
|
199
|
+
@@helpers << Devise::Controllers::Helpers
|
200
|
+
|
201
|
+
# Define a set of modules that are called when a provider is added.
|
202
|
+
mattr_reader :oauth_helpers
|
203
|
+
@@oauth_helpers = Set.new
|
204
|
+
|
205
|
+
# Private methods to interface with Warden.
|
206
|
+
mattr_accessor :warden_config
|
207
|
+
@@warden_config = nil
|
208
|
+
@@warden_config_block = nil
|
209
|
+
|
210
|
+
# Default way to setup Devise. Run rails generate devise_install to create
|
211
|
+
# a fresh initializer with all configuration values.
|
212
|
+
def self.setup
|
213
|
+
yield self
|
214
|
+
end
|
215
|
+
|
216
|
+
def self.cookie_domain=(value)
|
217
|
+
ActiveSupport::Deprecation.warn "Devise.cookie_domain=(value) is deprecated. "
|
218
|
+
"Please use Devise.cookie_options = { :domain => value } instead."
|
219
|
+
self.cookie_options[:domain] = value
|
220
|
+
end
|
221
|
+
|
222
|
+
# Get the mailer class from the mailer reference object.
|
223
|
+
def self.mailer
|
224
|
+
@@mailer_ref.get
|
225
|
+
end
|
226
|
+
|
227
|
+
# Set the mailer reference object to access the mailer.
|
228
|
+
def self.mailer=(class_name)
|
229
|
+
@@mailer_ref = ActiveSupport::Dependencies.ref(class_name)
|
230
|
+
end
|
231
|
+
self.mailer = "Devise::Mailer"
|
232
|
+
|
233
|
+
# Small method that adds a mapping to Devise.
|
234
|
+
def self.add_mapping(resource, options)
|
235
|
+
mapping = Devise::Mapping.new(resource, options)
|
236
|
+
@@mappings[mapping.name] = mapping
|
237
|
+
@@default_scope ||= mapping.name
|
238
|
+
@@helpers.each { |h| h.define_helpers(mapping) }
|
239
|
+
mapping
|
240
|
+
end
|
241
|
+
|
242
|
+
# Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
|
243
|
+
#
|
244
|
+
# == Options:
|
245
|
+
#
|
246
|
+
# +model+ - String representing the load path to a custom *model* for this module (to autoload.)
|
247
|
+
# +controller+ - Symbol representing the name of an exisiting or custom *controller* for this module.
|
248
|
+
# +route+ - Symbol representing the named *route* helper for this module.
|
249
|
+
# +strategy+ - Symbol representing if this module got a custom *strategy*.
|
250
|
+
#
|
251
|
+
# All values, except :model, accept also a boolean and will have the same name as the given module
|
252
|
+
# name.
|
253
|
+
#
|
254
|
+
# == Examples:
|
255
|
+
#
|
256
|
+
# Devise.add_module(:party_module)
|
257
|
+
# Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
|
258
|
+
# Devise.add_module(:party_module, :model => 'party_module/model')
|
259
|
+
#
|
260
|
+
def self.add_module(module_name, options = {})
|
261
|
+
ALL << module_name
|
262
|
+
options.assert_valid_keys(:strategy, :model, :controller, :route)
|
263
|
+
|
264
|
+
if strategy = options[:strategy]
|
265
|
+
STRATEGIES[module_name] = (strategy == true ? module_name : strategy)
|
266
|
+
end
|
267
|
+
|
268
|
+
if controller = options[:controller]
|
269
|
+
CONTROLLERS[module_name] = (controller == true ? module_name : controller)
|
270
|
+
end
|
271
|
+
|
272
|
+
if route = options[:route]
|
273
|
+
case route
|
274
|
+
when TrueClass
|
275
|
+
key, value = module_name, []
|
276
|
+
when Symbol
|
277
|
+
key, value = route, []
|
278
|
+
when Hash
|
279
|
+
key, value = route.keys.first, route.values.flatten
|
280
|
+
else
|
281
|
+
raise ArgumentError, ":route should be true, a Symbol or a Hash"
|
282
|
+
end
|
283
|
+
|
284
|
+
URL_HELPERS[key] ||= []
|
285
|
+
URL_HELPERS[key].concat(value)
|
286
|
+
URL_HELPERS[key].uniq!
|
287
|
+
|
288
|
+
ROUTES[module_name] = key
|
289
|
+
end
|
290
|
+
|
291
|
+
if options[:model]
|
292
|
+
path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
|
293
|
+
Devise::Models.send(:autoload, module_name.to_s.camelize.to_sym, path)
|
294
|
+
end
|
295
|
+
|
296
|
+
Devise::Mapping.add_module module_name
|
297
|
+
end
|
298
|
+
|
299
|
+
# Sets warden configuration using a block that will be invoked on warden
|
300
|
+
# initialization.
|
301
|
+
#
|
302
|
+
# Devise.initialize do |config|
|
303
|
+
# config.confirm_within = 2.days
|
304
|
+
#
|
305
|
+
# config.warden do |manager|
|
306
|
+
# # Configure warden to use other strategies, like oauth.
|
307
|
+
# manager.oauth(:twitter)
|
308
|
+
# end
|
309
|
+
# end
|
310
|
+
def self.warden(&block)
|
311
|
+
@@warden_config_block = block
|
312
|
+
end
|
313
|
+
|
314
|
+
# Specify an oauth provider.
|
315
|
+
#
|
316
|
+
# config.oauth :github, APP_ID, APP_SECRET,
|
317
|
+
# :site => 'https://github.com/',
|
318
|
+
# :authorize_path => '/login/oauth/authorize',
|
319
|
+
# :access_token_path => '/login/oauth/access_token',
|
320
|
+
# :scope => %w(user public_repo)
|
321
|
+
#
|
322
|
+
def self.oauth(provider, *args)
|
323
|
+
@@helpers << Devise::Oauth::UrlHelpers
|
324
|
+
@@oauth_helpers << Devise::Oauth::InternalHelpers
|
325
|
+
|
326
|
+
@@oauth_providers << provider
|
327
|
+
@@oauth_providers.uniq!
|
328
|
+
|
329
|
+
@@oauth_helpers.each { |h| h.define_oauth_helpers(provider) }
|
330
|
+
@@oauth_configs[provider] = Devise::Oauth::Config.new(*args)
|
331
|
+
end
|
332
|
+
|
333
|
+
# Include helpers in the given scope to AC and AV.
|
334
|
+
def self.include_helpers(scope)
|
335
|
+
ActiveSupport.on_load(:action_controller) do
|
336
|
+
include scope::Helpers
|
337
|
+
include scope::UrlHelpers
|
338
|
+
end
|
339
|
+
|
340
|
+
ActiveSupport.on_load(:action_view) do
|
341
|
+
include scope::UrlHelpers
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
# A method used internally to setup warden manager from the Rails initialize
|
346
|
+
# block.
|
347
|
+
def self.configure_warden! #:nodoc:
|
348
|
+
@@warden_configured ||= begin
|
349
|
+
warden_config.failure_app = Devise::FailureApp
|
350
|
+
warden_config.default_scope = Devise.default_scope
|
351
|
+
|
352
|
+
Devise.mappings.each_value do |mapping|
|
353
|
+
warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
|
354
|
+
end
|
355
|
+
|
356
|
+
@@warden_config_block.try :call, Devise.warden_config
|
357
|
+
true
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
# Generate a friendly string randomically to be used as token.
|
362
|
+
def self.friendly_token
|
363
|
+
ActiveSupport::SecureRandom.base64(44).tr('+/=', 'xyz')
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
require 'warden'
|
368
|
+
require 'devise/mapping'
|
369
|
+
require 'devise/models'
|
370
|
+
require 'devise/modules'
|
371
|
+
require 'devise/rails'
|