sorcery 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sorcery might be problematic. Click here for more details.

Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +75 -14
  4. data/CHANGELOG.md +23 -1
  5. data/Gemfile +1 -0
  6. data/README.md +137 -86
  7. data/gemfiles/active_record-rails40.gemfile +7 -0
  8. data/gemfiles/active_record-rails41.gemfile +3 -2
  9. data/gemfiles/mongo_mapper-rails40.gemfile +9 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +2 -1
  11. data/gemfiles/mongoid-rails40.gemfile +9 -0
  12. data/gemfiles/mongoid-rails41.gemfile +3 -5
  13. data/gemfiles/mongoid3-rails32.gemfile +9 -0
  14. data/lib/generators/sorcery/USAGE +1 -1
  15. data/lib/generators/sorcery/install_generator.rb +19 -5
  16. data/lib/generators/sorcery/templates/initializer.rb +34 -9
  17. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -1
  18. data/lib/generators/sorcery/templates/migration/core.rb +2 -2
  19. data/lib/generators/sorcery/templates/migration/external.rb +3 -1
  20. data/lib/sorcery.rb +75 -43
  21. data/lib/sorcery/adapters/active_record_adapter.rb +120 -0
  22. data/lib/sorcery/adapters/base_adapter.rb +30 -0
  23. data/lib/sorcery/adapters/data_mapper_adapter.rb +176 -0
  24. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +110 -0
  25. data/lib/sorcery/adapters/mongoid_adapter.rb +97 -0
  26. data/lib/sorcery/controller.rb +5 -64
  27. data/lib/sorcery/controller/config.rb +65 -0
  28. data/lib/sorcery/controller/submodules/activity_logging.rb +16 -21
  29. data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
  30. data/lib/sorcery/controller/submodules/external.rb +8 -28
  31. data/lib/sorcery/controller/submodules/remember_me.rb +4 -4
  32. data/lib/sorcery/controller/submodules/session_timeout.rb +10 -6
  33. data/lib/sorcery/model.rb +43 -175
  34. data/lib/sorcery/model/config.rb +96 -0
  35. data/lib/sorcery/model/submodules/activity_logging.rb +29 -36
  36. data/lib/sorcery/model/submodules/brute_force_protection.rb +21 -37
  37. data/lib/sorcery/model/submodules/external.rb +53 -9
  38. data/lib/sorcery/model/submodules/remember_me.rb +12 -31
  39. data/lib/sorcery/model/submodules/reset_password.rb +21 -39
  40. data/lib/sorcery/model/submodules/user_activation.rb +21 -63
  41. data/lib/sorcery/model/temporary_token.rb +4 -4
  42. data/lib/sorcery/providers/base.rb +11 -0
  43. data/lib/sorcery/providers/facebook.rb +1 -1
  44. data/lib/sorcery/providers/github.rb +1 -1
  45. data/lib/sorcery/providers/google.rb +1 -1
  46. data/lib/sorcery/providers/heroku.rb +57 -0
  47. data/lib/sorcery/providers/jira.rb +77 -0
  48. data/lib/sorcery/providers/linkedin.rb +1 -1
  49. data/lib/sorcery/providers/liveid.rb +1 -1
  50. data/lib/sorcery/providers/salesforce.rb +50 -0
  51. data/lib/sorcery/providers/twitter.rb +1 -1
  52. data/lib/sorcery/providers/vk.rb +6 -4
  53. data/lib/sorcery/providers/xing.rb +1 -1
  54. data/lib/sorcery/test_helpers/internal.rb +7 -3
  55. data/lib/sorcery/test_helpers/rails/controller.rb +5 -1
  56. data/lib/sorcery/version.rb +3 -0
  57. data/sorcery.gemspec +6 -2
  58. data/spec/active_record/user_activity_logging_spec.rb +9 -0
  59. data/spec/controllers/controller_activity_logging_spec.rb +124 -0
  60. data/spec/controllers/controller_brute_force_protection_spec.rb +43 -0
  61. data/spec/{active_record → controllers}/controller_http_basic_auth_spec.rb +14 -11
  62. data/spec/{active_record → controllers}/controller_oauth2_spec.rb +128 -56
  63. data/spec/{active_record → controllers}/controller_oauth_spec.rb +94 -70
  64. data/spec/{active_record → controllers}/controller_remember_me_spec.rb +32 -12
  65. data/spec/{active_record → controllers}/controller_session_timeout_spec.rb +15 -5
  66. data/spec/{shared_examples/controller_shared_examples.rb → controllers/controller_spec.rb} +34 -19
  67. data/spec/{datamapper → data_mapper}/user_activation_spec.rb +1 -1
  68. data/spec/data_mapper/user_activity_logging_spec.rb +14 -0
  69. data/spec/{datamapper → data_mapper}/user_brute_force_protection_spec.rb +1 -1
  70. data/spec/{datamapper → data_mapper}/user_oauth_spec.rb +1 -1
  71. data/spec/{datamapper → data_mapper}/user_remember_me_spec.rb +1 -1
  72. data/spec/{datamapper → data_mapper}/user_reset_password_spec.rb +1 -1
  73. data/spec/{datamapper → data_mapper}/user_spec.rb +1 -1
  74. data/spec/mongoid/user_spec.rb +13 -0
  75. data/spec/orm/active_record.rb +12 -0
  76. data/spec/orm/{datamapper.rb → data_mapper.rb} +16 -2
  77. data/spec/orm/mongo_mapper.rb +0 -1
  78. data/spec/orm/mongoid.rb +4 -0
  79. data/spec/rails_app/app/controllers/sorcery_controller.rb +62 -1
  80. data/spec/rails_app/app/{datamapper → data_mapper}/authentication.rb +0 -0
  81. data/spec/rails_app/app/{datamapper → data_mapper}/user.rb +0 -0
  82. data/spec/rails_app/app/mongo_mapper/user.rb +2 -0
  83. data/spec/rails_app/config/routes.rb +9 -0
  84. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +2 -2
  85. data/spec/shared_examples/user_activation_shared_examples.rb +7 -7
  86. data/spec/shared_examples/user_activity_logging_shared_examples.rb +73 -5
  87. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +127 -9
  88. data/spec/shared_examples/user_oauth_shared_examples.rb +3 -6
  89. data/spec/shared_examples/user_remember_me_shared_examples.rb +6 -3
  90. data/spec/shared_examples/user_reset_password_shared_examples.rb +10 -10
  91. data/spec/shared_examples/user_shared_examples.rb +117 -30
  92. data/spec/spec_helper.rb +7 -22
  93. metadata +36 -58
  94. data/Gemfile.rails4 +0 -22
  95. data/VERSION +0 -1
  96. data/lib/sorcery/model/adapters/active_record.rb +0 -54
  97. data/lib/sorcery/model/adapters/datamapper.rb +0 -123
  98. data/lib/sorcery/model/adapters/mongo_mapper.rb +0 -60
  99. data/lib/sorcery/model/adapters/mongoid.rb +0 -88
  100. data/lib/sorcery/test_helpers/rails.rb +0 -7
  101. data/spec/active_record/controller_activity_logging_spec.rb +0 -29
  102. data/spec/active_record/controller_brute_force_protection_spec.rb +0 -158
  103. data/spec/active_record/controller_spec.rb +0 -8
  104. data/spec/active_record/integration_spec.rb +0 -23
  105. data/spec/datamapper/controller_activity_logging_spec.rb +0 -17
  106. data/spec/datamapper/controller_spec.rb +0 -8
  107. data/spec/datamapper/user_activity_logging_spec.rb +0 -9
  108. data/spec/mongo_mapper/controller_spec.rb +0 -8
  109. data/spec/mongoid/controller_activity_logging_spec.rb +0 -16
  110. data/spec/mongoid/controller_spec.rb +0 -8
  111. data/spec/rails_app/public/404.html +0 -26
  112. data/spec/rails_app/public/422.html +0 -26
  113. data/spec/rails_app/public/500.html +0 -26
  114. data/spec/rails_app/public/favicon.ico +0 -0
  115. data/spec/rails_app/public/images/rails.png +0 -0
  116. data/spec/rails_app/public/javascripts/application.js +0 -2
  117. data/spec/rails_app/public/javascripts/controls.js +0 -965
  118. data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
  119. data/spec/rails_app/public/javascripts/effects.js +0 -1123
  120. data/spec/rails_app/public/javascripts/prototype.js +0 -6001
  121. data/spec/rails_app/public/javascripts/rails.js +0 -175
  122. data/spec/rails_app/public/robots.txt +0 -5
  123. data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
  124. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +0 -125
  125. data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -52
  126. data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -62
@@ -15,6 +15,9 @@ require 'rails/all'
15
15
  require 'rspec/rails'
16
16
  require 'timecop'
17
17
 
18
+ def setup_orm; end
19
+ def teardown_orm; end
20
+
18
21
  require "orm/#{SORCERY_ORM}"
19
22
 
20
23
  require "rails_app/config/environment"
@@ -27,33 +30,15 @@ RSpec.configure do |config|
27
30
  config.include RSpec::Rails::ControllerExampleGroup, :file_path => /controller(.)*_spec.rb$/
28
31
  config.filter_run_excluding :active_record => SORCERY_ORM.to_sym != :active_record
29
32
  config.filter_run_excluding :mongo_mapper => SORCERY_ORM.to_sym != :mongo_mapper
30
- config.filter_run_excluding :datamapper => SORCERY_ORM.to_sym != :datamapper
33
+ config.filter_run_excluding :data_mapper => SORCERY_ORM.to_sym != :data_mapper
31
34
  config.filter_run_excluding :mongoid => SORCERY_ORM.to_sym != :mongoid
32
35
  config.mock_with :rspec
33
36
 
34
37
  config.use_transactional_fixtures = true
35
38
 
36
- migrations_path = Rails.root.join("db", "migrate", "core")
37
-
38
- config.before(:suite) do
39
- if SORCERY_ORM.to_sym == :active_record
40
- ActiveRecord::Migrator.migrate(migrations_path)
41
- end
42
- if SORCERY_ORM.to_sym == :datamapper
43
- DataMapper.auto_migrate!
44
- DataMapper.finalize
45
- end
46
-
47
- if defined?(Mongoid)
48
- Mongoid.purge!
49
- end
50
- end
51
-
52
- config.after(:suite) do
53
- if SORCERY_ORM.to_sym == :active_record
54
- ActiveRecord::Migrator.rollback(migrations_path)
55
- end
56
- end
39
+ config.before(:suite) { setup_orm }
40
+ config.after(:suite) { teardown_orm }
41
+ config.before(:each) { ActionMailer::Base.deliveries.clear }
57
42
 
58
43
  config.include ::Sorcery::TestHelpers::Internal
59
44
  config.include ::Sorcery::TestHelpers::Internal::Rails
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorcery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noam Ben Ari
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-06-15 00:00:00.000000000 Z
13
+ date: 2015-01-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: oauth
@@ -39,9 +39,6 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.8.0
42
- - - "<"
43
- - !ruby/object:Gem::Version
44
- version: 1.0.0
45
42
  type: :runtime
46
43
  prerelease: false
47
44
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,9 +46,6 @@ dependencies:
49
46
  - - ">="
50
47
  - !ruby/object:Gem::Version
51
48
  version: 0.8.0
52
- - - "<"
53
- - !ruby/object:Gem::Version
54
- version: 1.0.0
55
49
  - !ruby/object:Gem::Dependency
56
50
  name: bcrypt
57
51
  requirement: !ruby/object:Gem::Requirement
@@ -177,14 +171,16 @@ files:
177
171
  - ".travis.yml"
178
172
  - CHANGELOG.md
179
173
  - Gemfile
180
- - Gemfile.rails4
181
174
  - LICENSE.txt
182
175
  - README.md
183
176
  - Rakefile
184
- - VERSION
177
+ - gemfiles/active_record-rails40.gemfile
185
178
  - gemfiles/active_record-rails41.gemfile
179
+ - gemfiles/mongo_mapper-rails40.gemfile
186
180
  - gemfiles/mongo_mapper-rails41.gemfile
181
+ - gemfiles/mongoid-rails40.gemfile
187
182
  - gemfiles/mongoid-rails41.gemfile
183
+ - gemfiles/mongoid3-rails32.gemfile
188
184
  - lib/generators/sorcery/USAGE
189
185
  - lib/generators/sorcery/helpers.rb
190
186
  - lib/generators/sorcery/install_generator.rb
@@ -197,7 +193,13 @@ files:
197
193
  - lib/generators/sorcery/templates/migration/reset_password.rb
198
194
  - lib/generators/sorcery/templates/migration/user_activation.rb
199
195
  - lib/sorcery.rb
196
+ - lib/sorcery/adapters/active_record_adapter.rb
197
+ - lib/sorcery/adapters/base_adapter.rb
198
+ - lib/sorcery/adapters/data_mapper_adapter.rb
199
+ - lib/sorcery/adapters/mongo_mapper_adapter.rb
200
+ - lib/sorcery/adapters/mongoid_adapter.rb
200
201
  - lib/sorcery/controller.rb
202
+ - lib/sorcery/controller/config.rb
201
203
  - lib/sorcery/controller/submodules/activity_logging.rb
202
204
  - lib/sorcery/controller/submodules/brute_force_protection.rb
203
205
  - lib/sorcery/controller/submodules/external.rb
@@ -213,10 +215,7 @@ files:
213
215
  - lib/sorcery/crypto_providers/sha512.rb
214
216
  - lib/sorcery/engine.rb
215
217
  - lib/sorcery/model.rb
216
- - lib/sorcery/model/adapters/active_record.rb
217
- - lib/sorcery/model/adapters/datamapper.rb
218
- - lib/sorcery/model/adapters/mongo_mapper.rb
219
- - lib/sorcery/model/adapters/mongoid.rb
218
+ - lib/sorcery/model/config.rb
220
219
  - lib/sorcery/model/submodules/activity_logging.rb
221
220
  - lib/sorcery/model/submodules/brute_force_protection.rb
222
221
  - lib/sorcery/model/submodules/external.rb
@@ -231,27 +230,21 @@ files:
231
230
  - lib/sorcery/providers/facebook.rb
232
231
  - lib/sorcery/providers/github.rb
233
232
  - lib/sorcery/providers/google.rb
233
+ - lib/sorcery/providers/heroku.rb
234
+ - lib/sorcery/providers/jira.rb
234
235
  - lib/sorcery/providers/linkedin.rb
235
236
  - lib/sorcery/providers/liveid.rb
237
+ - lib/sorcery/providers/salesforce.rb
236
238
  - lib/sorcery/providers/twitter.rb
237
239
  - lib/sorcery/providers/vk.rb
238
240
  - lib/sorcery/providers/xing.rb
239
241
  - lib/sorcery/railties/tasks.rake
240
242
  - lib/sorcery/test_helpers/internal.rb
241
243
  - lib/sorcery/test_helpers/internal/rails.rb
242
- - lib/sorcery/test_helpers/rails.rb
243
244
  - lib/sorcery/test_helpers/rails/controller.rb
244
245
  - lib/sorcery/test_helpers/rails/integration.rb
246
+ - lib/sorcery/version.rb
245
247
  - sorcery.gemspec
246
- - spec/active_record/controller_activity_logging_spec.rb
247
- - spec/active_record/controller_brute_force_protection_spec.rb
248
- - spec/active_record/controller_http_basic_auth_spec.rb
249
- - spec/active_record/controller_oauth2_spec.rb
250
- - spec/active_record/controller_oauth_spec.rb
251
- - spec/active_record/controller_remember_me_spec.rb
252
- - spec/active_record/controller_session_timeout_spec.rb
253
- - spec/active_record/controller_spec.rb
254
- - spec/active_record/integration_spec.rb
255
248
  - spec/active_record/user_activation_spec.rb
256
249
  - spec/active_record/user_activity_logging_spec.rb
257
250
  - spec/active_record/user_brute_force_protection_spec.rb
@@ -259,16 +252,21 @@ files:
259
252
  - spec/active_record/user_remember_me_spec.rb
260
253
  - spec/active_record/user_reset_password_spec.rb
261
254
  - spec/active_record/user_spec.rb
262
- - spec/datamapper/controller_activity_logging_spec.rb
263
- - spec/datamapper/controller_spec.rb
264
- - spec/datamapper/user_activation_spec.rb
265
- - spec/datamapper/user_activity_logging_spec.rb
266
- - spec/datamapper/user_brute_force_protection_spec.rb
267
- - spec/datamapper/user_oauth_spec.rb
268
- - spec/datamapper/user_remember_me_spec.rb
269
- - spec/datamapper/user_reset_password_spec.rb
270
- - spec/datamapper/user_spec.rb
271
- - spec/mongo_mapper/controller_spec.rb
255
+ - spec/controllers/controller_activity_logging_spec.rb
256
+ - spec/controllers/controller_brute_force_protection_spec.rb
257
+ - spec/controllers/controller_http_basic_auth_spec.rb
258
+ - spec/controllers/controller_oauth2_spec.rb
259
+ - spec/controllers/controller_oauth_spec.rb
260
+ - spec/controllers/controller_remember_me_spec.rb
261
+ - spec/controllers/controller_session_timeout_spec.rb
262
+ - spec/controllers/controller_spec.rb
263
+ - spec/data_mapper/user_activation_spec.rb
264
+ - spec/data_mapper/user_activity_logging_spec.rb
265
+ - spec/data_mapper/user_brute_force_protection_spec.rb
266
+ - spec/data_mapper/user_oauth_spec.rb
267
+ - spec/data_mapper/user_remember_me_spec.rb
268
+ - spec/data_mapper/user_reset_password_spec.rb
269
+ - spec/data_mapper/user_spec.rb
272
270
  - spec/mongo_mapper/user_activation_spec.rb
273
271
  - spec/mongo_mapper/user_activity_logging_spec.rb
274
272
  - spec/mongo_mapper/user_brute_force_protection_spec.rb
@@ -276,8 +274,6 @@ files:
276
274
  - spec/mongo_mapper/user_remember_me_spec.rb
277
275
  - spec/mongo_mapper/user_reset_password_spec.rb
278
276
  - spec/mongo_mapper/user_spec.rb
279
- - spec/mongoid/controller_activity_logging_spec.rb
280
- - spec/mongoid/controller_spec.rb
281
277
  - spec/mongoid/user_activation_spec.rb
282
278
  - spec/mongoid/user_activity_logging_spec.rb
283
279
  - spec/mongoid/user_brute_force_protection_spec.rb
@@ -286,15 +282,15 @@ files:
286
282
  - spec/mongoid/user_reset_password_spec.rb
287
283
  - spec/mongoid/user_spec.rb
288
284
  - spec/orm/active_record.rb
289
- - spec/orm/datamapper.rb
285
+ - spec/orm/data_mapper.rb
290
286
  - spec/orm/mongo_mapper.rb
291
287
  - spec/orm/mongoid.rb
292
288
  - spec/rails_app/app/active_record/authentication.rb
293
289
  - spec/rails_app/app/active_record/user.rb
294
290
  - spec/rails_app/app/active_record/user_provider.rb
295
291
  - spec/rails_app/app/controllers/sorcery_controller.rb
296
- - spec/rails_app/app/datamapper/authentication.rb
297
- - spec/rails_app/app/datamapper/user.rb
292
+ - spec/rails_app/app/data_mapper/authentication.rb
293
+ - spec/rails_app/app/data_mapper/user.rb
298
294
  - spec/rails_app/app/helpers/application_helper.rb
299
295
  - spec/rails_app/app/mailers/sorcery_mailer.rb
300
296
  - spec/rails_app/app/mongo_mapper/authentication.rb
@@ -334,23 +330,6 @@ files:
334
330
  - spec/rails_app/db/schema.rb
335
331
  - spec/rails_app/db/seeds.rb
336
332
  - spec/rails_app/log/development.log
337
- - spec/rails_app/public/404.html
338
- - spec/rails_app/public/422.html
339
- - spec/rails_app/public/500.html
340
- - spec/rails_app/public/favicon.ico
341
- - spec/rails_app/public/images/rails.png
342
- - spec/rails_app/public/javascripts/application.js
343
- - spec/rails_app/public/javascripts/controls.js
344
- - spec/rails_app/public/javascripts/dragdrop.js
345
- - spec/rails_app/public/javascripts/effects.js
346
- - spec/rails_app/public/javascripts/prototype.js
347
- - spec/rails_app/public/javascripts/rails.js
348
- - spec/rails_app/public/robots.txt
349
- - spec/rails_app/public/stylesheets/.gitkeep
350
- - spec/shared_examples/controller_activity_logging_shared_examples.rb
351
- - spec/shared_examples/controller_oauth2_shared_examples.rb
352
- - spec/shared_examples/controller_oauth_shared_examples.rb
353
- - spec/shared_examples/controller_shared_examples.rb
354
333
  - spec/shared_examples/user_activation_shared_examples.rb
355
334
  - spec/shared_examples/user_activity_logging_shared_examples.rb
356
335
  - spec/shared_examples/user_brute_force_protection_shared_examples.rb
@@ -381,9 +360,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
381
360
  version: '0'
382
361
  requirements: []
383
362
  rubyforge_project:
384
- rubygems_version: 2.2.1
363
+ rubygems_version: 2.2.2
385
364
  signing_key:
386
365
  specification_version: 4
387
366
  summary: Magical authentication for Rails 3 & 4 applications
388
367
  test_files: []
389
- has_rdoc:
@@ -1,22 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'sqlite3'
4
-
5
- group :mongomapper do
6
- gem 'mongo_mapper', github: 'jnunemaker/mongomapper'
7
- end
8
-
9
- group :mongoid do
10
- gem 'mongoid', github: 'mongoid/mongoid', ref: 'f91feef0a0c6b83a1b878e154f1014536aa1c298'
11
- gem 'bson_ext'
12
- end
13
-
14
- group :datamapper do
15
- gem 'mysql2'
16
- gem 'data_mapper'
17
- gem 'dm-mysql-adapter'
18
- end
19
-
20
- gem 'rails', '~> 4.0.1'
21
-
22
- gemspec
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.8.5
@@ -1,54 +0,0 @@
1
- module Sorcery
2
- module Model
3
- module Adapters
4
- module ActiveRecord
5
- def self.included(klass)
6
- klass.extend ClassMethods
7
- klass.send(:include, InstanceMethods)
8
- end
9
-
10
- module InstanceMethods
11
- def update_many_attributes(attrs)
12
- attrs.each do |name, value|
13
- self.send(:"#{name}=", value)
14
- end
15
- primary_key = self.class.primary_key
16
- self.class.where(:"#{primary_key}" => self.send(:"#{primary_key}")).update_all(attrs)
17
- end
18
-
19
- def update_single_attribute(name, value)
20
- update_many_attributes(name => value)
21
- end
22
-
23
- def sorcery_save(options = {})
24
- mthd = options.delete(:raise_on_failure) ? :save! : :save
25
- self.send(mthd, options)
26
- end
27
- end
28
-
29
- module ClassMethods
30
- def column_name(attribute)
31
- return "LOWER(#{attribute})" if (@sorcery_config.downcase_username_before_authenticating)
32
- attribute.to_s
33
- end
34
-
35
- def find_by_credentials(credentials)
36
- sql = @sorcery_config.username_attribute_names.map{|attribute| column_name(attribute) + " = :login"}
37
- where(sql.join(' OR '), :login => credentials[0]).first
38
- end
39
-
40
- def find_by_sorcery_token(token_attr_name, token)
41
- where("#{token_attr_name} = ?", token).first
42
- end
43
-
44
- def get_current_users
45
- config = @sorcery_config
46
- where("#{config.last_activity_at_attribute_name} IS NOT NULL") \
47
- .where("#{config.last_logout_at_attribute_name} IS NULL OR #{config.last_activity_at_attribute_name} > #{config.last_logout_at_attribute_name}") \
48
- .where("#{config.last_activity_at_attribute_name} > ? ", config.activity_timeout.seconds.ago.utc.to_s(:db))
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,123 +0,0 @@
1
- module Sorcery
2
- module Model
3
- module Adapters
4
- module DataMapper
5
- def self.included(klass)
6
- klass.extend ClassMethods
7
- klass.send(:include, InstanceMethods)
8
- end
9
-
10
- module InstanceMethods
11
- def increment(attr)
12
- self[attr] ||= 0
13
- self[attr] += 1
14
- self
15
- end
16
-
17
- def update_many_attributes(attrs)
18
- attrs.each do |name, value|
19
- value = value.utc if value.is_a?(ActiveSupport::TimeWithZone)
20
- self.send(:"#{name}=", value)
21
- end
22
- self.class.get(self.id).update(attrs)
23
- end
24
-
25
- def update_single_attribute(name, value)
26
- update_many_attributes(name => value)
27
- end
28
-
29
- def sorcery_save(options = {})
30
- if options.key?(:validate) && ! options[:validate]
31
- save!
32
- else
33
- save
34
- end
35
- end
36
- end
37
-
38
- module ClassMethods
39
- def find(id)
40
- get(id)
41
- end
42
-
43
- def delete_all
44
- destroy
45
- end
46
-
47
- # NOTE
48
- # DM Adapter dependent
49
- # DM creates MySQL tables case insensitive by default
50
- # http://datamapper.lighthouseapp.com/projects/20609-datamapper/tickets/1105
51
- def find_by_credentials(credentials)
52
- credential = credentials[0].dup
53
- credential.downcase! if @sorcery_config.downcase_username_before_authenticating
54
- @sorcery_config.username_attribute_names.each do |name|
55
- @user = first(name => credential)
56
- break if @user
57
- end
58
- !!@user ? get(@user.id) : nil
59
- end
60
-
61
- def find_by_provider_and_uid(provider, uid)
62
- @user_klass ||= ::Sorcery::Controller::Config.user_class.to_s.constantize
63
- user = first(@user_klass.sorcery_config.provider_attribute_name => provider, @user_klass.sorcery_config.provider_uid_attribute_name => uid)
64
- !!user ? get(user.id) : nil
65
- end
66
-
67
- def find_by_id(id)
68
- find(id)
69
- rescue ::DataMapper::ObjectNotFoundError
70
- nil
71
- end
72
-
73
- def find_by_activation_token(token)
74
- user = first(sorcery_config.activation_token_attribute_name => token)
75
- !!user ? get(user.id) : nil
76
- end
77
-
78
- def find_by_remember_me_token(token)
79
- user = first(sorcery_config.remember_me_token_attribute_name => token)
80
- !!user ? get(user.id) : nil
81
- end
82
-
83
- def find_by_username(username)
84
- user = nil
85
- sorcery_config.username_attribute_names.each do |name|
86
- user = first(name => username)
87
- break if user
88
- end
89
- !!user ? get(user.id) : nil
90
- end
91
-
92
- def transaction(&blk)
93
- tap(&blk)
94
- end
95
-
96
- def find_by_sorcery_token(token_attr_name, token)
97
- user = first(token_attr_name => token)
98
- !!user ? get(user.id) : nil
99
- end
100
-
101
- def find_by_email(email)
102
- user = first(sorcery_config.email_attribute_name => email)
103
- !!user ? get(user.id) : nil
104
- end
105
-
106
- # NOTE
107
- # DM Adapter dependent
108
- def get_current_users
109
- unless self.repository.adapter.is_a?(::DataMapper::Adapters::MysqlAdapter)
110
- raise 'Unsupported DataMapper Adapter'
111
- end
112
- config = sorcery_config
113
- ret = all(config.last_logout_at_attribute_name => nil) |
114
- all(config.last_activity_at_attribute_name.gt => config.last_logout_at_attribute_name)
115
- ret = ret.all(config.last_activity_at_attribute_name.not => nil)
116
- ret = ret.all(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc)
117
- ret
118
- end
119
- end
120
- end
121
- end
122
- end
123
- end