devbootsrap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +31 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/app/controllers/devise/confirmations_controller.rb +47 -0
  8. data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
  9. data/app/controllers/devise/passwords_controller.rb +70 -0
  10. data/app/controllers/devise/registrations_controller.rb +137 -0
  11. data/app/controllers/devise/sessions_controller.rb +53 -0
  12. data/app/controllers/devise/unlocks_controller.rb +46 -0
  13. data/app/controllers/devise_controller.rb +176 -0
  14. data/app/helpers/devise_helper.rb +25 -0
  15. data/app/mailers/devise/mailer.rb +20 -0
  16. data/app/views/devise/confirmations/new.html.erb +12 -0
  17. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  18. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  19. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  20. data/app/views/devise/passwords/edit.html.erb +16 -0
  21. data/app/views/devise/passwords/new.html.erb +12 -0
  22. data/app/views/devise/registrations/edit.html.erb +29 -0
  23. data/app/views/devise/registrations/new.html.erb +18 -0
  24. data/app/views/devise/sessions/new.html.erb +17 -0
  25. data/app/views/devise/shared/_links.erb +25 -0
  26. data/app/views/devise/unlocks/new.html.erb +12 -0
  27. data/config/locales/en.yml +59 -0
  28. data/devbootsrap.gemspec +29 -0
  29. data/gemfiles/Gemfile.rails-3.2-stable +29 -0
  30. data/gemfiles/Gemfile.rails-4.0-stable +29 -0
  31. data/gemfiles/Gemfile.rails-head +29 -0
  32. data/lib/devbootsrap.rb +5 -0
  33. data/lib/devbootsrap/version.rb +3 -0
  34. data/lib/devise.rb +491 -0
  35. data/lib/devise/controllers/helpers.rb +213 -0
  36. data/lib/devise/controllers/rememberable.rb +47 -0
  37. data/lib/devise/controllers/scoped_views.rb +17 -0
  38. data/lib/devise/controllers/sign_in_out.rb +103 -0
  39. data/lib/devise/controllers/store_location.rb +50 -0
  40. data/lib/devise/controllers/url_helpers.rb +67 -0
  41. data/lib/devise/delegator.rb +16 -0
  42. data/lib/devise/failure_app.rb +205 -0
  43. data/lib/devise/hooks/activatable.rb +11 -0
  44. data/lib/devise/hooks/csrf_cleaner.rb +5 -0
  45. data/lib/devise/hooks/forgetable.rb +9 -0
  46. data/lib/devise/hooks/lockable.rb +7 -0
  47. data/lib/devise/hooks/proxy.rb +21 -0
  48. data/lib/devise/hooks/rememberable.rb +7 -0
  49. data/lib/devise/hooks/timeoutable.rb +28 -0
  50. data/lib/devise/hooks/trackable.rb +9 -0
  51. data/lib/devise/mailers/helpers.rb +90 -0
  52. data/lib/devise/mapping.rb +172 -0
  53. data/lib/devise/models.rb +119 -0
  54. data/lib/devise/models/authenticatable.rb +284 -0
  55. data/lib/devise/models/confirmable.rb +295 -0
  56. data/lib/devise/models/database_authenticatable.rb +164 -0
  57. data/lib/devise/models/lockable.rb +196 -0
  58. data/lib/devise/models/omniauthable.rb +27 -0
  59. data/lib/devise/models/recoverable.rb +131 -0
  60. data/lib/devise/models/registerable.rb +25 -0
  61. data/lib/devise/models/rememberable.rb +129 -0
  62. data/lib/devise/models/timeoutable.rb +49 -0
  63. data/lib/devise/models/trackable.rb +35 -0
  64. data/lib/devise/models/validatable.rb +66 -0
  65. data/lib/devise/modules.rb +28 -0
  66. data/lib/devise/omniauth.rb +28 -0
  67. data/lib/devise/omniauth/config.rb +45 -0
  68. data/lib/devise/omniauth/url_helpers.rb +18 -0
  69. data/lib/devise/orm/active_record.rb +3 -0
  70. data/lib/devise/orm/mongoid.rb +3 -0
  71. data/lib/devise/parameter_filter.rb +40 -0
  72. data/lib/devise/parameter_sanitizer.rb +99 -0
  73. data/lib/devise/rails.rb +56 -0
  74. data/lib/devise/rails/routes.rb +496 -0
  75. data/lib/devise/rails/warden_compat.rb +22 -0
  76. data/lib/devise/strategies/authenticatable.rb +167 -0
  77. data/lib/devise/strategies/base.rb +20 -0
  78. data/lib/devise/strategies/database_authenticatable.rb +23 -0
  79. data/lib/devise/strategies/rememberable.rb +55 -0
  80. data/lib/devise/test_helpers.rb +132 -0
  81. data/lib/devise/time_inflector.rb +14 -0
  82. data/lib/devise/token_generator.rb +70 -0
  83. data/lib/devise/version.rb +3 -0
  84. data/lib/generators/active_record/devise_generator.rb +73 -0
  85. data/lib/generators/active_record/templates/migration.rb +18 -0
  86. data/lib/generators/active_record/templates/migration_existing.rb +25 -0
  87. data/lib/generators/devise/devise_generator.rb +26 -0
  88. data/lib/generators/devise/install_generator.rb +29 -0
  89. data/lib/generators/devise/orm_helpers.rb +51 -0
  90. data/lib/generators/devise/views_generator.rb +135 -0
  91. data/lib/generators/mongoid/devise_generator.rb +55 -0
  92. data/lib/generators/templates/README +35 -0
  93. data/lib/generators/templates/devise.rb +260 -0
  94. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  95. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  96. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  97. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +16 -0
  98. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  99. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  100. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +27 -0
  101. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  102. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  103. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +16 -0
  104. data/test/controllers/custom_registrations_controller_test.rb +35 -0
  105. data/test/controllers/custom_strategy_test.rb +62 -0
  106. data/test/controllers/helpers_test.rb +276 -0
  107. data/test/controllers/internal_helpers_test.rb +123 -0
  108. data/test/controllers/passwords_controller_test.rb +31 -0
  109. data/test/controllers/sessions_controller_test.rb +103 -0
  110. data/test/controllers/url_helpers_test.rb +59 -0
  111. data/test/delegator_test.rb +19 -0
  112. data/test/devise_test.rb +94 -0
  113. data/test/failure_app_test.rb +232 -0
  114. data/test/generators/active_record_generator_test.rb +103 -0
  115. data/test/generators/devise_generator_test.rb +39 -0
  116. data/test/generators/install_generator_test.rb +13 -0
  117. data/test/generators/mongoid_generator_test.rb +23 -0
  118. data/test/generators/views_generator_test.rb +96 -0
  119. data/test/helpers/devise_helper_test.rb +51 -0
  120. data/test/integration/authenticatable_test.rb +713 -0
  121. data/test/integration/confirmable_test.rb +284 -0
  122. data/test/integration/database_authenticatable_test.rb +84 -0
  123. data/test/integration/http_authenticatable_test.rb +105 -0
  124. data/test/integration/lockable_test.rb +239 -0
  125. data/test/integration/omniauthable_test.rb +133 -0
  126. data/test/integration/recoverable_test.rb +334 -0
  127. data/test/integration/registerable_test.rb +349 -0
  128. data/test/integration/rememberable_test.rb +167 -0
  129. data/test/integration/timeoutable_test.rb +183 -0
  130. data/test/integration/trackable_test.rb +92 -0
  131. data/test/mailers/confirmation_instructions_test.rb +115 -0
  132. data/test/mailers/reset_password_instructions_test.rb +96 -0
  133. data/test/mailers/unlock_instructions_test.rb +91 -0
  134. data/test/mapping_test.rb +127 -0
  135. data/test/models/authenticatable_test.rb +13 -0
  136. data/test/models/confirmable_test.rb +454 -0
  137. data/test/models/database_authenticatable_test.rb +249 -0
  138. data/test/models/lockable_test.rb +316 -0
  139. data/test/models/omniauthable_test.rb +7 -0
  140. data/test/models/recoverable_test.rb +184 -0
  141. data/test/models/registerable_test.rb +7 -0
  142. data/test/models/rememberable_test.rb +183 -0
  143. data/test/models/serializable_test.rb +49 -0
  144. data/test/models/timeoutable_test.rb +51 -0
  145. data/test/models/trackable_test.rb +13 -0
  146. data/test/models/validatable_test.rb +127 -0
  147. data/test/models_test.rb +144 -0
  148. data/test/omniauth/config_test.rb +57 -0
  149. data/test/omniauth/url_helpers_test.rb +54 -0
  150. data/test/orm/active_record.rb +10 -0
  151. data/test/orm/mongoid.rb +13 -0
  152. data/test/parameter_sanitizer_test.rb +81 -0
  153. data/test/rails_app/Rakefile +6 -0
  154. data/test/rails_app/app/active_record/admin.rb +6 -0
  155. data/test/rails_app/app/active_record/shim.rb +2 -0
  156. data/test/rails_app/app/active_record/user.rb +6 -0
  157. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  158. data/test/rails_app/app/controllers/admins_controller.rb +11 -0
  159. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  160. data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -0
  161. data/test/rails_app/app/controllers/home_controller.rb +25 -0
  162. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  163. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  164. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  165. data/test/rails_app/app/controllers/users_controller.rb +31 -0
  166. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  167. data/test/rails_app/app/mailers/users/mailer.rb +12 -0
  168. data/test/rails_app/app/mongoid/admin.rb +29 -0
  169. data/test/rails_app/app/mongoid/shim.rb +23 -0
  170. data/test/rails_app/app/mongoid/user.rb +39 -0
  171. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  172. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  173. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  174. data/test/rails_app/app/views/home/index.html.erb +1 -0
  175. data/test/rails_app/app/views/home/join.html.erb +1 -0
  176. data/test/rails_app/app/views/home/private.html.erb +1 -0
  177. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  178. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  179. data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
  180. data/test/rails_app/app/views/users/index.html.erb +1 -0
  181. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  182. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  183. data/test/rails_app/bin/bundle +3 -0
  184. data/test/rails_app/bin/rails +4 -0
  185. data/test/rails_app/bin/rake +4 -0
  186. data/test/rails_app/config.ru +4 -0
  187. data/test/rails_app/config/application.rb +40 -0
  188. data/test/rails_app/config/boot.rb +14 -0
  189. data/test/rails_app/config/database.yml +18 -0
  190. data/test/rails_app/config/environment.rb +5 -0
  191. data/test/rails_app/config/environments/development.rb +30 -0
  192. data/test/rails_app/config/environments/production.rb +80 -0
  193. data/test/rails_app/config/environments/test.rb +36 -0
  194. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  195. data/test/rails_app/config/initializers/devise.rb +181 -0
  196. data/test/rails_app/config/initializers/inflections.rb +2 -0
  197. data/test/rails_app/config/initializers/secret_token.rb +8 -0
  198. data/test/rails_app/config/initializers/session_store.rb +1 -0
  199. data/test/rails_app/config/routes.rb +108 -0
  200. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
  201. data/test/rails_app/db/schema.rb +55 -0
  202. data/test/rails_app/lib/shared_admin.rb +17 -0
  203. data/test/rails_app/lib/shared_user.rb +29 -0
  204. data/test/rails_app/public/404.html +26 -0
  205. data/test/rails_app/public/422.html +26 -0
  206. data/test/rails_app/public/500.html +26 -0
  207. data/test/rails_app/public/favicon.ico +0 -0
  208. data/test/routes_test.rb +262 -0
  209. data/test/support/action_controller/record_identifier.rb +10 -0
  210. data/test/support/assertions.rb +40 -0
  211. data/test/support/helpers.rb +70 -0
  212. data/test/support/integration.rb +92 -0
  213. data/test/support/locale/en.yml +8 -0
  214. data/test/support/mongoid.yml +6 -0
  215. data/test/support/webrat/integrations/rails.rb +24 -0
  216. data/test/test_helper.rb +27 -0
  217. data/test/test_helpers_test.rb +173 -0
  218. data/test/test_models.rb +33 -0
  219. metadata +480 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b546c5b0fed21e4497c59ec6ba484e41313be864
4
+ data.tar.gz: 6663447f3c73507cfd8f50be12774815643d70f9
5
+ SHA512:
6
+ metadata.gz: 3692340299e3150b36ad516cf85ea9f502ce16993fdd4739bdc7197d92ee63a4f2cc2ddbcc2eda654b03e150f86eac40e828b45dbf3a5b525d436694b59f863d
7
+ data.tar.gz: 33f34a407a96e3a0302d9d33a98f0ad44243e5d99c83fdf3cde22d4410440a5b9f7a88d4c7f6c6e7ad43fe4288174c46e2479cfbe5a0d2745158900a23cba51a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,31 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in devbootsrap.gemspec
4
+ gemspec
5
+
6
+ gem "rails", "~> 4.0.0"
7
+ gem "omniauth", "~> 1.0.0"
8
+ gem "omniauth-oauth2", "~> 1.0.0"
9
+ gem "rdoc"
10
+
11
+ group :test do
12
+ gem "omniauth-facebook"
13
+ gem "omniauth-openid", "~> 1.0.1"
14
+ gem "webrat", "0.7.3", require: false
15
+ gem "mocha", "~> 1.0.0", require: false
16
+ end
17
+
18
+ platforms :jruby do
19
+ gem "activerecord-jdbc-adapter"
20
+ gem "activerecord-jdbcsqlite3-adapter"
21
+ gem "jruby-openssl"
22
+ end
23
+
24
+ platforms :ruby do
25
+ gem "sqlite3"
26
+ end
27
+
28
+ group :mongoid do
29
+ gem "mongoid", github: "mongoid/mongoid", branch: "master"
30
+ end
31
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ratnakar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Devbootsrap
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'devbootsrap'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install devbootsrap
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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?
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,137 @@
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
+ respond_with self.resource
9
+ end
10
+
11
+ # POST /resource
12
+ def create
13
+ build_resource(sign_up_params)
14
+
15
+ resource_saved = resource.save
16
+ yield resource if block_given?
17
+ if resource_saved
18
+ if resource.active_for_authentication?
19
+ set_flash_message :notice, :signed_up if is_flashing_format?
20
+ sign_up(resource_name, resource)
21
+ respond_with resource, location: after_sign_up_path_for(resource)
22
+ else
23
+ set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
24
+ expire_data_after_sign_in!
25
+ respond_with resource, location: after_inactive_sign_up_path_for(resource)
26
+ end
27
+ else
28
+ clean_up_passwords resource
29
+ respond_with resource
30
+ end
31
+ end
32
+
33
+ # GET /resource/edit
34
+ def edit
35
+ render :edit
36
+ end
37
+
38
+ # PUT /resource
39
+ # We need to use a copy of the resource because we don't want to change
40
+ # the current user in place.
41
+ def update
42
+ self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
43
+ prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
44
+
45
+ resource_updated = update_resource(resource, account_update_params)
46
+ yield resource if block_given?
47
+ if resource_updated
48
+ if is_flashing_format?
49
+ flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
50
+ :update_needs_confirmation : :updated
51
+ set_flash_message :notice, flash_key
52
+ end
53
+ sign_in resource_name, resource, bypass: true
54
+ respond_with resource, location: after_update_path_for(resource)
55
+ else
56
+ clean_up_passwords resource
57
+ respond_with resource
58
+ end
59
+ end
60
+
61
+ # DELETE /resource
62
+ def destroy
63
+ resource.destroy
64
+ Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
65
+ set_flash_message :notice, :destroyed if is_flashing_format?
66
+ yield resource if block_given?
67
+ respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
68
+ end
69
+
70
+ # GET /resource/cancel
71
+ # Forces the session data which is usually expired after sign
72
+ # in to be expired now. This is useful if the user wants to
73
+ # cancel oauth signing in/up in the middle of the process,
74
+ # removing all OAuth session data.
75
+ def cancel
76
+ expire_data_after_sign_in!
77
+ redirect_to new_registration_path(resource_name)
78
+ end
79
+
80
+ protected
81
+
82
+ def update_needs_confirmation?(resource, previous)
83
+ resource.respond_to?(:pending_reconfirmation?) &&
84
+ resource.pending_reconfirmation? &&
85
+ previous != resource.unconfirmed_email
86
+ end
87
+
88
+ # By default we want to require a password checks on update.
89
+ # You can overwrite this method in your own RegistrationsController.
90
+ def update_resource(resource, params)
91
+ resource.update_with_password(params)
92
+ end
93
+
94
+ # Build a devise resource passing in the session. Useful to move
95
+ # temporary session data to the newly created user.
96
+ def build_resource(hash=nil)
97
+ self.resource = resource_class.new_with_session(hash || {}, session)
98
+ end
99
+
100
+ # Signs in a user on sign up. You can overwrite this method in your own
101
+ # RegistrationsController.
102
+ def sign_up(resource_name, resource)
103
+ sign_in(resource_name, resource)
104
+ end
105
+
106
+ # The path used after sign up. You need to overwrite this method
107
+ # in your own RegistrationsController.
108
+ def after_sign_up_path_for(resource)
109
+ after_sign_in_path_for(resource)
110
+ end
111
+
112
+ # The path used after sign up for inactive accounts. You need to overwrite
113
+ # this method in your own RegistrationsController.
114
+ def after_inactive_sign_up_path_for(resource)
115
+ respond_to?(:root_path) ? root_path : "/"
116
+ end
117
+
118
+ # The default url to be used after updating a resource. You need to overwrite
119
+ # this method in your own RegistrationsController.
120
+ def after_update_path_for(resource)
121
+ signed_in_root_path(resource)
122
+ end
123
+
124
+ # Authenticates the current scope and gets the current resource from the session.
125
+ def authenticate_scope!
126
+ send(:"authenticate_#{resource_name}!", force: true)
127
+ self.resource = send(:"current_#{resource_name}")
128
+ end
129
+
130
+ def sign_up_params
131
+ devise_parameter_sanitizer.sanitize(:sign_up)
132
+ end
133
+
134
+ def account_update_params
135
+ devise_parameter_sanitizer.sanitize(:account_update)
136
+ end
137
+ end
@@ -0,0 +1,53 @@
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 only: [ :create, :destroy ] { request.env["devise.skip_timeout"] = true }
5
+
6
+ # GET /resource/sign_in
7
+ def new
8
+ self.resource = resource_class.new(sign_in_params)
9
+ clean_up_passwords(resource)
10
+ respond_with(resource, serialize_options(resource))
11
+ end
12
+
13
+ # POST /resource/sign_in
14
+ def create
15
+ self.resource = warden.authenticate!(auth_options)
16
+ set_flash_message(:notice, :signed_in) if is_flashing_format?
17
+ sign_in(resource_name, resource)
18
+ yield resource if block_given?
19
+ respond_with resource, location: after_sign_in_path_for(resource)
20
+ end
21
+
22
+ # DELETE /resource/sign_out
23
+ def destroy
24
+ redirect_path = after_sign_out_path_for(resource_name)
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
+
29
+ # We actually need to hardcode this as Rails default responder doesn't
30
+ # support returning empty response on GET request
31
+ respond_to do |format|
32
+ format.all { head :no_content }
33
+ format.any(*navigational_formats) { redirect_to redirect_path }
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ def sign_in_params
40
+ devise_parameter_sanitizer.sanitize(:sign_in)
41
+ end
42
+
43
+ def serialize_options(resource)
44
+ methods = resource_class.authentication_keys.dup
45
+ methods = methods.keys if methods.is_a?(Hash)
46
+ methods << :password if resource.respond_to?(:password)
47
+ { methods: methods, only: [:password] }
48
+ end
49
+
50
+ def auth_options
51
+ { scope: resource_name, recall: "#{controller_path}#new" }
52
+ end
53
+ end