brainsome_devise 3.3.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.
Files changed (234) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +35 -0
  4. data/.yardopts +9 -0
  5. data/CHANGELOG.md +1086 -0
  6. data/CONTRIBUTING.md +14 -0
  7. data/Gemfile +29 -0
  8. data/Gemfile.lock +166 -0
  9. data/MIT-LICENSE +20 -0
  10. data/README.md +506 -0
  11. data/Rakefile +35 -0
  12. data/app/controllers/devise/confirmations_controller.rb +47 -0
  13. data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
  14. data/app/controllers/devise/passwords_controller.rb +70 -0
  15. data/app/controllers/devise/registrations_controller.rb +148 -0
  16. data/app/controllers/devise/sessions_controller.rb +76 -0
  17. data/app/controllers/devise/unlocks_controller.rb +46 -0
  18. data/app/controllers/devise_controller.rb +176 -0
  19. data/app/helpers/devise_helper.rb +25 -0
  20. data/app/mailers/devise/mailer.rb +20 -0
  21. data/app/views/devise/confirmations/new.html.erb +12 -0
  22. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  23. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  24. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  25. data/app/views/devise/passwords/edit.html.erb +16 -0
  26. data/app/views/devise/passwords/new.html.erb +12 -0
  27. data/app/views/devise/registrations/edit.html.erb +29 -0
  28. data/app/views/devise/registrations/new.html.erb +18 -0
  29. data/app/views/devise/sessions/new.html.erb +17 -0
  30. data/app/views/devise/shared/_links.html.erb +25 -0
  31. data/app/views/devise/unlocks/new.html.erb +12 -0
  32. data/config/locales/en.yml +60 -0
  33. data/devise.gemspec +27 -0
  34. data/devise.png +0 -0
  35. data/gemfiles/Gemfile.rails-3.2-stable +29 -0
  36. data/gemfiles/Gemfile.rails-3.2-stable.lock +166 -0
  37. data/gemfiles/Gemfile.rails-4.0-stable +29 -0
  38. data/gemfiles/Gemfile.rails-4.0-stable.lock +162 -0
  39. data/gemfiles/Gemfile.rails-head +32 -0
  40. data/gemfiles/Gemfile.rails-head.lock +206 -0
  41. data/lib/devise.rb +495 -0
  42. data/lib/devise/controllers/helpers.rb +284 -0
  43. data/lib/devise/controllers/rememberable.rb +47 -0
  44. data/lib/devise/controllers/scoped_views.rb +17 -0
  45. data/lib/devise/controllers/sign_in_out.rb +102 -0
  46. data/lib/devise/controllers/store_location.rb +56 -0
  47. data/lib/devise/controllers/url_helpers.rb +69 -0
  48. data/lib/devise/delegator.rb +16 -0
  49. data/lib/devise/failure_app.rb +205 -0
  50. data/lib/devise/hooks/activatable.rb +10 -0
  51. data/lib/devise/hooks/csrf_cleaner.rb +7 -0
  52. data/lib/devise/hooks/forgetable.rb +9 -0
  53. data/lib/devise/hooks/lockable.rb +7 -0
  54. data/lib/devise/hooks/proxy.rb +21 -0
  55. data/lib/devise/hooks/rememberable.rb +7 -0
  56. data/lib/devise/hooks/timeoutable.rb +35 -0
  57. data/lib/devise/hooks/trackable.rb +9 -0
  58. data/lib/devise/mailers/helpers.rb +90 -0
  59. data/lib/devise/mapping.rb +175 -0
  60. data/lib/devise/models.rb +119 -0
  61. data/lib/devise/models/authenticatable.rb +284 -0
  62. data/lib/devise/models/confirmable.rb +295 -0
  63. data/lib/devise/models/database_authenticatable.rb +164 -0
  64. data/lib/devise/models/lockable.rb +196 -0
  65. data/lib/devise/models/omniauthable.rb +27 -0
  66. data/lib/devise/models/recoverable.rb +147 -0
  67. data/lib/devise/models/registerable.rb +25 -0
  68. data/lib/devise/models/rememberable.rb +129 -0
  69. data/lib/devise/models/timeoutable.rb +49 -0
  70. data/lib/devise/models/trackable.rb +38 -0
  71. data/lib/devise/models/validatable.rb +66 -0
  72. data/lib/devise/modules.rb +28 -0
  73. data/lib/devise/omniauth.rb +28 -0
  74. data/lib/devise/omniauth/config.rb +45 -0
  75. data/lib/devise/omniauth/url_helpers.rb +18 -0
  76. data/lib/devise/orm/active_record.rb +3 -0
  77. data/lib/devise/orm/mongoid.rb +3 -0
  78. data/lib/devise/parameter_filter.rb +40 -0
  79. data/lib/devise/parameter_sanitizer.rb +99 -0
  80. data/lib/devise/rails.rb +56 -0
  81. data/lib/devise/rails/routes.rb +498 -0
  82. data/lib/devise/rails/warden_compat.rb +22 -0
  83. data/lib/devise/strategies/authenticatable.rb +174 -0
  84. data/lib/devise/strategies/base.rb +20 -0
  85. data/lib/devise/strategies/database_authenticatable.rb +23 -0
  86. data/lib/devise/strategies/rememberable.rb +55 -0
  87. data/lib/devise/test_helpers.rb +132 -0
  88. data/lib/devise/time_inflector.rb +14 -0
  89. data/lib/devise/token_generator.rb +70 -0
  90. data/lib/devise/version.rb +3 -0
  91. data/lib/generators/active_record/devise_generator.rb +91 -0
  92. data/lib/generators/active_record/templates/migration.rb +18 -0
  93. data/lib/generators/active_record/templates/migration_existing.rb +25 -0
  94. data/lib/generators/devise/devise_generator.rb +26 -0
  95. data/lib/generators/devise/install_generator.rb +29 -0
  96. data/lib/generators/devise/orm_helpers.rb +51 -0
  97. data/lib/generators/devise/views_generator.rb +135 -0
  98. data/lib/generators/mongoid/devise_generator.rb +55 -0
  99. data/lib/generators/templates/README +35 -0
  100. data/lib/generators/templates/devise.rb +263 -0
  101. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  102. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  103. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  104. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +16 -0
  105. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  106. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  107. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +27 -0
  108. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  109. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  110. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +16 -0
  111. data/script/cached-bundle +49 -0
  112. data/script/s3-put +71 -0
  113. data/test/controllers/custom_registrations_controller_test.rb +35 -0
  114. data/test/controllers/custom_strategy_test.rb +62 -0
  115. data/test/controllers/helpers_test.rb +311 -0
  116. data/test/controllers/internal_helpers_test.rb +123 -0
  117. data/test/controllers/passwords_controller_test.rb +31 -0
  118. data/test/controllers/sessions_controller_test.rb +103 -0
  119. data/test/controllers/url_helpers_test.rb +59 -0
  120. data/test/delegator_test.rb +19 -0
  121. data/test/devise_test.rb +107 -0
  122. data/test/failure_app_test.rb +268 -0
  123. data/test/generators/active_record_generator_test.rb +109 -0
  124. data/test/generators/devise_generator_test.rb +39 -0
  125. data/test/generators/install_generator_test.rb +13 -0
  126. data/test/generators/mongoid_generator_test.rb +23 -0
  127. data/test/generators/views_generator_test.rb +96 -0
  128. data/test/helpers/devise_helper_test.rb +52 -0
  129. data/test/integration/authenticatable_test.rb +729 -0
  130. data/test/integration/confirmable_test.rb +324 -0
  131. data/test/integration/database_authenticatable_test.rb +84 -0
  132. data/test/integration/http_authenticatable_test.rb +105 -0
  133. data/test/integration/lockable_test.rb +239 -0
  134. data/test/integration/omniauthable_test.rb +133 -0
  135. data/test/integration/recoverable_test.rb +334 -0
  136. data/test/integration/registerable_test.rb +359 -0
  137. data/test/integration/rememberable_test.rb +167 -0
  138. data/test/integration/timeoutable_test.rb +189 -0
  139. data/test/integration/trackable_test.rb +92 -0
  140. data/test/mailers/confirmation_instructions_test.rb +115 -0
  141. data/test/mailers/reset_password_instructions_test.rb +96 -0
  142. data/test/mailers/unlock_instructions_test.rb +91 -0
  143. data/test/mapping_test.rb +127 -0
  144. data/test/models/authenticatable_test.rb +13 -0
  145. data/test/models/confirmable_test.rb +454 -0
  146. data/test/models/database_authenticatable_test.rb +249 -0
  147. data/test/models/lockable_test.rb +322 -0
  148. data/test/models/omniauthable_test.rb +7 -0
  149. data/test/models/recoverable_test.rb +196 -0
  150. data/test/models/registerable_test.rb +7 -0
  151. data/test/models/rememberable_test.rb +198 -0
  152. data/test/models/serializable_test.rb +49 -0
  153. data/test/models/timeoutable_test.rb +51 -0
  154. data/test/models/trackable_test.rb +41 -0
  155. data/test/models/validatable_test.rb +127 -0
  156. data/test/models_test.rb +144 -0
  157. data/test/omniauth/config_test.rb +57 -0
  158. data/test/omniauth/url_helpers_test.rb +54 -0
  159. data/test/orm/active_record.rb +10 -0
  160. data/test/orm/mongoid.rb +13 -0
  161. data/test/parameter_sanitizer_test.rb +81 -0
  162. data/test/rails_app/Rakefile +6 -0
  163. data/test/rails_app/app/active_record/admin.rb +6 -0
  164. data/test/rails_app/app/active_record/shim.rb +2 -0
  165. data/test/rails_app/app/active_record/user.rb +6 -0
  166. data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
  167. data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
  168. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  169. data/test/rails_app/app/controllers/admins_controller.rb +11 -0
  170. data/test/rails_app/app/controllers/application_controller.rb +12 -0
  171. data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
  172. data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -0
  173. data/test/rails_app/app/controllers/home_controller.rb +25 -0
  174. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  175. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  176. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  177. data/test/rails_app/app/controllers/users_controller.rb +31 -0
  178. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  179. data/test/rails_app/app/mailers/users/mailer.rb +12 -0
  180. data/test/rails_app/app/mongoid/admin.rb +29 -0
  181. data/test/rails_app/app/mongoid/shim.rb +23 -0
  182. data/test/rails_app/app/mongoid/user.rb +39 -0
  183. data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
  184. data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
  185. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  186. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  187. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  188. data/test/rails_app/app/views/home/index.html.erb +1 -0
  189. data/test/rails_app/app/views/home/join.html.erb +1 -0
  190. data/test/rails_app/app/views/home/private.html.erb +1 -0
  191. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  192. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  193. data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
  194. data/test/rails_app/app/views/users/index.html.erb +1 -0
  195. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  196. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  197. data/test/rails_app/bin/bundle +3 -0
  198. data/test/rails_app/bin/rails +4 -0
  199. data/test/rails_app/bin/rake +4 -0
  200. data/test/rails_app/config.ru +4 -0
  201. data/test/rails_app/config/application.rb +40 -0
  202. data/test/rails_app/config/boot.rb +14 -0
  203. data/test/rails_app/config/database.yml +18 -0
  204. data/test/rails_app/config/environment.rb +5 -0
  205. data/test/rails_app/config/environments/development.rb +30 -0
  206. data/test/rails_app/config/environments/production.rb +80 -0
  207. data/test/rails_app/config/environments/test.rb +36 -0
  208. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  209. data/test/rails_app/config/initializers/devise.rb +183 -0
  210. data/test/rails_app/config/initializers/inflections.rb +2 -0
  211. data/test/rails_app/config/initializers/secret_token.rb +8 -0
  212. data/test/rails_app/config/initializers/session_store.rb +1 -0
  213. data/test/rails_app/config/routes.rb +122 -0
  214. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
  215. data/test/rails_app/db/schema.rb +55 -0
  216. data/test/rails_app/lib/shared_admin.rb +17 -0
  217. data/test/rails_app/lib/shared_user.rb +29 -0
  218. data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
  219. data/test/rails_app/public/404.html +26 -0
  220. data/test/rails_app/public/422.html +26 -0
  221. data/test/rails_app/public/500.html +26 -0
  222. data/test/rails_app/public/favicon.ico +0 -0
  223. data/test/routes_test.rb +264 -0
  224. data/test/support/action_controller/record_identifier.rb +10 -0
  225. data/test/support/assertions.rb +39 -0
  226. data/test/support/helpers.rb +70 -0
  227. data/test/support/integration.rb +92 -0
  228. data/test/support/locale/en.yml +8 -0
  229. data/test/support/mongoid.yml +6 -0
  230. data/test/support/webrat/integrations/rails.rb +24 -0
  231. data/test/test_helper.rb +29 -0
  232. data/test/test_helpers_test.rb +163 -0
  233. data/test/test_models.rb +33 -0
  234. metadata +474 -0
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ require 'rdoc/task'
5
+
6
+ desc 'Default: run tests for all ORMs.'
7
+ task default: :test
8
+
9
+ desc 'Run Devise tests for all ORMs.'
10
+ task :pre_commit do
11
+ Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
12
+ orm = File.basename(file).split(".").first
13
+ # "Some day, my son, rake's inner wisdom will reveal itself. Until then,
14
+ # take this `system` -- may its brute force protect you well."
15
+ exit 1 unless system "rake test DEVISE_ORM=#{orm}"
16
+ end
17
+ end
18
+
19
+ desc 'Run Devise unit tests.'
20
+ Rake::TestTask.new(:test) do |t|
21
+ t.libs << 'lib'
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = true
25
+ t.warning = false
26
+ end
27
+
28
+ desc 'Generate documentation for Devise.'
29
+ Rake::RDocTask.new(:rdoc) do |rdoc|
30
+ rdoc.rdoc_dir = 'rdoc'
31
+ rdoc.title = 'Devise'
32
+ rdoc.options << '--line-numbers' << '--inline-source'
33
+ rdoc.rdoc_files.include('README.md')
34
+ rdoc.rdoc_files.include('lib/**/*.rb')
35
+ end
@@ -0,0 +1,47 @@
1
+ class Devise::ConfirmationsController < DeviseController
2
+ # GET /resource/confirmation/new
3
+ def new
4
+ self.resource = resource_class.new
5
+ end
6
+
7
+ # POST /resource/confirmation
8
+ def create
9
+ self.resource = resource_class.send_confirmation_instructions(resource_params)
10
+ yield resource if block_given?
11
+
12
+ if successfully_sent?(resource)
13
+ respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))
14
+ else
15
+ respond_with(resource)
16
+ end
17
+ end
18
+
19
+ # GET /resource/confirmation?confirmation_token=abcdef
20
+ def show
21
+ self.resource = resource_class.confirm_by_token(params[:confirmation_token])
22
+ yield resource if block_given?
23
+
24
+ if resource.errors.empty?
25
+ set_flash_message(:notice, :confirmed) if is_flashing_format?
26
+ respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
27
+ else
28
+ respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
29
+ end
30
+ end
31
+
32
+ protected
33
+
34
+ # The path used after resending confirmation instructions.
35
+ def after_resending_confirmation_instructions_path_for(resource_name)
36
+ new_session_path(resource_name) if is_navigational_format?
37
+ end
38
+
39
+ # The path used after confirmation.
40
+ def after_confirmation_path_for(resource_name, resource)
41
+ if signed_in?(resource_name)
42
+ signed_in_root_path(resource)
43
+ else
44
+ new_session_path(resource_name)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ class Devise::OmniauthCallbacksController < DeviseController
2
+ prepend_before_filter { request.env["devise.skip_timeout"] = true }
3
+
4
+ def passthru
5
+ render status: 404, text: "Not found. Authentication passthru."
6
+ end
7
+
8
+ def failure
9
+ set_flash_message :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message
10
+ redirect_to after_omniauth_failure_path_for(resource_name)
11
+ end
12
+
13
+ protected
14
+
15
+ def failed_strategy
16
+ env["omniauth.error.strategy"]
17
+ end
18
+
19
+ def failure_message
20
+ exception = env["omniauth.error"]
21
+ error = exception.error_reason if exception.respond_to?(:error_reason)
22
+ error ||= exception.error if exception.respond_to?(:error)
23
+ error ||= env["omniauth.error.type"].to_s
24
+ error.to_s.humanize if error
25
+ end
26
+
27
+ def after_omniauth_failure_path_for(scope)
28
+ new_session_path(scope)
29
+ end
30
+ end
@@ -0,0 +1,70 @@
1
+ class Devise::PasswordsController < DeviseController
2
+ prepend_before_filter :require_no_authentication
3
+ # Render the #edit only if coming from a reset password email link
4
+ append_before_filter :assert_reset_token_passed, only: :edit
5
+
6
+ # GET /resource/password/new
7
+ def new
8
+ self.resource = resource_class.new
9
+ end
10
+
11
+ # POST /resource/password
12
+ def create
13
+ self.resource = resource_class.send_reset_password_instructions(resource_params)
14
+ yield resource if block_given?
15
+
16
+ if successfully_sent?(resource)
17
+ respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
18
+ else
19
+ respond_with(resource)
20
+ end
21
+ end
22
+
23
+ # GET /resource/password/edit?reset_password_token=abcdef
24
+ def edit
25
+ self.resource = resource_class.new
26
+ resource.reset_password_token = params[:reset_password_token]
27
+ end
28
+
29
+ # PUT /resource/password
30
+ def update
31
+ self.resource = resource_class.reset_password_by_token(resource_params)
32
+ yield resource if block_given?
33
+
34
+ if resource.errors.empty?
35
+ resource.unlock_access! if unlockable?(resource)
36
+ flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
37
+ set_flash_message(:notice, flash_message) if is_flashing_format?
38
+ sign_in(resource_name, resource)
39
+ respond_with resource, location: after_resetting_password_path_for(resource)
40
+ else
41
+ respond_with resource
42
+ end
43
+ end
44
+
45
+ protected
46
+ def after_resetting_password_path_for(resource)
47
+ after_sign_in_path_for(resource)
48
+ end
49
+
50
+ # The path used after sending reset password instructions
51
+ def after_sending_reset_password_instructions_path_for(resource_name)
52
+ new_session_path(resource_name) if is_navigational_format?
53
+ end
54
+
55
+ # Check if a reset_password_token is provided in the request
56
+ def assert_reset_token_passed
57
+ if params[:reset_password_token].blank?
58
+ set_flash_message(:alert, :no_token)
59
+ redirect_to new_session_path(resource_name)
60
+ end
61
+ end
62
+
63
+ # Check if proper Lockable module methods are present & unlock strategy
64
+ # allows to unlock resource on password reset
65
+ def unlockable?(resource)
66
+ resource.respond_to?(:unlock_access!) &&
67
+ resource.respond_to?(:unlock_strategy_enabled?) &&
68
+ resource.unlock_strategy_enabled?(:email)
69
+ end
70
+ end
@@ -0,0 +1,148 @@
1
+ class Devise::RegistrationsController < DeviseController
2
+ prepend_before_filter :require_no_authentication, only: [ :new, :create, :cancel ]
3
+ prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy]
4
+
5
+ # GET /resource/sign_up
6
+ def new
7
+ build_resource({})
8
+ @validatable = devise_mapping.validatable?
9
+ if @validatable
10
+ @minimum_password_length = resource_class.password_length.min
11
+ end
12
+ respond_with self.resource
13
+ end
14
+
15
+ # POST /resource
16
+ def create
17
+ build_resource(sign_up_params)
18
+
19
+ resource_saved = resource.save
20
+ yield resource if block_given?
21
+ if resource_saved
22
+ if resource.active_for_authentication?
23
+ set_flash_message :notice, :signed_up if is_flashing_format?
24
+ sign_up(resource_name, resource)
25
+ respond_with resource, location: after_sign_up_path_for(resource)
26
+ else
27
+ set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
28
+ expire_data_after_sign_in!
29
+ respond_with resource, location: after_inactive_sign_up_path_for(resource)
30
+ end
31
+ else
32
+ clean_up_passwords resource
33
+ @validatable = devise_mapping.validatable?
34
+ if @validatable
35
+ @minimum_password_length = resource_class.password_length.min
36
+ end
37
+ respond_with resource
38
+ end
39
+ end
40
+
41
+ # GET /resource/edit
42
+ def edit
43
+ render :edit
44
+ end
45
+
46
+ # PUT /resource
47
+ # We need to use a copy of the resource because we don't want to change
48
+ # the current user in place.
49
+ def update
50
+ self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
51
+ prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
52
+
53
+ resource_updated = update_resource(resource, account_update_params)
54
+ yield resource if block_given?
55
+ if resource_updated
56
+ if is_flashing_format?
57
+ flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
58
+ :update_needs_confirmation : :updated
59
+ set_flash_message :notice, flash_key
60
+ end
61
+ sign_in resource_name, resource, bypass: true
62
+ respond_with resource, location: after_update_path_for(resource)
63
+ else
64
+ clean_up_passwords resource
65
+ respond_with resource
66
+ end
67
+ end
68
+
69
+ # DELETE /resource
70
+ def destroy
71
+ resource.destroy
72
+ Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
73
+ set_flash_message :notice, :destroyed if is_flashing_format?
74
+ yield resource if block_given?
75
+ respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
76
+ end
77
+
78
+ # GET /resource/cancel
79
+ # Forces the session data which is usually expired after sign
80
+ # in to be expired now. This is useful if the user wants to
81
+ # cancel oauth signing in/up in the middle of the process,
82
+ # removing all OAuth session data.
83
+ def cancel
84
+ expire_data_after_sign_in!
85
+ redirect_to new_registration_path(resource_name)
86
+ end
87
+
88
+ protected
89
+
90
+ def update_needs_confirmation?(resource, previous)
91
+ resource.respond_to?(:pending_reconfirmation?) &&
92
+ resource.pending_reconfirmation? &&
93
+ previous != resource.unconfirmed_email
94
+ end
95
+
96
+ # By default we want to require a password checks on update.
97
+ # You can overwrite this method in your own RegistrationsController.
98
+ def update_resource(resource, params)
99
+ resource.update_with_password(params)
100
+ end
101
+
102
+ # Build a devise resource passing in the session. Useful to move
103
+ # temporary session data to the newly created user.
104
+ def build_resource(hash=nil)
105
+ self.resource = resource_class.new_with_session(hash || {}, session)
106
+ end
107
+
108
+ # Signs in a user on sign up. You can overwrite this method in your own
109
+ # RegistrationsController.
110
+ def sign_up(resource_name, resource)
111
+ sign_in(resource_name, resource)
112
+ end
113
+
114
+ # The path used after sign up. You need to overwrite this method
115
+ # in your own RegistrationsController.
116
+ def after_sign_up_path_for(resource)
117
+ after_sign_in_path_for(resource)
118
+ end
119
+
120
+ # The path used after sign up for inactive accounts. You need to overwrite
121
+ # this method in your own RegistrationsController.
122
+ def after_inactive_sign_up_path_for(resource)
123
+ scope = Devise::Mapping.find_scope!(resource)
124
+ router_name = Devise.mappings[scope].router_name
125
+ context = router_name ? send(router_name) : self
126
+ context.respond_to?(:root_path) ? context.root_path : "/"
127
+ end
128
+
129
+ # The default url to be used after updating a resource. You need to overwrite
130
+ # this method in your own RegistrationsController.
131
+ def after_update_path_for(resource)
132
+ signed_in_root_path(resource)
133
+ end
134
+
135
+ # Authenticates the current scope and gets the current resource from the session.
136
+ def authenticate_scope!
137
+ send(:"authenticate_#{resource_name}!", force: true)
138
+ self.resource = send(:"current_#{resource_name}")
139
+ end
140
+
141
+ def sign_up_params
142
+ devise_parameter_sanitizer.sanitize(:sign_up)
143
+ end
144
+
145
+ def account_update_params
146
+ devise_parameter_sanitizer.sanitize(:account_update)
147
+ end
148
+ end
@@ -0,0 +1,76 @@
1
+ class Devise::SessionsController < DeviseController
2
+ prepend_before_filter :require_no_authentication, only: [ :new, :create ]
3
+ prepend_before_filter :allow_params_authentication!, only: :create
4
+ prepend_before_filter :verify_signed_out_user, only: :destroy
5
+ prepend_before_filter only: [ :create, :destroy ] { request.env["devise.skip_timeout"] = true }
6
+
7
+ # GET /resource/sign_in
8
+ def new
9
+ self.resource = resource_class.new(sign_in_params)
10
+ clean_up_passwords(resource)
11
+ respond_with(resource, serialize_options(resource))
12
+ end
13
+
14
+ # POST /resource/sign_in
15
+ def create
16
+ self.resource = warden.authenticate!(auth_options)
17
+ set_flash_message(:notice, :signed_in) if is_flashing_format?
18
+ sign_in(resource_name, resource)
19
+ yield resource if block_given?
20
+ respond_with resource, location: after_sign_in_path_for(resource)
21
+ end
22
+
23
+ # DELETE /resource/sign_out
24
+ def destroy
25
+ signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
26
+ set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
27
+ yield if block_given?
28
+ respond_to_on_destroy
29
+ end
30
+
31
+ protected
32
+
33
+ def sign_in_params
34
+ devise_parameter_sanitizer.sanitize(:sign_in)
35
+ end
36
+
37
+ def serialize_options(resource)
38
+ methods = resource_class.authentication_keys.dup
39
+ methods = methods.keys if methods.is_a?(Hash)
40
+ methods << :password if resource.respond_to?(:password)
41
+ { methods: methods, only: [:password] }
42
+ end
43
+
44
+ def auth_options
45
+ { scope: resource_name, recall: "#{controller_path}#new" }
46
+ end
47
+
48
+ private
49
+
50
+ # Check if there is no signed in user before doing the sign out.
51
+ #
52
+ # If there is no signed in user, it will set the flash message and redirect
53
+ # to the after_sign_out path.
54
+ def verify_signed_out_user
55
+ if all_signed_out?
56
+ set_flash_message :notice, :already_signed_out if is_flashing_format?
57
+
58
+ respond_to_on_destroy
59
+ end
60
+ end
61
+
62
+ def all_signed_out?
63
+ users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
64
+
65
+ users.all?(&:blank?)
66
+ end
67
+
68
+ def respond_to_on_destroy
69
+ # We actually need to hardcode this as Rails default responder doesn't
70
+ # support returning empty response on GET request
71
+ respond_to do |format|
72
+ format.all { head :no_content }
73
+ format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,46 @@
1
+ class Devise::UnlocksController < DeviseController
2
+ prepend_before_filter :require_no_authentication
3
+
4
+ # GET /resource/unlock/new
5
+ def new
6
+ self.resource = resource_class.new
7
+ end
8
+
9
+ # POST /resource/unlock
10
+ def create
11
+ self.resource = resource_class.send_unlock_instructions(resource_params)
12
+ yield resource if block_given?
13
+
14
+ if successfully_sent?(resource)
15
+ respond_with({}, location: after_sending_unlock_instructions_path_for(resource))
16
+ else
17
+ respond_with(resource)
18
+ end
19
+ end
20
+
21
+ # GET /resource/unlock?unlock_token=abcdef
22
+ def show
23
+ self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
24
+ yield resource if block_given?
25
+
26
+ if resource.errors.empty?
27
+ set_flash_message :notice, :unlocked if is_flashing_format?
28
+ respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
29
+ else
30
+ respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ # The path used after sending unlock password instructions
37
+ def after_sending_unlock_instructions_path_for(resource)
38
+ new_session_path(resource) if is_navigational_format?
39
+ end
40
+
41
+ # The path used after unlocking the resource
42
+ def after_unlock_path_for(resource)
43
+ new_session_path(resource) if is_navigational_format?
44
+ end
45
+
46
+ end