sorcery 0.7.4 → 0.8.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 (70) hide show
  1. data/.travis.yml +3 -0
  2. data/Gemfile +9 -4
  3. data/Gemfile.lock +103 -62
  4. data/README.rdoc +33 -8
  5. data/Rakefile +6 -7
  6. data/VERSION +1 -1
  7. data/lib/generators/sorcery/install_generator.rb +15 -10
  8. data/lib/generators/sorcery/templates/initializer.rb +343 -125
  9. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +2 -0
  10. data/lib/generators/sorcery/templates/migration/reset_password.rb +1 -1
  11. data/lib/sorcery/controller/submodules/activity_logging.rb +3 -3
  12. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  13. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +19 -19
  14. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +20 -5
  15. data/lib/sorcery/controller/submodules/external/providers/github.rb +15 -4
  16. data/lib/sorcery/controller/submodules/external/providers/google.rb +90 -0
  17. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +101 -0
  18. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +91 -0
  19. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +2 -1
  20. data/lib/sorcery/controller/submodules/external/providers/vkontakte.rb +94 -0
  21. data/lib/sorcery/controller/submodules/external.rb +89 -15
  22. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  23. data/lib/sorcery/controller/submodules/remember_me.rb +11 -2
  24. data/lib/sorcery/controller.rb +14 -6
  25. data/lib/sorcery/crypto_providers/bcrypt.rb +1 -0
  26. data/lib/sorcery/model/adapters/active_record.rb +21 -1
  27. data/lib/sorcery/model/adapters/mongo_mapper.rb +22 -15
  28. data/lib/sorcery/model/adapters/mongoid.rb +20 -3
  29. data/lib/sorcery/model/submodules/activity_logging.rb +4 -4
  30. data/lib/sorcery/model/submodules/brute_force_protection.rb +46 -15
  31. data/lib/sorcery/model/submodules/remember_me.rb +4 -6
  32. data/lib/sorcery/model/submodules/reset_password.rb +18 -12
  33. data/lib/sorcery/model/submodules/user_activation.rb +15 -8
  34. data/lib/sorcery/model.rb +57 -43
  35. data/lib/sorcery/railties/tasks.rake +2 -0
  36. data/lib/sorcery.rb +5 -1
  37. data/sorcery.gemspec +33 -21
  38. data/spec/Gemfile +1 -1
  39. data/spec/Gemfile.lock +22 -21
  40. data/spec/README.md +8 -8
  41. data/spec/rails3/Gemfile +3 -3
  42. data/spec/rails3/Gemfile.lock +55 -33
  43. data/spec/rails3/app/controllers/application_controller.rb +85 -2
  44. data/spec/rails3/app/mailers/sorcery_mailer.rb +7 -0
  45. data/spec/rails3/app/views/sorcery_mailer/send_unlock_token_email.text.erb +1 -0
  46. data/spec/rails3/config/environments/in_memory.rb +35 -0
  47. data/spec/rails3/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +2 -0
  48. data/spec/rails3/spec/controller_activity_logging_spec.rb +10 -0
  49. data/spec/rails3/spec/controller_brute_force_protection_spec.rb +23 -1
  50. data/spec/rails3/spec/controller_oauth2_spec.rb +260 -22
  51. data/spec/rails3/spec/controller_oauth_spec.rb +111 -6
  52. data/spec/rails3/spec/controller_spec.rb +37 -2
  53. data/spec/rails3/spec/integration_spec.rb +15 -15
  54. data/spec/rails3/spec/spec_helper.rb +1 -1
  55. data/spec/rails3_mongo_mapper/Gemfile +2 -1
  56. data/spec/rails3_mongo_mapper/Gemfile.lock +40 -42
  57. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +14 -0
  58. data/spec/rails3_mongo_mapper/spec/controller_spec.rb +41 -1
  59. data/spec/rails3_mongoid/Gemfile +1 -0
  60. data/spec/rails3_mongoid/Gemfile.lock +30 -27
  61. data/spec/rails3_mongoid/app/controllers/application_controller.rb +19 -0
  62. data/spec/rails3_mongoid/config/mongoid.yml +1 -1
  63. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +18 -11
  64. data/spec/rails3_mongoid/spec/controller_spec.rb +41 -1
  65. data/spec/shared_examples/controller_oauth2_shared_examples.rb +20 -1
  66. data/spec/shared_examples/controller_oauth_shared_examples.rb +18 -0
  67. data/spec/shared_examples/user_activation_shared_examples.rb +71 -41
  68. data/spec/shared_examples/user_reset_password_shared_examples.rb +80 -27
  69. data/spec/sorcery_crypto_providers_spec.rb +14 -1
  70. metadata +74 -46
@@ -7,193 +7,411 @@ Rails.application.config.sorcery.submodules = []
7
7
  # Here you can configure each submodule's features.
8
8
  Rails.application.config.sorcery.configure do |config|
9
9
  # -- core --
10
- # config.not_authenticated_action = :not_authenticated # what controller action to call for
11
- # non-authenticated users.
12
- # You can also override 'not_authenticated'
13
- # instead.
10
+ # What controller action to call for non-authenticated users. You can also
11
+ # override the 'not_authenticated' method of course.
12
+ # Default: `:not_authenticated`
13
+ #
14
+ # config.not_authenticated_action =
15
+
16
+
17
+ # When a non logged in user tries to enter a page that requires login, save
18
+ # the URL he wanted to reach, and send him there after login, using 'redirect_back_or_to'.
19
+ # Default: `true`
20
+ #
21
+ # config.save_return_to_url =
22
+
14
23
 
15
- # config.save_return_to_url = true # when a non logged in user tries to enter
16
- # a page that requires login,
17
- # save the URL he wanted to reach,
18
- # and send him there after login, using
19
- # 'redirect_back_or_to'.
24
+ # Set domain option for cookies; Useful for remember_me submodule.
25
+ # Default: `nil`
26
+ #
27
+ # config.cookie_domain =
20
28
 
21
- # config.cookie_domain = nil # set domain option for cookies
22
- # Useful for remember_me submodule
29
+
30
+ # -- remember_me --
31
+ # allow the remember_me cookie to settable through AJAX
32
+ # Default: `true`
33
+ #
34
+ # user.remember_me_httponly =
35
+
23
36
 
24
37
  # -- session timeout --
25
- # config.session_timeout = 3600 # how long in seconds to keep the session alive.
26
- # config.session_timeout_from_last_action = false # use the last action as the beginning of
27
- # session timeout.
38
+ # How long in seconds to keep the session alive.
39
+ # Default: `3600`
40
+ #
41
+ # config.session_timeout =
42
+
43
+
44
+ # Use the last action as the beginning of session timeout.
45
+ # Default: `false`
46
+ #
47
+ # config.session_timeout_from_last_action =
48
+
28
49
 
29
50
  # -- http_basic_auth --
30
- # config.controller_to_realm_map = {"application" => "Application"} # What realm to display for which controller name.
31
- # For example {"My App" => "Application"}
32
-
51
+ # What realm to display for which controller name. For example {"My App" => "Application"}
52
+ # Default: `{"application" => "Application"}`
53
+ #
54
+ # config.controller_to_realm_map =
55
+
56
+
33
57
  # -- activity logging --
34
- # config.register_login_time = true # will register the time of last user login, every login.
35
- # config.register_logout_time = true # will register the time of last user logout, every logout.
36
- # config.register_last_activity_time = true # will register the time of last user action, every action.
37
-
58
+ # will register the time of last user login, every login.
59
+ # Default: `true`
60
+ #
61
+ # config.register_login_time =
62
+
63
+
64
+ # will register the time of last user logout, every logout.
65
+ # Default: `true`
66
+ #
67
+ # config.register_logout_time =
68
+
69
+
70
+ # will register the time of last user action, every action.
71
+ # Default: `true`
72
+ #
73
+ # config.register_last_activity_time =
74
+
75
+
38
76
  # -- external --
39
- # config.external_providers = [] # What providers are supported by this app,
40
- # i.e. [:twitter, :facebook, :github] .
41
- # config.ca_file = 'path/to/ca_file' # Path to ca_file. By default use a internal ca-bundle.crt.
42
- # You can change it by your local ca_file.
43
- # i.e. '/etc/pki/tls/certs/ca-bundle.crt'
44
-
45
- # config.twitter.key = "eYVNBjBDi33aa9GkA3w"
46
- # config.twitter.secret = "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8"
77
+ # What providers are supported by this app, i.e. [:twitter, :facebook, :github, :google, :liveid] .
78
+ # Default: `[]`
79
+ #
80
+ # config.external_providers =
81
+
82
+
83
+ # You can change it by your local ca_file. i.e. '/etc/pki/tls/certs/ca-bundle.crt'
84
+ # Path to ca_file. By default use a internal ca-bundle.crt.
85
+ # Default: `'path/to/ca_file'`
86
+ #
87
+ # config.ca_file =
88
+
89
+
90
+ # For information about LinkedIn API:
91
+ # - user info fields go to https://developer.linkedin.com/documents/profile-fields
92
+ # - access permissions go to https://developer.linkedin.com/documents/authentication#granting
93
+ #
94
+ # config.linkedin.key = ""
95
+ # config.linkedin.secret = ""
96
+ # config.linkedin.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=linkedin"
97
+ # config.linkedin.user_info_fields = ['first-name', 'last-name']
98
+ # config.linkedin.user_info_mapping = {first_name: "firstName", last_name: "lastName"}
99
+ # config.linkedin.access_permissions = ['r_basicprofile']
100
+ #
101
+ # Twitter wil not accept any requests nor redirect uri containing localhost,
102
+ # make sure you use 0.0.0.0:3000 to access your app in development
103
+ #
104
+ # config.twitter.key = ""
105
+ # config.twitter.secret = ""
47
106
  # config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter"
48
107
  # config.twitter.user_info_mapping = {:email => "screen_name"}
49
108
  #
50
- # config.facebook.key = "34cebc81c08a521bc66e212f947d73ec"
51
- # config.facebook.secret = "5b458d179f61d4f036ee66a497ffbcd0"
109
+ # config.facebook.key = ""
110
+ # config.facebook.secret = ""
52
111
  # config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
53
112
  # config.facebook.user_info_mapping = {:email => "name"}
113
+ # config.facebook.access_permissions = ["email", "publish_stream"]
54
114
  #
55
115
  # config.github.key = ""
56
116
  # config.github.secret = ""
57
117
  # config.github.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=github"
58
118
  # config.github.user_info_mapping = {:email => "name"}
119
+ #
120
+ # config.google.key = ""
121
+ # config.google.secret = ""
122
+ # config.google.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=google"
123
+ # config.google.user_info_mapping = {:email => "email", :username => "name"}
124
+ #
125
+ # To use liveid in development mode you have to replace mydomain.com with
126
+ # a valid domain even in development. To use a valid domain in development
127
+ # simply add your domain in your /etc/hosts file in front of 127.0.0.1
128
+ #
129
+ # config.liveid.key = ""
130
+ # config.liveid.secret = ""
131
+ # config.liveid.callback_url = "http://mydomain.com:3000/oauth/callback?provider=liveid"
132
+ # config.liveid.user_info_mapping = {:username => "name"}
133
+
59
134
 
60
135
  # --- user config ---
61
136
  config.user_config do |user|
62
137
  # -- core --
63
- # user.username_attribute_names = [:username] # specify username
64
- # attributes, for example:
65
- # [:username, :email].
138
+ # specify username attributes, for example: [:username, :email].
139
+ # Default: `[:username]`
140
+ #
141
+ # user.username_attribute_names =
142
+
143
+
144
+ # change *virtual* password attribute, the one which is used until an encrypted one is generated.
145
+ # Default: `:password`
146
+ #
147
+ # user.password_attribute_name =
148
+
149
+
150
+ # downcase the username before trying to authenticate, default is false
151
+ # Default: `false`
152
+ #
153
+ # user.downcase_username_before_authenticating =
154
+
66
155
 
67
- # user.password_attribute_name = :password # change *virtual* password
68
- # attribute, the one which is used
69
- # until an encrypted one is
70
- # generated.
156
+ # change default email attribute.
157
+ # Default: `:email`
158
+ #
159
+ # user.email_attribute_name =
71
160
 
72
- # user.email_attribute_name = :email # change default email attribute.
73
161
 
74
- # user.crypted_password_attribute_name = :crypted_password # change default crypted_password
75
- # attribute.
162
+ # change default crypted_password attribute.
163
+ # Default: `:crypted_password`
164
+ #
165
+ # user.crypted_password_attribute_name =
76
166
 
77
- # user.salt_join_token = "" # what pattern to use to join the
78
- # password with the salt
79
167
 
80
- # user.salt_attribute_name = :salt # change default salt attribute.
168
+ # what pattern to use to join the password with the salt
169
+ # Default: `""`
170
+ #
171
+ # user.salt_join_token =
81
172
 
82
- # user.stretches = nil # how many times to apply
83
- # encryption to the password.
84
173
 
85
- # user.encryption_key = nil # encryption key used to encrypt
86
- # reversible encryptions such as
87
- # AES256.
88
- #
89
- # WARNING:
90
- #
91
- # If used for users' passwords, changing this key
92
- # will leave passwords undecryptable!
174
+ # change default salt attribute.
175
+ # Default: `:salt`
176
+ #
177
+ # user.salt_attribute_name =
93
178
 
94
- # user.custom_encryption_provider = nil # use an external encryption
95
- # class.
96
179
 
97
- # user.encryption_algorithm = :bcrypt # encryption algorithm name. See
98
- # 'encryption_algorithm=' for
99
- # available options.
180
+ # how many times to apply encryption to the password.
181
+ # Default: `nil`
182
+ #
183
+ # user.stretches =
184
+
185
+
186
+ # encryption key used to encrypt reversible encryptions such as AES256.
187
+ # WARNING: If used for users' passwords, changing this key will leave passwords undecryptable!
188
+ # Default: `nil`
189
+ #
190
+ # user.encryption_key =
191
+
192
+
193
+ # use an external encryption class.
194
+ # Default: `nil`
195
+ #
196
+ # user.custom_encryption_provider =
197
+
198
+
199
+ # encryption algorithm name. See 'encryption_algorithm=' for available options.
200
+ # Default: `:bcrypt`
201
+ #
202
+ # user.encryption_algorithm =
203
+
204
+
205
+ # make this configuration inheritable for subclasses. Useful for ActiveRecord's STI.
206
+ # Default: `false`
207
+ #
208
+ # user.subclasses_inherit_config =
100
209
 
101
- # user.subclasses_inherit_config = false # make this configuration
102
- # inheritable for subclasses.
103
- # Useful for ActiveRecord's STI.
104
210
 
105
211
  # -- user_activation --
106
- # user.activation_state_attribute_name = :activation_state # the attribute name to hold
107
- # activation state
108
- # (active/pending).
212
+ # the attribute name to hold activation state (active/pending).
213
+ # Default: `:activation_state`
214
+ #
215
+ # user.activation_state_attribute_name =
216
+
217
+
218
+ # the attribute name to hold activation code (sent by email).
219
+ # Default: `:activation_token`
220
+ #
221
+ # user.activation_token_attribute_name =
222
+
109
223
 
110
- # user.activation_token_attribute_name = :activation_token # the attribute name to hold
111
- # activation code (sent by email).
224
+ # the attribute name to hold activation code expiration date.
225
+ # Default: `:activation_token_expires_at`
226
+ #
227
+ # user.activation_token_expires_at_attribute_name =
112
228
 
113
- # user.activation_token_expires_at_attribute_name = :activation_token_expires_at # the attribute name to hold
114
- # activation code expiration date.
115
229
 
116
- # user.activation_token_expiration_period = nil # how many seconds before the
117
- # activation code expires. nil for
118
- # never expires.
230
+ # how many seconds before the activation code expires. nil for never expires.
231
+ # Default: `nil`
232
+ #
233
+ # user.activation_token_expiration_period =
119
234
 
120
- # user.user_activation_mailer = nil # your mailer class. Required.
121
235
 
122
- # user.activation_needed_email_method_name = :activation_needed_email # activation needed email method
123
- # on your mailer class.
236
+ # your mailer class. Required.
237
+ # Default: `nil`
238
+ #
239
+ # user.user_activation_mailer =
124
240
 
125
- # user.activation_success_email_method_name = :activation_success_email # activation success email method
126
- # on your mailer class.
127
241
 
128
- # user.prevent_non_active_users_to_login = true # do you want to prevent or allow
129
- # users that did not activate by
130
- # email to login?
242
+ # when true sorcery will not automatically
243
+ # email activation details and allow you to
244
+ # manually handle how and when email is sent.
245
+ # Default: `false`
246
+ #
247
+ # user.activation_mailer_disabled =
248
+
249
+
250
+ # activation needed email method on your mailer class.
251
+ # Default: `:activation_needed_email`
252
+ #
253
+ # user.activation_needed_email_method_name =
254
+
255
+
256
+ # activation success email method on your mailer class.
257
+ # Default: `:activation_success_email`
258
+ #
259
+ # user.activation_success_email_method_name =
260
+
261
+
262
+ # do you want to prevent or allow users that did not activate by email to login?
263
+ # Default: `true`
264
+ #
265
+ # user.prevent_non_active_users_to_login =
266
+
131
267
 
132
268
  # -- reset_password --
133
- # user.reset_password_token_attribute_name = :reset_password_token # reset password code
134
- # attribute name.
269
+ # reset password code attribute name.
270
+ # Default: `:reset_password_token`
271
+ #
272
+ # user.reset_password_token_attribute_name =
273
+
274
+
275
+ # expires at attribute name.
276
+ # Default: `:reset_password_token_expires_at`
277
+ #
278
+ # user.reset_password_token_expires_at_attribute_name =
279
+
280
+
281
+ # when was email sent, used for hammering protection.
282
+ # Default: `:reset_password_email_sent_at`
283
+ #
284
+ # user.reset_password_email_sent_at_attribute_name =
135
285
 
136
- # user.reset_password_token_expires_at_attribute_name = :reset_password_token_expires_at # expires at attribute
137
- # name.
138
286
 
139
- # user.reset_password_email_sent_at_attribute_name = :reset_password_email_sent_at # when was email sent,
140
- # used for hammering
141
- # protection.
287
+ # mailer class. Needed.
288
+ # Default: `nil`
289
+ #
290
+ # user.reset_password_mailer =
142
291
 
143
- # user.reset_password_mailer = nil # mailer class. Needed.
144
292
 
145
- # user.reset_password_email_method_name = :reset_password_email # reset password email
146
- # method on your mailer
147
- # class.
293
+ # reset password email method on your mailer class.
294
+ # Default: `:reset_password_email`
295
+ #
296
+ # user.reset_password_email_method_name =
148
297
 
149
- # user.reset_password_expiration_period = nil # how many seconds
150
- # before the reset
151
- # request expires. nil
152
- # for never expires.
153
298
 
154
- # user.reset_password_time_between_emails = 5 * 60 # hammering protection,
155
- # how long to wait
156
- # before allowing
157
- # another email to be
158
- # sent.
299
+ # when true sorcery will not automatically
300
+ # email password reset details and allow you to
301
+ # manually handle how and when email is sent
302
+ # Default: `false`
303
+ #
304
+ # user.reset_password_mailer_disabled =
305
+
306
+
307
+ # how many seconds before the reset request expires. nil for never expires.
308
+ # Default: `nil`
309
+ #
310
+ # user.reset_password_expiration_period =
311
+
312
+
313
+ # hammering protection, how long to wait before allowing another email to be sent.
314
+ # Default: `5 * 60`
315
+ #
316
+ # user.reset_password_time_between_emails =
317
+
159
318
 
160
319
  # -- brute_force_protection --
161
- # user.failed_logins_count_attribute_name = :failed_logins_count # failed logins attribute name.
320
+ # Failed logins attribute name.
321
+ # Default: `:failed_logins_count`
322
+ #
323
+ # user.failed_logins_count_attribute_name =
324
+
325
+
326
+ # This field indicates whether user is banned and when it will be active again.
327
+ # Default: `:lock_expires_at`
328
+ #
329
+ # user.lock_expires_at_attribute_name =
330
+
331
+
332
+ # How many failed logins allowed.
333
+ # Default: `50`
334
+ #
335
+ # user.consecutive_login_retries_amount_limit =
336
+
337
+
338
+ # How long the user should be banned. in seconds. 0 for permanent.
339
+ # Default: `60 * 60`
340
+ #
341
+ # user.login_lock_time_period =
162
342
 
163
- # user.lock_expires_at_attribute_name = :lock_expires_at # this field indicates whether
164
- # user is banned and when it will
165
- # be active again.
343
+ # Unlock token attribute name
344
+ # Default: `:unlock_token`
345
+ #
346
+ # user.unlock_token_attribute_name =
166
347
 
167
- # user.consecutive_login_retries_amount_limit = 50 # how many failed logins allowed.
348
+ # Unlock token mailer method
349
+ # Default: `:send_unlock_token_email`
350
+ #
351
+ # user.unlock_token_email_method_name =
168
352
 
169
- # user.login_lock_time_period = 60 * 60 # how long the user should be
170
- # banned. in seconds. 0 for
171
- # permanent.
353
+ # when true sorcery will not automatically
354
+ # send email with unlock token
355
+ # Default: `false`
356
+ #
357
+ # user.unlock_token_mailer_disabled = true
358
+
359
+ # Unlock token mailer class
360
+ # Default: `nil`
361
+ #
362
+ # user.unlock_token_mailer = UserMailer
172
363
 
173
364
  # -- activity logging --
174
- # user.last_login_at_attribute_name = :last_login_at # last login attribute name.
175
- # user.last_logout_at_attribute_name = :last_logout_at # last logout attribute name.
176
- # user.last_activity_at_attribute_name = :last_activity_at # last activity attribute name.
177
- # user.activity_timeout = 10 * 60 # how long since last activity is
178
- # the user defined logged out?
365
+ # Last login attribute name.
366
+ # Default: `:last_login_at`
367
+ #
368
+ # user.last_login_at_attribute_name =
369
+
370
+
371
+ # Last logout attribute name.
372
+ # Default: `:last_logout_at`
373
+ #
374
+ # user.last_logout_at_attribute_name =
375
+
376
+
377
+ # Last activity attribute name.
378
+ # Default: `:last_activity_at`
379
+ #
380
+ # user.last_activity_at_attribute_name =
381
+
382
+
383
+ # How long since last activity is he user defined logged out?
384
+ # Default: `10 * 60`
385
+ #
386
+ # user.activity_timeout =
387
+
179
388
 
180
389
  # -- external --
181
- # user.authentications_class = nil # class which holds the various
182
- # external provider data for this
183
- # user.
390
+ # Class which holds the various external provider data for this user.
391
+ # Default: `nil`
392
+ #
393
+ # user.authentications_class =
394
+
395
+
396
+ # User's identifier in authentications class.
397
+ # Default: `:user_id`
398
+ #
399
+ # user.authentications_user_id_attribute_name =
400
+
184
401
 
185
- # user.authentications_user_id_attribute_name = :user_id # user's identifier in
186
- # authentications class.
402
+ # Provider's identifier in authentications class.
403
+ # Default: `:provider`
404
+ #
405
+ # user.provider_attribute_name =
187
406
 
188
- # user.provider_attribute_name = :provider # provider's identifier in
189
- # authentications class.
190
407
 
191
- # user.provider_uid_attribute_name = :uid # user's external unique
192
- # identifier in authentications
193
- # class.
408
+ # User's external unique identifier in authentications class.
409
+ # Default: `:uid`
410
+ #
411
+ # user.provider_uid_attribute_name =
194
412
  end
195
413
 
196
414
  # This line must come after the 'user config' block.
197
- config.user_class = "<%= model_class_name %>" # define which model authenticates
198
- # with sorcery.
415
+ # Define which model authenticates with sorcery.
416
+ config.user_class = "<%= model_class_name %>"
199
417
  end
@@ -2,10 +2,12 @@ class SorceryBruteForceProtection < ActiveRecord::Migration
2
2
  def self.up
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
5
+ add_column :<%= model_class_name.tableize %>, :unlock_token, :string, :default => nil
5
6
  end
6
7
 
7
8
  def self.down
8
9
  remove_column :<%= model_class_name.tableize %>, :lock_expires_at
9
10
  remove_column :<%= model_class_name.tableize %>, :failed_logins_count
11
+ remove_column :<%= model_class_name.tableize %>, :unlock_token
10
12
  end
11
13
  end
@@ -8,7 +8,7 @@ class SorceryResetPassword < ActiveRecord::Migration
8
8
  end
9
9
 
10
10
  def self.down
11
- remove_index :users, :reset_password_token
11
+ remove_index :<%= model_class_name.tableize %>, :reset_password_token
12
12
 
13
13
  remove_column :<%= model_class_name.tableize %>, :reset_password_email_sent_at
14
14
  remove_column :<%= model_class_name.tableize %>, :reset_password_token_expires_at
@@ -52,14 +52,14 @@ module Sorcery
52
52
  # This runs as a hook just after a successful login.
53
53
  def register_login_time_to_db(user, credentials)
54
54
  return unless Config.register_login_time
55
- user.update_attribute(user.sorcery_config.last_login_at_attribute_name, Time.now.in_time_zone)
55
+ user.update_single_attribute(user.sorcery_config.last_login_at_attribute_name, Time.now.in_time_zone)
56
56
  end
57
57
 
58
58
  # registers last logout time on every logout.
59
59
  # This runs as a hook just before a logout.
60
60
  def register_logout_time_to_db(user)
61
61
  return unless Config.register_logout_time
62
- user.update_attribute(user.sorcery_config.last_logout_at_attribute_name, Time.now.in_time_zone)
62
+ user.update_single_attribute(user.sorcery_config.last_logout_at_attribute_name, Time.now.in_time_zone)
63
63
  end
64
64
 
65
65
  # Updates last activity time on every request.
@@ -67,7 +67,7 @@ module Sorcery
67
67
  def register_last_activity_time_to_db
68
68
  return unless Config.register_last_activity_time
69
69
  return unless logged_in?
70
- current_user.update_attribute(current_user.sorcery_config.last_activity_at_attribute_name, Time.now.in_time_zone)
70
+ current_user.update_single_attribute(current_user.sorcery_config.last_activity_at_attribute_name, Time.now.in_time_zone)
71
71
  end
72
72
  end
73
73
  end
@@ -29,8 +29,7 @@ module Sorcery
29
29
  # Resets the failed logins counter.
30
30
  # Runs as a hook after a successful login.
31
31
  def reset_failed_logins_count!(user, credentials)
32
- user.send(:"#{user_class.sorcery_config.failed_logins_count_attribute_name}=", 0)
33
- user.save!(:validate => false)
32
+ user.update_many_attributes(user_class.sorcery_config.failed_logins_count_attribute_name => 0)
34
33
  end
35
34
  end
36
35
  end
@@ -8,34 +8,34 @@ module Sorcery
8
8
  def oauth_version
9
9
  "2.0"
10
10
  end
11
-
11
+
12
12
  def authorize_url(options = {})
13
+ client = build_client(options)
14
+ client.auth_code.authorize_url(
15
+ :redirect_uri => @callback_url,
16
+ :scope => @scope,
17
+ :display => @display
18
+ )
19
+ end
20
+
21
+ def get_access_token(args, options = {})
22
+ client = build_client(options)
23
+ client.auth_code.get_token(
24
+ args[:code],
25
+ { :redirect_uri => @callback_url, :parse => options.delete(:parse) }, options
26
+ )
27
+ end
28
+
29
+ def build_client(options = {})
13
30
  defaults = {
14
31
  :site => @site,
15
32
  :ssl => { :ca_file => Config.ca_file }
16
33
  }
17
- client = ::OAuth2::Client.new(
34
+ ::OAuth2::Client.new(
18
35
  @key,
19
36
  @secret,
20
37
  defaults.merge!(options)
21
38
  )
22
- client.web_server.authorize_url(
23
- :redirect_uri => @callback_url,
24
- :scope => @scope
25
- )
26
- end
27
-
28
- def get_access_token(args)
29
- client = ::OAuth2::Client.new(
30
- @key,
31
- @secret,
32
- :site => @site,
33
- :ssl => { :ca_file => Config.ca_file }
34
- )
35
- client.web_server.get_access_token(
36
- args[:code],
37
- :redirect_uri => @callback_url
38
- )
39
39
  end
40
40
  end
41
41
  end