sorcery 0.9.0 → 0.10.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 (150) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -104
  3. data/CHANGELOG.md +22 -1
  4. data/Gemfile +2 -16
  5. data/README.md +124 -271
  6. data/Rakefile +2 -2
  7. data/gemfiles/{mongoid-rails40.gemfile → active_record-rails42.gemfile} +1 -3
  8. data/lib/generators/sorcery/helpers.rb +4 -4
  9. data/lib/generators/sorcery/install_generator.rb +25 -19
  10. data/lib/generators/sorcery/templates/initializer.rb +29 -53
  11. data/lib/generators/sorcery/templates/migration/activity_logging.rb +2 -2
  12. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +1 -1
  13. data/lib/generators/sorcery/templates/migration/core.rb +3 -3
  14. data/lib/generators/sorcery/templates/migration/external.rb +3 -3
  15. data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -2
  16. data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -2
  17. data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -2
  18. data/lib/sorcery/adapters/active_record_adapter.rb +7 -18
  19. data/lib/sorcery/controller/config.rb +20 -18
  20. data/lib/sorcery/controller/submodules/activity_logging.rb +7 -15
  21. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  22. data/lib/sorcery/controller/submodules/external.rb +23 -15
  23. data/lib/sorcery/controller/submodules/http_basic_auth.rb +16 -19
  24. data/lib/sorcery/controller/submodules/remember_me.rb +15 -10
  25. data/lib/sorcery/controller/submodules/session_timeout.rb +7 -8
  26. data/lib/sorcery/controller.rb +19 -21
  27. data/lib/sorcery/crypto_providers/aes256.rb +15 -15
  28. data/lib/sorcery/crypto_providers/bcrypt.rb +19 -21
  29. data/lib/sorcery/crypto_providers/common.rb +1 -1
  30. data/lib/sorcery/crypto_providers/md5.rb +5 -5
  31. data/lib/sorcery/crypto_providers/sha1.rb +5 -5
  32. data/lib/sorcery/crypto_providers/sha256.rb +2 -2
  33. data/lib/sorcery/crypto_providers/sha512.rb +3 -3
  34. data/lib/sorcery/engine.rb +3 -8
  35. data/lib/sorcery/model/config.rb +64 -49
  36. data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
  37. data/lib/sorcery/model/submodules/brute_force_protection.rb +23 -23
  38. data/lib/sorcery/model/submodules/external.rb +3 -7
  39. data/lib/sorcery/model/submodules/remember_me.rb +19 -7
  40. data/lib/sorcery/model/submodules/reset_password.rb +32 -36
  41. data/lib/sorcery/model/submodules/user_activation.rb +38 -50
  42. data/lib/sorcery/model/temporary_token.rb +2 -2
  43. data/lib/sorcery/model.rb +27 -31
  44. data/lib/sorcery/protocols/oauth.rb +3 -9
  45. data/lib/sorcery/protocols/oauth2.rb +0 -2
  46. data/lib/sorcery/providers/base.rb +4 -4
  47. data/lib/sorcery/providers/facebook.rb +17 -9
  48. data/lib/sorcery/providers/github.rb +12 -5
  49. data/lib/sorcery/providers/google.rb +3 -5
  50. data/lib/sorcery/providers/heroku.rb +6 -8
  51. data/lib/sorcery/providers/jira.rb +12 -17
  52. data/lib/sorcery/providers/linkedin.rb +6 -8
  53. data/lib/sorcery/providers/liveid.rb +4 -7
  54. data/lib/sorcery/providers/paypal.rb +60 -0
  55. data/lib/sorcery/providers/salesforce.rb +3 -5
  56. data/lib/sorcery/providers/slack.rb +45 -0
  57. data/lib/sorcery/providers/twitter.rb +4 -6
  58. data/lib/sorcery/providers/vk.rb +3 -5
  59. data/lib/sorcery/providers/wechat.rb +79 -0
  60. data/lib/sorcery/providers/xing.rb +8 -11
  61. data/lib/sorcery/test_helpers/internal/rails.rb +16 -8
  62. data/lib/sorcery/test_helpers/internal.rb +10 -10
  63. data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
  64. data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
  65. data/lib/sorcery/version.rb +1 -1
  66. data/lib/sorcery.rb +0 -28
  67. data/sorcery.gemspec +25 -27
  68. data/spec/active_record/user_activation_spec.rb +2 -3
  69. data/spec/active_record/user_activity_logging_spec.rb +2 -4
  70. data/spec/active_record/user_brute_force_protection_spec.rb +3 -4
  71. data/spec/active_record/user_oauth_spec.rb +3 -4
  72. data/spec/active_record/user_remember_me_spec.rb +3 -4
  73. data/spec/active_record/user_reset_password_spec.rb +2 -3
  74. data/spec/active_record/user_spec.rb +7 -7
  75. data/spec/controllers/controller_activity_logging_spec.rb +13 -24
  76. data/spec/controllers/controller_brute_force_protection_spec.rb +6 -8
  77. data/spec/controllers/controller_http_basic_auth_spec.rb +19 -20
  78. data/spec/controllers/controller_oauth2_spec.rb +142 -102
  79. data/spec/controllers/controller_oauth_spec.rb +86 -66
  80. data/spec/controllers/controller_remember_me_spec.rb +35 -30
  81. data/spec/controllers/controller_session_timeout_spec.rb +14 -15
  82. data/spec/controllers/controller_spec.rb +77 -111
  83. data/spec/orm/active_record.rb +1 -1
  84. data/spec/rails_app/app/active_record/authentication.rb +1 -1
  85. data/spec/rails_app/app/active_record/user.rb +2 -2
  86. data/spec/rails_app/app/controllers/sorcery_controller.rb +89 -24
  87. data/spec/rails_app/app/mailers/sorcery_mailer.rb +16 -17
  88. data/spec/rails_app/config/application.rb +7 -7
  89. data/spec/rails_app/config/boot.rb +1 -1
  90. data/spec/rails_app/config/environments/test.rb +1 -1
  91. data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
  92. data/spec/rails_app/config/initializers/session_store.rb +3 -3
  93. data/spec/rails_app/config/routes.rb +11 -1
  94. data/spec/rails_app/config.ru +1 -1
  95. data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +4 -4
  96. data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +8 -8
  97. data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +5 -5
  98. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +5 -5
  99. data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +3 -3
  100. data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +6 -6
  101. data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +5 -5
  102. data/spec/shared_examples/user_activation_shared_examples.rb +99 -58
  103. data/spec/shared_examples/user_activity_logging_shared_examples.rb +47 -41
  104. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +19 -24
  105. data/spec/shared_examples/user_oauth_shared_examples.rb +7 -10
  106. data/spec/shared_examples/user_remember_me_shared_examples.rb +90 -21
  107. data/spec/shared_examples/user_reset_password_shared_examples.rb +52 -54
  108. data/spec/shared_examples/user_shared_examples.rb +226 -116
  109. data/spec/sorcery_crypto_providers_spec.rb +63 -76
  110. data/spec/spec_helper.rb +17 -13
  111. metadata +28 -82
  112. data/gemfiles/mongo_mapper-rails40.gemfile +0 -9
  113. data/gemfiles/mongo_mapper-rails41.gemfile +0 -9
  114. data/gemfiles/mongoid-rails41.gemfile +0 -9
  115. data/gemfiles/mongoid3-rails32.gemfile +0 -9
  116. data/lib/sorcery/adapters/data_mapper_adapter.rb +0 -176
  117. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +0 -110
  118. data/lib/sorcery/adapters/mongoid_adapter.rb +0 -97
  119. data/lib/sorcery/railties/tasks.rake +0 -6
  120. data/spec/data_mapper/user_activation_spec.rb +0 -10
  121. data/spec/data_mapper/user_activity_logging_spec.rb +0 -14
  122. data/spec/data_mapper/user_brute_force_protection_spec.rb +0 -9
  123. data/spec/data_mapper/user_oauth_spec.rb +0 -9
  124. data/spec/data_mapper/user_remember_me_spec.rb +0 -8
  125. data/spec/data_mapper/user_reset_password_spec.rb +0 -8
  126. data/spec/data_mapper/user_spec.rb +0 -27
  127. data/spec/mongo_mapper/user_activation_spec.rb +0 -9
  128. data/spec/mongo_mapper/user_activity_logging_spec.rb +0 -8
  129. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +0 -8
  130. data/spec/mongo_mapper/user_oauth_spec.rb +0 -8
  131. data/spec/mongo_mapper/user_remember_me_spec.rb +0 -8
  132. data/spec/mongo_mapper/user_reset_password_spec.rb +0 -8
  133. data/spec/mongo_mapper/user_spec.rb +0 -37
  134. data/spec/mongoid/user_activation_spec.rb +0 -9
  135. data/spec/mongoid/user_activity_logging_spec.rb +0 -8
  136. data/spec/mongoid/user_brute_force_protection_spec.rb +0 -8
  137. data/spec/mongoid/user_oauth_spec.rb +0 -8
  138. data/spec/mongoid/user_remember_me_spec.rb +0 -8
  139. data/spec/mongoid/user_reset_password_spec.rb +0 -8
  140. data/spec/mongoid/user_spec.rb +0 -51
  141. data/spec/orm/data_mapper.rb +0 -48
  142. data/spec/orm/mongo_mapper.rb +0 -10
  143. data/spec/orm/mongoid.rb +0 -22
  144. data/spec/rails_app/app/data_mapper/authentication.rb +0 -8
  145. data/spec/rails_app/app/data_mapper/user.rb +0 -7
  146. data/spec/rails_app/app/mongo_mapper/authentication.rb +0 -6
  147. data/spec/rails_app/app/mongo_mapper/user.rb +0 -7
  148. data/spec/rails_app/app/mongoid/authentication.rb +0 -7
  149. data/spec/rails_app/app/mongoid/user.rb +0 -7
  150. data/spec/rails_app/log/development.log +0 -1791
@@ -13,79 +13,67 @@ Rails.application.config.sorcery.configure do |config|
13
13
  #
14
14
  # config.not_authenticated_action =
15
15
 
16
-
17
16
  # When a non logged in user tries to enter a page that requires login, save
18
17
  # the URL he wanted to reach, and send him there after login, using 'redirect_back_or_to'.
19
18
  # Default: `true`
20
19
  #
21
20
  # config.save_return_to_url =
22
21
 
23
-
24
22
  # Set domain option for cookies; Useful for remember_me submodule.
25
23
  # Default: `nil`
26
24
  #
27
25
  # config.cookie_domain =
28
26
 
29
-
30
27
  # Allow the remember_me cookie to be set through AJAX
31
28
  # Default: `true`
32
29
  #
33
30
  # config.remember_me_httponly =
34
31
 
35
-
36
32
  # -- session timeout --
37
33
  # How long in seconds to keep the session alive.
38
34
  # Default: `3600`
39
35
  #
40
36
  # config.session_timeout =
41
37
 
42
-
43
38
  # Use the last action as the beginning of session timeout.
44
39
  # Default: `false`
45
40
  #
46
41
  # config.session_timeout_from_last_action =
47
42
 
48
-
49
43
  # -- http_basic_auth --
50
44
  # What realm to display for which controller name. For example {"My App" => "Application"}
51
45
  # Default: `{"application" => "Application"}`
52
46
  #
53
47
  # config.controller_to_realm_map =
54
48
 
55
-
56
49
  # -- activity logging --
57
50
  # will register the time of last user login, every login.
58
51
  # Default: `true`
59
52
  #
60
53
  # config.register_login_time =
61
54
 
62
-
63
55
  # will register the time of last user logout, every logout.
64
56
  # Default: `true`
65
57
  #
66
58
  # config.register_logout_time =
67
59
 
68
-
69
60
  # will register the time of last user action, every action.
70
61
  # Default: `true`
71
62
  #
72
63
  # config.register_last_activity_time =
73
64
 
74
-
75
65
  # -- external --
76
- # What providers are supported by this app, i.e. [:twitter, :facebook, :github, :linkedin, :xing, :google, :liveid, :salesforce] .
66
+ # What providers are supported by this app, i.e. [:twitter, :facebook, :github, :linkedin, :xing, :google, :liveid, :salesforce, :slack] .
77
67
  # Default: `[]`
78
68
  #
79
69
  # config.external_providers =
80
70
 
81
-
82
71
  # You can change it by your local ca_file. i.e. '/etc/pki/tls/certs/ca-bundle.crt'
83
72
  # Path to ca_file. By default use a internal ca-bundle.crt.
84
73
  # Default: `'path/to/ca_file'`
85
74
  #
86
75
  # config.ca_file =
87
76
 
88
-
89
77
  # For information about LinkedIn API:
90
78
  # - user info fields go to https://developer.linkedin.com/documents/profile-fields
91
79
  # - access permissions go to https://developer.linkedin.com/documents/authentication#granting
@@ -119,24 +107,40 @@ Rails.application.config.sorcery.configure do |config|
119
107
  # config.facebook.secret = ""
120
108
  # config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
121
109
  # config.facebook.user_info_mapping = {:email => "name"}
122
- # config.facebook.access_permissions = ["email", "publish_stream"]
110
+ # config.facebook.access_permissions = ["email", "publish_actions"]
123
111
  # config.facebook.display = "page"
112
+ # config.facebook.api_version = "v2.2"
124
113
  #
125
114
  # config.github.key = ""
126
115
  # config.github.secret = ""
127
116
  # config.github.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=github"
128
117
  # config.github.user_info_mapping = {:email => "name"}
129
118
  #
119
+ # config.paypal.key = ""
120
+ # config.paypal.secret = ""
121
+ # config.paypal.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=paypal"
122
+ # config.paypal.user_info_mapping = {:email => "email"}
123
+ #
124
+ # config.wechat.key = ""
125
+ # config.wechat.secret = ""
126
+ # config.wechat.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=wechat"
127
+ #
130
128
  # config.google.key = ""
131
129
  # config.google.secret = ""
132
130
  # config.google.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=google"
133
131
  # config.google.user_info_mapping = {:email => "email", :username => "name"}
132
+ # config.google.scope = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
134
133
  #
135
134
  # config.vk.key = ""
136
135
  # config.vk.secret = ""
137
136
  # config.vk.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=vk"
138
137
  # config.vk.user_info_mapping = {:login => "domain", :name => "full_name"}
139
138
  #
139
+ # config.slack.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=slack"
140
+ # config.slack.key = ''
141
+ # config.slack.secret = ''
142
+ # config.slack.user_info_mapping = {email: 'email'}
143
+ #
140
144
  # To use liveid in development mode you have to replace mydomain.com with
141
145
  # a valid domain even in development. To use a valid domain in development
142
146
  # simply add your domain in your /etc/hosts file in front of 127.0.0.1
@@ -178,80 +182,73 @@ Rails.application.config.sorcery.configure do |config|
178
182
  #
179
183
  # user.username_attribute_names =
180
184
 
181
-
182
185
  # change *virtual* password attribute, the one which is used until an encrypted one is generated.
183
186
  # Default: `:password`
184
187
  #
185
188
  # user.password_attribute_name =
186
189
 
187
-
188
190
  # downcase the username before trying to authenticate, default is false
189
191
  # Default: `false`
190
192
  #
191
193
  # user.downcase_username_before_authenticating =
192
194
 
193
-
194
195
  # change default email attribute.
195
196
  # Default: `:email`
196
197
  #
197
198
  # user.email_attribute_name =
198
199
 
199
-
200
200
  # change default crypted_password attribute.
201
201
  # Default: `:crypted_password`
202
202
  #
203
203
  # user.crypted_password_attribute_name =
204
204
 
205
-
206
205
  # what pattern to use to join the password with the salt
207
206
  # Default: `""`
208
207
  #
209
208
  # user.salt_join_token =
210
209
 
211
-
212
210
  # change default salt attribute.
213
211
  # Default: `:salt`
214
212
  #
215
213
  # user.salt_attribute_name =
216
214
 
217
-
218
215
  # how many times to apply encryption to the password.
219
216
  # Default: `nil`
220
217
  #
221
218
  # user.stretches =
222
219
 
223
-
224
220
  # encryption key used to encrypt reversible encryptions such as AES256.
225
221
  # WARNING: If used for users' passwords, changing this key will leave passwords undecryptable!
226
222
  # Default: `nil`
227
223
  #
228
224
  # user.encryption_key =
229
225
 
230
-
231
226
  # use an external encryption class.
232
227
  # Default: `nil`
233
228
  #
234
229
  # user.custom_encryption_provider =
235
230
 
236
-
237
231
  # encryption algorithm name. See 'encryption_algorithm=' for available options.
238
232
  # Default: `:bcrypt`
239
233
  #
240
234
  # user.encryption_algorithm =
241
235
 
242
-
243
236
  # make this configuration inheritable for subclasses. Useful for ActiveRecord's STI.
244
237
  # Default: `false`
245
238
  #
246
239
  # user.subclasses_inherit_config =
247
240
 
248
-
249
241
  # -- remember_me --
250
242
  # How long in seconds the session length will be
251
243
  # Default: `604800`
252
244
  #
253
245
  # user.remember_me_for =
254
246
 
247
+ # when true sorcery will persist a single remember me token for all
248
+ # logins/logouts (supporting remembering on multiple browsers simultaneously).
249
+ # Default: false
250
+ #
251
+ # user.remember_me_token_persist_globally =
255
252
 
256
253
  # -- user_activation --
257
254
  # the attribute name to hold activation state (active/pending).
@@ -259,31 +256,26 @@ Rails.application.config.sorcery.configure do |config|
259
256
  #
260
257
  # user.activation_state_attribute_name =
261
258
 
262
-
263
259
  # the attribute name to hold activation code (sent by email).
264
260
  # Default: `:activation_token`
265
261
  #
266
262
  # user.activation_token_attribute_name =
267
263
 
268
-
269
264
  # the attribute name to hold activation code expiration date.
270
265
  # Default: `:activation_token_expires_at`
271
266
  #
272
267
  # user.activation_token_expires_at_attribute_name =
273
268
 
274
-
275
269
  # how many seconds before the activation code expires. nil for never expires.
276
270
  # Default: `nil`
277
271
  #
278
272
  # user.activation_token_expiration_period =
279
273
 
280
-
281
274
  # your mailer class. Required.
282
275
  # Default: `nil`
283
276
  #
284
277
  # user.user_activation_mailer =
285
278
 
286
-
287
279
  # when true sorcery will not automatically
288
280
  # email activation details and allow you to
289
281
  # manually handle how and when email is sent.
@@ -291,56 +283,53 @@ Rails.application.config.sorcery.configure do |config|
291
283
  #
292
284
  # user.activation_mailer_disabled =
293
285
 
286
+ # method to send email related
287
+ # options: `:deliver_later`, `:deliver_now`, `:deliver`
288
+ # Default: :deliver (Rails version < 4.2) or :deliver_now (Rails version 4.2+)
289
+ #
290
+ # user.email_delivery_method =
294
291
 
295
292
  # activation needed email method on your mailer class.
296
293
  # Default: `:activation_needed_email`
297
294
  #
298
295
  # user.activation_needed_email_method_name =
299
296
 
300
-
301
297
  # activation success email method on your mailer class.
302
298
  # Default: `:activation_success_email`
303
299
  #
304
300
  # user.activation_success_email_method_name =
305
301
 
306
-
307
302
  # do you want to prevent or allow users that did not activate by email to login?
308
303
  # Default: `true`
309
304
  #
310
305
  # user.prevent_non_active_users_to_login =
311
306
 
312
-
313
307
  # -- reset_password --
314
308
  # reset password code attribute name.
315
309
  # Default: `:reset_password_token`
316
310
  #
317
311
  # user.reset_password_token_attribute_name =
318
312
 
319
-
320
313
  # expires at attribute name.
321
314
  # Default: `:reset_password_token_expires_at`
322
315
  #
323
316
  # user.reset_password_token_expires_at_attribute_name =
324
317
 
325
-
326
318
  # when was email sent, used for hammering protection.
327
319
  # Default: `:reset_password_email_sent_at`
328
320
  #
329
321
  # user.reset_password_email_sent_at_attribute_name =
330
322
 
331
-
332
323
  # mailer class. Needed.
333
324
  # Default: `nil`
334
325
  #
335
326
  # user.reset_password_mailer =
336
327
 
337
-
338
328
  # reset password email method on your mailer class.
339
329
  # Default: `:reset_password_email`
340
330
  #
341
331
  # user.reset_password_email_method_name =
342
332
 
343
-
344
333
  # when true sorcery will not automatically
345
334
  # email password reset details and allow you to
346
335
  # manually handle how and when email is sent
@@ -348,38 +337,32 @@ Rails.application.config.sorcery.configure do |config|
348
337
  #
349
338
  # user.reset_password_mailer_disabled =
350
339
 
351
-
352
340
  # how many seconds before the reset request expires. nil for never expires.
353
341
  # Default: `nil`
354
342
  #
355
343
  # user.reset_password_expiration_period =
356
344
 
357
-
358
345
  # hammering protection, how long in seconds to wait before allowing another email to be sent.
359
346
  # Default: `5 * 60`
360
347
  #
361
348
  # user.reset_password_time_between_emails =
362
349
 
363
-
364
350
  # -- brute_force_protection --
365
351
  # Failed logins attribute name.
366
352
  # Default: `:failed_logins_count`
367
353
  #
368
354
  # user.failed_logins_count_attribute_name =
369
355
 
370
-
371
356
  # This field indicates whether user is banned and when it will be active again.
372
357
  # Default: `:lock_expires_at`
373
358
  #
374
359
  # user.lock_expires_at_attribute_name =
375
360
 
376
-
377
361
  # How many failed logins allowed.
378
362
  # Default: `50`
379
363
  #
380
364
  # user.consecutive_login_retries_amount_limit =
381
365
 
382
-
383
366
  # How long the user should be banned. in seconds. 0 for permanent.
384
367
  # Default: `60 * 60`
385
368
  #
@@ -412,44 +395,37 @@ Rails.application.config.sorcery.configure do |config|
412
395
  #
413
396
  # user.last_login_at_attribute_name =
414
397
 
415
-
416
398
  # Last logout attribute name.
417
399
  # Default: `:last_logout_at`
418
400
  #
419
401
  # user.last_logout_at_attribute_name =
420
402
 
421
-
422
403
  # Last activity attribute name.
423
404
  # Default: `:last_activity_at`
424
405
  #
425
406
  # user.last_activity_at_attribute_name =
426
407
 
427
-
428
408
  # How long since last activity is the user defined logged out?
429
409
  # Default: `10 * 60`
430
410
  #
431
411
  # user.activity_timeout =
432
412
 
433
-
434
413
  # -- external --
435
414
  # Class which holds the various external provider data for this user.
436
415
  # Default: `nil`
437
416
  #
438
417
  # user.authentications_class =
439
418
 
440
-
441
419
  # User's identifier in authentications class.
442
420
  # Default: `:user_id`
443
421
  #
444
422
  # user.authentications_user_id_attribute_name =
445
423
 
446
-
447
424
  # Provider's identifier in authentications class.
448
425
  # Default: `:provider`
449
426
  #
450
427
  # user.provider_attribute_name =
451
428
 
452
-
453
429
  # User's external unique identifier in authentications class.
454
430
  # Default: `:uid`
455
431
  #
@@ -458,5 +434,5 @@ Rails.application.config.sorcery.configure do |config|
458
434
 
459
435
  # This line must come after the 'user config' block.
460
436
  # Define which model authenticates with sorcery.
461
- config.user_class = "<%= model_class_name %>"
437
+ config.user_class = '<%= model_class_name %>'
462
438
  end
@@ -1,4 +1,4 @@
1
- class SorceryActivityLogging < ActiveRecord::Migration
1
+ class SorceryActivityLogging < <%= migration_class_name %>
2
2
  def change
3
3
  add_column :<%= model_class_name.tableize %>, :last_login_at, :datetime, :default => nil
4
4
  add_column :<%= model_class_name.tableize %>, :last_logout_at, :datetime, :default => nil
@@ -7,4 +7,4 @@ class SorceryActivityLogging < ActiveRecord::Migration
7
7
 
8
8
  add_index :<%= model_class_name.tableize %>, [:last_logout_at, :last_activity_at]
9
9
  end
10
- end
10
+ end
@@ -1,4 +1,4 @@
1
- class SorceryBruteForceProtection < ActiveRecord::Migration
1
+ class SorceryBruteForceProtection < <%= migration_class_name %>
2
2
  def change
3
3
  add_column :<%= model_class_name.tableize %>, :failed_logins_count, :integer, :default => 0
4
4
  add_column :<%= model_class_name.tableize %>, :lock_expires_at, :datetime, :default => nil
@@ -1,13 +1,13 @@
1
- class SorceryCore < ActiveRecord::Migration
1
+ class SorceryCore < <%= migration_class_name %>
2
2
  def change
3
3
  create_table :<%= model_class_name.tableize %> do |t|
4
4
  t.string :email, :null => false
5
5
  t.string :crypted_password
6
6
  t.string :salt
7
7
 
8
- t.timestamps
8
+ t.timestamps :null => false
9
9
  end
10
10
 
11
11
  add_index :<%= model_class_name.tableize %>, :email, unique: true
12
12
  end
13
- end
13
+ end
@@ -1,12 +1,12 @@
1
- class SorceryExternal < ActiveRecord::Migration
1
+ class SorceryExternal < <%= migration_class_name %>
2
2
  def change
3
3
  create_table :authentications do |t|
4
4
  t.integer :<%= model_class_name.tableize.singularize %>_id, :null => false
5
5
  t.string :provider, :uid, :null => false
6
6
 
7
- t.timestamps
7
+ t.timestamps :null => false
8
8
  end
9
9
 
10
- add_index :<%= model_class_name.tableize %>, [:provider, :uid]
10
+ add_index :authentications, [:provider, :uid]
11
11
  end
12
12
  end
@@ -1,8 +1,8 @@
1
- class SorceryRememberMe < ActiveRecord::Migration
1
+ class SorceryRememberMe < <%= migration_class_name %>
2
2
  def change
3
3
  add_column :<%= model_class_name.tableize %>, :remember_me_token, :string, :default => nil
4
4
  add_column :<%= model_class_name.tableize %>, :remember_me_token_expires_at, :datetime, :default => nil
5
5
 
6
6
  add_index :<%= model_class_name.tableize %>, :remember_me_token
7
7
  end
8
- end
8
+ end
@@ -1,4 +1,4 @@
1
- class SorceryResetPassword < ActiveRecord::Migration
1
+ class SorceryResetPassword < <%= migration_class_name %>
2
2
  def change
3
3
  add_column :<%= model_class_name.tableize %>, :reset_password_token, :string, :default => nil
4
4
  add_column :<%= model_class_name.tableize %>, :reset_password_token_expires_at, :datetime, :default => nil
@@ -6,4 +6,4 @@ class SorceryResetPassword < ActiveRecord::Migration
6
6
 
7
7
  add_index :<%= model_class_name.tableize %>, :reset_password_token
8
8
  end
9
- end
9
+ end
@@ -1,4 +1,4 @@
1
- class SorceryUserActivation < ActiveRecord::Migration
1
+ class SorceryUserActivation < <%= migration_class_name %>
2
2
  def change
3
3
  add_column :<%= model_class_name.tableize %>, :activation_state, :string, :default => nil
4
4
  add_column :<%= model_class_name.tableize %>, :activation_token, :string, :default => nil
@@ -6,4 +6,4 @@ class SorceryUserActivation < ActiveRecord::Migration
6
6
 
7
7
  add_index :<%= model_class_name.tableize %>, :activation_token
8
8
  end
9
- end
9
+ end
@@ -29,11 +29,11 @@ module Sorcery
29
29
  end
30
30
 
31
31
  class << self
32
- def define_field(name, type, options={})
32
+ def define_field(name, type, options = {})
33
33
  # AR fields are defined through migrations, only validator here
34
34
  end
35
35
 
36
- def define_callback(time, event, method_name, options={})
36
+ def define_callback(time, event, method_name, options = {})
37
37
  @klass.send "#{time}_#{event}", method_name, options.slice(:if)
38
38
  end
39
39
 
@@ -61,11 +61,11 @@ module Sorcery
61
61
  condition = @klass.arel_table[attribute].eq(credentials[0])
62
62
  end
63
63
 
64
- if relation.nil?
65
- relation = condition
66
- else
67
- relation = relation.or(condition)
68
- end
64
+ relation = if relation.nil?
65
+ condition
66
+ else
67
+ relation.or(condition)
68
+ end
69
69
  end
70
70
 
71
71
  @klass.where(relation).first
@@ -100,21 +100,10 @@ module Sorcery
100
100
  @klass.where(@klass.sorcery_config.email_attribute_name => email).first
101
101
  end
102
102
 
103
- def get_current_users
104
- config = @klass.sorcery_config
105
-
106
- @klass
107
- .where("#{config.last_activity_at_attribute_name} IS NOT NULL") \
108
- .where("#{config.last_logout_at_attribute_name} IS NULL OR #{config.last_activity_at_attribute_name} > #{config.last_logout_at_attribute_name}") \
109
- .where("#{config.last_activity_at_attribute_name} > ? ", config.activity_timeout.seconds.ago.utc.to_s(:db))
110
- end
111
-
112
103
  def transaction(&blk)
113
104
  @klass.tap(&blk)
114
105
  end
115
106
  end
116
107
  end
117
-
118
-
119
108
  end
120
109
  end
@@ -2,21 +2,22 @@ module Sorcery
2
2
  module Controller
3
3
  module Config
4
4
  class << self
5
- attr_accessor :submodules,
6
- :user_class, # what class to use as the user class.
7
- :not_authenticated_action, # what controller action to call for non-authenticated users.
5
+ attr_accessor :submodules
6
+ # what class to use as the user class.
7
+ attr_accessor :user_class
8
+ # what controller action to call for non-authenticated users.
9
+ attr_accessor :not_authenticated_action
10
+ # when a non logged in user tries to enter a page that requires login,
11
+ # save the URL he wanted to reach, and send him there after login.
12
+ attr_accessor :save_return_to_url
13
+ # set domain option for cookies
14
+ attr_accessor :cookie_domain
8
15
 
9
- :save_return_to_url, # when a non logged in user tries to enter a page that requires
10
- # login, save the URL he wanted to reach,
11
- # and send him there after login.
12
-
13
- :cookie_domain, # set domain option for cookies
14
-
15
- :login_sources,
16
- :after_login,
17
- :after_failed_login,
18
- :before_logout,
19
- :after_logout
16
+ attr_accessor :login_sources
17
+ attr_accessor :after_login
18
+ attr_accessor :after_failed_login
19
+ attr_accessor :before_logout
20
+ attr_accessor :after_logout
20
21
 
21
22
  def init!
22
23
  @defaults = {
@@ -35,14 +36,14 @@ module Sorcery
35
36
 
36
37
  # Resets all configuration options to their default values.
37
38
  def reset!
38
- @defaults.each do |k,v|
39
- instance_variable_set(k,v)
39
+ @defaults.each do |k, v|
40
+ instance_variable_set(k, v)
40
41
  end
41
42
  end
42
43
 
43
44
  def update!
44
- @defaults.each do |k,v|
45
- instance_variable_set(k,v) if !instance_variable_defined?(k)
45
+ @defaults.each do |k, v|
46
+ instance_variable_set(k, v) unless instance_variable_defined?(k)
46
47
  end
47
48
  end
48
49
 
@@ -58,6 +59,7 @@ module Sorcery
58
59
  @configure_blk.call(self) if @configure_blk
59
60
  end
60
61
  end
62
+
61
63
  init!
62
64
  reset!
63
65
  end
@@ -25,8 +25,7 @@ module Sorcery
25
25
  @defaults.merge!(:@register_login_time => true,
26
26
  :@register_logout_time => true,
27
27
  :@register_last_activity_time => true,
28
- :@register_last_ip_address => true
29
- )
28
+ :@register_last_ip_address => true)
30
29
  end
31
30
  end
32
31
  merge_activity_logging_defaults!
@@ -34,31 +33,24 @@ module Sorcery
34
33
  Config.after_login << :register_login_time_to_db
35
34
  Config.after_login << :register_last_ip_address
36
35
  Config.before_logout << :register_logout_time_to_db
37
- base.after_filter :register_last_activity_time_to_db
36
+ base.after_action :register_last_activity_time_to_db
38
37
  end
39
38
 
40
39
  module InstanceMethods
41
- # Returns an array of the active users.
42
- def current_users
43
- ActiveSupport::Deprecation.warn("Sorcery: `current_users` method is deprecated. Read more on Github: https://github.com/NoamB/sorcery/issues/602")
44
-
45
- user_class.current_users
46
- end
47
-
48
40
  protected
49
41
 
50
42
  # registers last login time on every login.
51
43
  # This runs as a hook just after a successful login.
52
- def register_login_time_to_db(user, credentials)
44
+ def register_login_time_to_db(user, _credentials)
53
45
  return unless Config.register_login_time
54
46
  user.set_last_login_at(Time.now.in_time_zone)
55
47
  end
56
48
 
57
49
  # registers last logout time on every logout.
58
50
  # This runs as a hook just before a logout.
59
- def register_logout_time_to_db(user)
51
+ def register_logout_time_to_db
60
52
  return unless Config.register_logout_time
61
- user.set_last_logout_at(Time.now.in_time_zone)
53
+ current_user.set_last_logout_at(Time.now.in_time_zone)
62
54
  end
63
55
 
64
56
  # Updates last activity time on every request.
@@ -71,9 +63,9 @@ module Sorcery
71
63
 
72
64
  # Updates IP address on every login.
73
65
  # This runs as a hook just after a successful login.
74
- def register_last_ip_address(user, credentials)
66
+ def register_last_ip_address(_user, _credentials)
75
67
  return unless Config.register_last_ip_address
76
- current_user.set_last_ip_addess(request.remote_ip)
68
+ current_user.set_last_ip_address(request.remote_ip)
77
69
  end
78
70
  end
79
71
  end
@@ -16,7 +16,6 @@ module Sorcery
16
16
  end
17
17
 
18
18
  module InstanceMethods
19
-
20
19
  protected
21
20
 
22
21
  # Increments the failed logins counter on every failed login.
@@ -28,7 +27,7 @@ module Sorcery
28
27
 
29
28
  # Resets the failed logins counter.
30
29
  # Runs as a hook after a successful login.
31
- def reset_failed_logins_count!(user, credentials)
30
+ def reset_failed_logins_count!(user, _credentials)
32
31
  user.sorcery_adapter.update_attribute(user_class.sorcery_config.failed_logins_count_attribute_name, 0)
33
32
  end
34
33
  end