sorcery 0.10.2 → 0.10.3

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52531921390dcbdf3af822e2042445099effba31
4
- data.tar.gz: 0371505f7cf6d86ad0fd31fa04f6a0fe94029ade
3
+ metadata.gz: 834f45ceded7dd7507da33d0cafad5b379998102
4
+ data.tar.gz: 194d9e21b374a802866f293df90142725a632c66
5
5
  SHA512:
6
- metadata.gz: 241a97cd9ab0abf01812f9e103de6508d2abc95e7522430e845917bed47179d180bff41a8a906069e30cac5b8d188c1298879711acbd1d1347e3e73088100d36
7
- data.tar.gz: 341766db00f2d304cbd637ec258873df61dd691e354449ba2f6c943cb581844075b135c3b522e77c19fc4cc3379d6ff0d60717b6bc19374c955288dce7abc42f
6
+ metadata.gz: 87cc0189f538838548bb214779dadf2ee384f7d024e38db8a58ad4fbaf0ba6ea04872d745d307c47665bc2ad6016eb98cdd14eb9be64d41ce44310122e3082d0
7
+ data.tar.gz: bb35b65397c6ed3f8285d5d098edb475b8f7733eef644e95b0d9c56a7bad36090f6f4e92e59c5f7d332b837fde0e93948b642ce2e767d8ab77f30b6e687d2bda
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.3
4
+
5
+ * Revert removal of MongoID Adapter (breaks Sorcery for MongoID users until separate gem is created) [#45](https://github.com/Sorcery/sorcery/pull/45)
6
+
3
7
  ## 0.10.2
4
8
 
5
9
  * Added support for Microsoft OAuth (thanks to @athix) [#37](https://github.com/Sorcery/sorcery/pull/37)
@@ -0,0 +1,97 @@
1
+ module Sorcery
2
+ module Adapters
3
+ class MongoidAdapter < BaseAdapter
4
+ def increment(attr)
5
+ mongoid_4? ? @model.inc(attr => 1) : @model.inc(attr, 1)
6
+ end
7
+
8
+ def update_attributes(attrs)
9
+ attrs.each do |name, value|
10
+ attrs[name] = value.utc if value.is_a?(ActiveSupport::TimeWithZone)
11
+ @model.send(:"#{name}=", value)
12
+ end
13
+ @model.class.where(:_id => @model.id).update_all(attrs)
14
+ end
15
+
16
+ def update_attribute(name, value)
17
+ update_attributes(name => value)
18
+ end
19
+
20
+ def save(options = {})
21
+ mthd = options.delete(:raise_on_failure) ? :save! : :save
22
+ @model.send(mthd, options)
23
+ end
24
+
25
+ def mongoid_4?
26
+ Gem::Version.new(::Mongoid::VERSION) >= Gem::Version.new("4.0.0.alpha")
27
+ end
28
+
29
+ class << self
30
+
31
+ def define_field(name, type, options={})
32
+ @klass.field name, options.slice(:default).merge(type: type)
33
+ end
34
+
35
+ def define_callback(time, event, method_name, options={})
36
+ @klass.send "#{time}_#{event}", method_name, options.slice(:if)
37
+ end
38
+
39
+ def credential_regex(credential)
40
+ return { :$regex => /^#{Regexp.escape(credential)}$/i } if (@klass.sorcery_config.downcase_username_before_authenticating)
41
+ credential
42
+ end
43
+
44
+ def find_by_credentials(credentials)
45
+ @klass.sorcery_config.username_attribute_names.each do |attribute|
46
+ @user = @klass.where(attribute => credential_regex(credentials[0])).first
47
+ break if @user
48
+ end
49
+ @user
50
+ end
51
+
52
+ def find_by_oauth_credentials(provider, uid)
53
+ @user_config ||= ::Sorcery::Controller::Config.user_class.to_s.constantize.sorcery_config
54
+ @klass.where(@user_config.provider_attribute_name => provider, @user_config.provider_uid_attribute_name => uid).first
55
+ end
56
+
57
+ def find_by_activation_token(token)
58
+ @klass.where(@klass.sorcery_config.activation_token_attribute_name => token).first
59
+ end
60
+
61
+ def find_by_remember_me_token(token)
62
+ @klass.where(@klass.sorcery_config.remember_me_token_attribute_name => token).first
63
+ end
64
+
65
+ def transaction(&blk)
66
+ tap(&blk)
67
+ end
68
+
69
+ def find_by_id(id)
70
+ @klass.find(id)
71
+ rescue ::Mongoid::Errors::DocumentNotFound
72
+ nil
73
+ end
74
+
75
+ def find_by_username(username)
76
+ query = @klass.sorcery_config.username_attribute_names.map {|name| {name => username}}
77
+ @klass.any_of(*query).first
78
+ end
79
+
80
+ def find_by_token(token_attr_name, token)
81
+ @klass.where(token_attr_name => token).first
82
+ end
83
+
84
+ def find_by_email(email)
85
+ @klass.where(@klass.sorcery_config.email_attribute_name => email).first
86
+ end
87
+
88
+ def get_current_users
89
+ config = @klass.sorcery_config
90
+ @klass.where(config.last_activity_at_attribute_name.ne => nil) \
91
+ .where("this.#{config.last_logout_at_attribute_name} == null || this.#{config.last_activity_at_attribute_name} > this.#{config.last_logout_at_attribute_name}") \
92
+ .where(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc).order_by([:_id,:asc])
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,3 +1,3 @@
1
1
  module Sorcery
2
- VERSION = '0.10.2'
2
+ VERSION = '0.10.3'
3
3
  end
data/lib/sorcery.rb CHANGED
@@ -65,7 +65,7 @@ module Sorcery
65
65
 
66
66
  require 'sorcery/adapters/base_adapter'
67
67
 
68
- if defined?(ActiveRecord)
68
+ if defined?(ActiveRecord::Base)
69
69
  require 'sorcery/adapters/active_record_adapter'
70
70
  ActiveRecord::Base.extend Sorcery::Model
71
71
 
@@ -78,5 +78,18 @@ module Sorcery
78
78
  end
79
79
  end
80
80
 
81
+ if defined?(Mongoid::Document)
82
+ require 'sorcery/adapters/mongoid_adapter'
83
+ Mongoid::Document::ClassMethods.send :include, Sorcery::Model
84
+
85
+ Mongoid::Document.send :define_method, :sorcery_adapter do
86
+ @sorcery_adapter ||= Sorcery::Adapters::MongoidAdapter.new(self)
87
+ end
88
+
89
+ Mongoid::Document::ClassMethods.send :define_method, :sorcery_adapter do
90
+ Sorcery::Adapters::MongoidAdapter.from(self)
91
+ end
92
+ end
93
+
81
94
  require 'sorcery/engine' if defined?(Rails)
82
95
  end
data/sorcery.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
10
10
  s.description = 'Provides common authentication needs such as signing in/out, activating by email and resetting password.'
11
11
  s.summary = 'Magical authentication for Rails applications'
12
12
  s.homepage = 'https://github.com/Sorcery/sorcery'
13
- s.post_install_message = "As of version 1.0 oauth/oauth2 won't be automatically bundled\n"
14
- s.post_install_message += 'you need to add those dependencies to your Gemfile'
13
+ s.post_install_message = "As of version 1.0 oauth/oauth2 won't be automatically bundled so you may need to add those dependencies to your Gemfile.\n"
14
+ s.post_install_message += 'You may need oauth2 if you use external providers such as any of these: https://github.com/Sorcery/sorcery/tree/master/lib/sorcery/providers'
15
15
 
16
16
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
17
  s.require_paths = ['lib']
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.10.2
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noam Ben Ari
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-01-04 00:00:00.000000000 Z
14
+ date: 2017-03-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: oauth
@@ -184,6 +184,7 @@ files:
184
184
  - lib/sorcery.rb
185
185
  - lib/sorcery/adapters/active_record_adapter.rb
186
186
  - lib/sorcery/adapters/base_adapter.rb
187
+ - lib/sorcery/adapters/mongoid_adapter.rb
187
188
  - lib/sorcery/controller.rb
188
189
  - lib/sorcery/controller/config.rb
189
190
  - lib/sorcery/controller/submodules/activity_logging.rb
@@ -304,8 +305,8 @@ licenses:
304
305
  - MIT
305
306
  metadata: {}
306
307
  post_install_message: |-
307
- As of version 1.0 oauth/oauth2 won't be automatically bundled
308
- you need to add those dependencies to your Gemfile
308
+ As of version 1.0 oauth/oauth2 won't be automatically bundled so you may need to add those dependencies to your Gemfile.
309
+ You may need oauth2 if you use external providers such as any of these: https://github.com/Sorcery/sorcery/tree/master/lib/sorcery/providers
309
310
  rdoc_options: []
310
311
  require_paths:
311
312
  - lib