cloudfoundry-devise 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.rdoc +755 -0
- data/Gemfile +35 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +366 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +46 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +50 -0
- data/app/controllers/devise/registrations_controller.rb +114 -0
- data/app/controllers/devise/sessions_controller.rb +49 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +25 -0
- data/app/mailers/devise/mailer.rb +15 -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/cloudfoundry-devise.gemspec +25 -0
- data/config/locales/en.yml +59 -0
- data/lib/devise.rb +453 -0
- data/lib/devise/controllers/helpers.rb +260 -0
- data/lib/devise/controllers/internal_helpers.rb +161 -0
- data/lib/devise/controllers/rememberable.rb +52 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/shared_helpers.rb +26 -0
- data/lib/devise/controllers/url_helpers.rb +53 -0
- data/lib/devise/delegator.rb +16 -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 +149 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +9 -0
- data/lib/devise/hooks/rememberable.rb +6 -0
- data/lib/devise/hooks/timeoutable.rb +24 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mailers/helpers.rb +86 -0
- data/lib/devise/mapping.rb +175 -0
- data/lib/devise/models.rb +91 -0
- data/lib/devise/models/authenticatable.rb +181 -0
- data/lib/devise/models/confirmable.rb +220 -0
- data/lib/devise/models/database_authenticatable.rb +122 -0
- data/lib/devise/models/encryptable.rb +72 -0
- data/lib/devise/models/lockable.rb +169 -0
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +136 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +114 -0
- data/lib/devise/models/serializable.rb +43 -0
- data/lib/devise/models/timeoutable.rb +45 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +62 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth.rb +28 -0
- data/lib/devise/omniauth/config.rb +45 -0
- data/lib/devise/omniauth/url_helpers.rb +33 -0
- data/lib/devise/orm/active_record.rb +44 -0
- data/lib/devise/orm/mongoid.rb +31 -0
- data/lib/devise/param_filter.rb +41 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails.rb +73 -0
- data/lib/devise/rails/routes.rb +385 -0
- data/lib/devise/rails/warden_compat.rb +120 -0
- data/lib/devise/schema.rb +109 -0
- data/lib/devise/strategies/authenticatable.rb +155 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +53 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +90 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +71 -0
- data/lib/generators/active_record/templates/migration.rb +29 -0
- data/lib/generators/active_record/templates/migration_existing.rb +26 -0
- data/lib/generators/devise/devise_generator.rb +22 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +31 -0
- data/lib/generators/devise/views_generator.rb +98 -0
- data/lib/generators/mongoid/devise_generator.rb +60 -0
- data/lib/generators/templates/README +32 -0
- data/lib/generators/templates/devise.rb +215 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
- data/test/controllers/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +96 -0
- data/test/controllers/sessions_controller_test.rb +16 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/delegator_test.rb +19 -0
- data/test/devise_test.rb +72 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +207 -0
- data/test/generators/active_record_generator_test.rb +47 -0
- data/test/generators/devise_generator_test.rb +39 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +23 -0
- data/test/generators/views_generator_test.rb +52 -0
- data/test/helpers/devise_helper_test.rb +51 -0
- data/test/indifferent_hash.rb +33 -0
- data/test/integration/authenticatable_test.rb +590 -0
- data/test/integration/confirmable_test.rb +262 -0
- data/test/integration/database_authenticatable_test.rb +82 -0
- data/test/integration/http_authenticatable_test.rb +82 -0
- data/test/integration/lockable_test.rb +212 -0
- data/test/integration/omniauthable_test.rb +133 -0
- data/test/integration/recoverable_test.rb +287 -0
- data/test/integration/registerable_test.rb +335 -0
- data/test/integration/rememberable_test.rb +158 -0
- data/test/integration/timeoutable_test.rb +98 -0
- data/test/integration/token_authenticatable_test.rb +148 -0
- data/test/integration/trackable_test.rb +92 -0
- data/test/mailers/confirmation_instructions_test.rb +95 -0
- data/test/mailers/reset_password_instructions_test.rb +83 -0
- data/test/mailers/unlock_instructions_test.rb +77 -0
- data/test/mapping_test.rb +128 -0
- data/test/models/confirmable_test.rb +334 -0
- data/test/models/database_authenticatable_test.rb +167 -0
- data/test/models/encryptable_test.rb +67 -0
- data/test/models/lockable_test.rb +225 -0
- data/test/models/recoverable_test.rb +198 -0
- data/test/models/rememberable_test.rb +168 -0
- data/test/models/serializable_test.rb +38 -0
- data/test/models/timeoutable_test.rb +42 -0
- data/test/models/token_authenticatable_test.rb +49 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +113 -0
- data/test/models_test.rb +109 -0
- data/test/omniauth/config_test.rb +57 -0
- data/test/omniauth/url_helpers_test.rb +58 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +14 -0
- data/test/rails_app/Rakefile +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 +6 -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 +8 -0
- data/test/rails_app/app/controllers/home_controller.rb +25 -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/omniauth_callbacks_controller.rb +14 -0
- data/test/rails_app/app/controllers/users_controller.rb +23 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +24 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -0
- data/test/rails_app/app/mongoid/user.rb +45 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +41 -0
- data/test/rails_app/config/boot.rb +8 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +18 -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 +197 -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 +87 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +10 -0
- data/test/rails_app/lib/shared_user.rb +26 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +240 -0
- data/test/support/assertions.rb +27 -0
- data/test/support/helpers.rb +109 -0
- data/test/support/integration.rb +88 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +27 -0
- data/test/test_helpers_test.rb +134 -0
- metadata +295 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
class Devise::ConfirmationsController < ApplicationController
|
2
|
+
include Devise::Controllers::InternalHelpers
|
3
|
+
|
4
|
+
# GET /resource/confirmation/new
|
5
|
+
def new
|
6
|
+
build_resource({})
|
7
|
+
render_with_scope :new
|
8
|
+
end
|
9
|
+
|
10
|
+
# POST /resource/confirmation
|
11
|
+
def create
|
12
|
+
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
|
13
|
+
|
14
|
+
if successfully_sent?(resource)
|
15
|
+
respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
|
16
|
+
else
|
17
|
+
respond_with_navigational(resource){ render_with_scope :new }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /resource/confirmation?confirmation_token=abcdef
|
22
|
+
def show
|
23
|
+
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
|
24
|
+
|
25
|
+
if resource.errors.empty?
|
26
|
+
set_flash_message(:notice, :confirmed) if is_navigational_format?
|
27
|
+
sign_in(resource_name, resource)
|
28
|
+
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
|
29
|
+
else
|
30
|
+
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
# The path used after resending confirmation instructions.
|
37
|
+
def after_resending_confirmation_instructions_path_for(resource_name)
|
38
|
+
new_session_path(resource_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
# The path used after confirmation.
|
42
|
+
def after_confirmation_path_for(resource_name, resource)
|
43
|
+
after_sign_in_path_for(resource)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Devise::OmniauthCallbacksController < ApplicationController
|
2
|
+
include Devise::Controllers::InternalHelpers
|
3
|
+
|
4
|
+
def failure
|
5
|
+
set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
|
6
|
+
redirect_to after_omniauth_failure_path_for(resource_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def failed_strategy
|
12
|
+
env["omniauth.error.strategy"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message
|
16
|
+
exception = env["omniauth.error"]
|
17
|
+
error = exception.error_reason if exception.respond_to?(:error_reason)
|
18
|
+
error ||= exception.error if exception.respond_to?(:error)
|
19
|
+
error ||= env["omniauth.error.type"].to_s
|
20
|
+
error.to_s.humanize if error
|
21
|
+
end
|
22
|
+
|
23
|
+
def after_omniauth_failure_path_for(scope)
|
24
|
+
new_session_path(scope)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Devise::PasswordsController < ApplicationController
|
2
|
+
prepend_before_filter :require_no_authentication
|
3
|
+
include Devise::Controllers::InternalHelpers
|
4
|
+
|
5
|
+
# GET /resource/password/new
|
6
|
+
def new
|
7
|
+
build_resource({})
|
8
|
+
render_with_scope :new
|
9
|
+
end
|
10
|
+
|
11
|
+
# POST /resource/password
|
12
|
+
def create
|
13
|
+
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
14
|
+
|
15
|
+
if successfully_sent?(resource)
|
16
|
+
respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
|
17
|
+
else
|
18
|
+
respond_with_navigational(resource){ render_with_scope :new }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /resource/password/edit?reset_password_token=abcdef
|
23
|
+
def edit
|
24
|
+
self.resource = resource_class.new
|
25
|
+
resource.reset_password_token = params[:reset_password_token]
|
26
|
+
render_with_scope :edit
|
27
|
+
end
|
28
|
+
|
29
|
+
# PUT /resource/password
|
30
|
+
def update
|
31
|
+
self.resource = resource_class.reset_password_by_token(params[resource_name])
|
32
|
+
|
33
|
+
if resource.errors.empty?
|
34
|
+
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
35
|
+
set_flash_message(:notice, flash_message) if is_navigational_format?
|
36
|
+
sign_in(resource_name, resource)
|
37
|
+
respond_with resource, :location => after_sign_in_path_for(resource)
|
38
|
+
else
|
39
|
+
respond_with_navigational(resource){ render_with_scope :edit }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
# The path used after sending reset password instructions
|
46
|
+
def after_sending_reset_password_instructions_path_for(resource_name)
|
47
|
+
new_session_path(resource_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class Devise::RegistrationsController < ApplicationController
|
2
|
+
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
|
3
|
+
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
4
|
+
include Devise::Controllers::InternalHelpers
|
5
|
+
|
6
|
+
# GET /resource/sign_up
|
7
|
+
def new
|
8
|
+
resource = build_resource({})
|
9
|
+
respond_with_navigational(resource){ render_with_scope :new }
|
10
|
+
end
|
11
|
+
|
12
|
+
# POST /resource
|
13
|
+
def create
|
14
|
+
build_resource
|
15
|
+
|
16
|
+
if resource.save
|
17
|
+
if resource.active_for_authentication?
|
18
|
+
set_flash_message :notice, :signed_up if is_navigational_format?
|
19
|
+
sign_in(resource_name, resource)
|
20
|
+
respond_with resource, :location => after_sign_up_path_for(resource)
|
21
|
+
else
|
22
|
+
set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format?
|
23
|
+
expire_session_data_after_sign_in!
|
24
|
+
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
clean_up_passwords(resource)
|
28
|
+
respond_with_navigational(resource) { render_with_scope :new }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# GET /resource/edit
|
33
|
+
def edit
|
34
|
+
render_with_scope :edit
|
35
|
+
end
|
36
|
+
|
37
|
+
# PUT /resource
|
38
|
+
# We need to use a copy of the resource because we don't want to change
|
39
|
+
# the current user in place.
|
40
|
+
def update
|
41
|
+
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
42
|
+
|
43
|
+
if resource.update_with_password(params[resource_name])
|
44
|
+
if is_navigational_format?
|
45
|
+
if resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation?
|
46
|
+
flash_key = :update_needs_confirmation
|
47
|
+
end
|
48
|
+
set_flash_message :notice, flash_key || :updated
|
49
|
+
end
|
50
|
+
sign_in resource_name, resource, :bypass => true
|
51
|
+
respond_with resource, :location => after_update_path_for(resource)
|
52
|
+
else
|
53
|
+
clean_up_passwords(resource)
|
54
|
+
respond_with_navigational(resource){ render_with_scope :edit }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# DELETE /resource
|
59
|
+
def destroy
|
60
|
+
resource.destroy
|
61
|
+
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
62
|
+
set_flash_message :notice, :destroyed if is_navigational_format?
|
63
|
+
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
|
64
|
+
end
|
65
|
+
|
66
|
+
# GET /resource/cancel
|
67
|
+
# Forces the session data which is usually expired after sign
|
68
|
+
# in to be expired now. This is useful if the user wants to
|
69
|
+
# cancel oauth signing in/up in the middle of the process,
|
70
|
+
# removing all OAuth session data.
|
71
|
+
def cancel
|
72
|
+
expire_session_data_after_sign_in!
|
73
|
+
redirect_to new_registration_path(resource_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
# Build a devise resource passing in the session. Useful to move
|
79
|
+
# temporary session data to the newly created user.
|
80
|
+
def build_resource(hash=nil)
|
81
|
+
hash ||= params[resource_name] || {}
|
82
|
+
self.resource = resource_class.new_with_session(hash, session)
|
83
|
+
end
|
84
|
+
|
85
|
+
# The path used after sign up. You need to overwrite this method
|
86
|
+
# in your own RegistrationsController.
|
87
|
+
def after_sign_up_path_for(resource)
|
88
|
+
after_sign_in_path_for(resource)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns the inactive reason translated.
|
92
|
+
def inactive_reason(resource)
|
93
|
+
reason = resource.inactive_message.to_s
|
94
|
+
I18n.t("devise.registrations.reasons.#{reason}", :default => reason)
|
95
|
+
end
|
96
|
+
|
97
|
+
# The path used after sign up for inactive accounts. You need to overwrite
|
98
|
+
# this method in your own RegistrationsController.
|
99
|
+
def after_inactive_sign_up_path_for(resource)
|
100
|
+
root_path
|
101
|
+
end
|
102
|
+
|
103
|
+
# The default url to be used after updating a resource. You need to overwrite
|
104
|
+
# this method in your own RegistrationsController.
|
105
|
+
def after_update_path_for(resource)
|
106
|
+
signed_in_root_path(resource)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Authenticates the current scope and gets the current resource from the session.
|
110
|
+
def authenticate_scope!
|
111
|
+
send(:"authenticate_#{resource_name}!", :force => true)
|
112
|
+
self.resource = send(:"current_#{resource_name}")
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Devise::SessionsController < ApplicationController
|
2
|
+
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
|
3
|
+
prepend_before_filter :allow_params_authentication!, :only => :create
|
4
|
+
include Devise::Controllers::InternalHelpers
|
5
|
+
|
6
|
+
# GET /resource/sign_in
|
7
|
+
def new
|
8
|
+
resource = build_resource
|
9
|
+
clean_up_passwords(resource)
|
10
|
+
respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }
|
11
|
+
end
|
12
|
+
|
13
|
+
# POST /resource/sign_in
|
14
|
+
def create
|
15
|
+
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
|
16
|
+
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
17
|
+
sign_in(resource_name, resource)
|
18
|
+
respond_with resource, :location => after_sign_in_path_for(resource)
|
19
|
+
end
|
20
|
+
|
21
|
+
# DELETE /resource/sign_out
|
22
|
+
def destroy
|
23
|
+
signed_in = signed_in?(resource_name)
|
24
|
+
redirect_path = after_sign_out_path_for(resource_name)
|
25
|
+
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
26
|
+
set_flash_message :notice, :signed_out if signed_in
|
27
|
+
|
28
|
+
# We actually need to hardcode this as Rails default responder doesn't
|
29
|
+
# support returning empty response on GET request
|
30
|
+
respond_to do |format|
|
31
|
+
format.any(*navigational_formats) { redirect_to redirect_path }
|
32
|
+
format.all do
|
33
|
+
method = "to_#{request_format}"
|
34
|
+
text = {}.respond_to?(method) ? {}.send(method) : ""
|
35
|
+
render :text => text, :status => :ok
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def stub_options(resource)
|
43
|
+
methods = resource_class.authentication_keys.dup
|
44
|
+
methods = methods.keys if methods.is_a?(Hash)
|
45
|
+
methods << :password if resource.respond_to?(:password)
|
46
|
+
{ :methods => methods, :only => [:password] }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -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 successfully_sent?(resource)
|
16
|
+
respond_with({}, :location => new_session_path(resource_name))
|
17
|
+
else
|
18
|
+
respond_with_navigational(resource){ render_with_scope :new }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /resource/unlock?unlock_token=abcdef
|
23
|
+
def show
|
24
|
+
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
|
25
|
+
|
26
|
+
if resource.errors.empty?
|
27
|
+
set_flash_message :notice, :unlocked if is_navigational_format?
|
28
|
+
sign_in(resource_name, resource)
|
29
|
+
respond_with_navigational(resource){ redirect_to after_sign_in_path_for(resource) }
|
30
|
+
else
|
31
|
+
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module DeviseHelper
|
2
|
+
# A simple way to show error messages for the current devise resource. If you need
|
3
|
+
# to customize this method, you can either overwrite it in your application helpers or
|
4
|
+
# copy the views to your application.
|
5
|
+
#
|
6
|
+
# This method is intended to stay simple and it is unlikely that we are going to change
|
7
|
+
# it to add more behavior or options.
|
8
|
+
def devise_error_messages!
|
9
|
+
return "" if resource.errors.empty?
|
10
|
+
|
11
|
+
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
|
12
|
+
sentence = I18n.t("errors.messages.not_saved",
|
13
|
+
:count => resource.errors.count,
|
14
|
+
:resource => resource.class.model_name.human.downcase)
|
15
|
+
|
16
|
+
html = <<-HTML
|
17
|
+
<div id="error_explanation">
|
18
|
+
<h2>#{sentence}</h2>
|
19
|
+
<ul>#{messages}</ul>
|
20
|
+
</div>
|
21
|
+
HTML
|
22
|
+
|
23
|
+
html.html_safe
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Devise::Mailer < ::ActionMailer::Base
|
2
|
+
include Devise::Mailers::Helpers
|
3
|
+
|
4
|
+
def confirmation_instructions(record)
|
5
|
+
devise_mail(record, :confirmation_instructions)
|
6
|
+
end
|
7
|
+
|
8
|
+
def reset_password_instructions(record)
|
9
|
+
devise_mail(record, :reset_password_instructions)
|
10
|
+
end
|
11
|
+
|
12
|
+
def unlock_instructions(record)
|
13
|
+
devise_mail(record, :unlock_instructions)
|
14
|
+
end
|
15
|
+
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
|
+
<div><%= f.label :email %><br />
|
7
|
+
<%= f.email_field :email %></div>
|
8
|
+
|
9
|
+
<div><%= f.submit "Resend confirmation instructions" %></div>
|
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
|
+
<div><%= f.label :password, "New password" %><br />
|
8
|
+
<%= f.password_field :password %></div>
|
9
|
+
|
10
|
+
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
|
11
|
+
<%= f.password_field :password_confirmation %></div>
|
12
|
+
|
13
|
+
<div><%= f.submit "Change my password" %></div>
|
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
|
+
<div><%= f.label :email %><br />
|
7
|
+
<%= f.email_field :email %></div>
|
8
|
+
|
9
|
+
<div><%= f.submit "Send me reset password instructions" %></div>
|
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
|
+
<div><%= f.label :email %><br />
|
7
|
+
<%= f.email_field :email %></div>
|
8
|
+
|
9
|
+
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
10
|
+
<%= f.password_field :password %></div>
|
11
|
+
|
12
|
+
<div><%= f.label :password_confirmation %><br />
|
13
|
+
<%= f.password_field :password_confirmation %></div>
|
14
|
+
|
15
|
+
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
16
|
+
<%= f.password_field :current_password %></div>
|
17
|
+
|
18
|
+
<div><%= f.submit "Update" %></div>
|
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 %>
|