sorcery 0.9.1 → 0.10.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 (149) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -104
  3. data/CHANGELOG.md +13 -1
  4. data/Gemfile +2 -16
  5. data/README.md +124 -272
  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 +27 -52
  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 +2 -2
  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.rb +0 -28
  19. data/lib/sorcery/adapters/active_record_adapter.rb +7 -18
  20. data/lib/sorcery/controller.rb +19 -21
  21. data/lib/sorcery/controller/config.rb +20 -18
  22. data/lib/sorcery/controller/submodules/activity_logging.rb +7 -15
  23. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  24. data/lib/sorcery/controller/submodules/external.rb +22 -14
  25. data/lib/sorcery/controller/submodules/http_basic_auth.rb +16 -19
  26. data/lib/sorcery/controller/submodules/remember_me.rb +15 -10
  27. data/lib/sorcery/controller/submodules/session_timeout.rb +7 -8
  28. data/lib/sorcery/crypto_providers/aes256.rb +15 -15
  29. data/lib/sorcery/crypto_providers/bcrypt.rb +19 -21
  30. data/lib/sorcery/crypto_providers/common.rb +1 -1
  31. data/lib/sorcery/crypto_providers/md5.rb +5 -5
  32. data/lib/sorcery/crypto_providers/sha1.rb +5 -5
  33. data/lib/sorcery/crypto_providers/sha256.rb +2 -2
  34. data/lib/sorcery/crypto_providers/sha512.rb +3 -3
  35. data/lib/sorcery/engine.rb +3 -8
  36. data/lib/sorcery/model.rb +24 -32
  37. data/lib/sorcery/model/config.rb +64 -49
  38. data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
  39. data/lib/sorcery/model/submodules/brute_force_protection.rb +23 -23
  40. data/lib/sorcery/model/submodules/external.rb +3 -7
  41. data/lib/sorcery/model/submodules/remember_me.rb +19 -7
  42. data/lib/sorcery/model/submodules/reset_password.rb +32 -36
  43. data/lib/sorcery/model/submodules/user_activation.rb +38 -50
  44. data/lib/sorcery/model/temporary_token.rb +2 -2
  45. data/lib/sorcery/protocols/oauth.rb +3 -9
  46. data/lib/sorcery/protocols/oauth2.rb +0 -2
  47. data/lib/sorcery/providers/base.rb +4 -4
  48. data/lib/sorcery/providers/facebook.rb +5 -8
  49. data/lib/sorcery/providers/github.rb +5 -7
  50. data/lib/sorcery/providers/google.rb +3 -5
  51. data/lib/sorcery/providers/heroku.rb +6 -8
  52. data/lib/sorcery/providers/jira.rb +12 -17
  53. data/lib/sorcery/providers/linkedin.rb +6 -8
  54. data/lib/sorcery/providers/liveid.rb +4 -7
  55. data/lib/sorcery/providers/paypal.rb +60 -0
  56. data/lib/sorcery/providers/salesforce.rb +3 -5
  57. data/lib/sorcery/providers/slack.rb +45 -0
  58. data/lib/sorcery/providers/twitter.rb +4 -6
  59. data/lib/sorcery/providers/vk.rb +3 -5
  60. data/lib/sorcery/providers/wechat.rb +79 -0
  61. data/lib/sorcery/providers/xing.rb +7 -10
  62. data/lib/sorcery/test_helpers/internal.rb +10 -10
  63. data/lib/sorcery/test_helpers/internal/rails.rb +16 -8
  64. data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
  65. data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
  66. data/lib/sorcery/version.rb +1 -1
  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 +125 -100
  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.ru +1 -1
  89. data/spec/rails_app/config/application.rb +7 -7
  90. data/spec/rails_app/config/boot.rb +1 -1
  91. data/spec/rails_app/config/environments/test.rb +1 -1
  92. data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
  93. data/spec/rails_app/config/initializers/session_store.rb +3 -3
  94. data/spec/rails_app/config/routes.rb +11 -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 +215 -118
  109. data/spec/sorcery_crypto_providers_spec.rb +63 -76
  110. data/spec/spec_helper.rb +17 -13
  111. metadata +28 -83
  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
@@ -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,10 +1,10 @@
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
10
  add_index :authentications, [:provider, :uid]
@@ -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
@@ -1,7 +1,6 @@
1
1
  require 'sorcery/version'
2
2
 
3
3
  module Sorcery
4
-
5
4
  require 'sorcery/model'
6
5
 
7
6
  module Adapters
@@ -12,7 +11,6 @@ module Sorcery
12
11
  require 'sorcery/model/temporary_token'
13
12
  require 'sorcery/model/config'
14
13
 
15
-
16
14
  module Submodules
17
15
  require 'sorcery/model/submodules/user_activation'
18
16
  require 'sorcery/model/submodules/reset_password'
@@ -63,7 +61,6 @@ module Sorcery
63
61
  module Internal
64
62
  require 'sorcery/test_helpers/internal/rails'
65
63
  end
66
-
67
64
  end
68
65
 
69
66
  require 'sorcery/adapters/base_adapter'
@@ -81,30 +78,5 @@ module Sorcery
81
78
  end
82
79
  end
83
80
 
84
- if defined?(Mongoid)
85
- require 'sorcery/adapters/mongoid_adapter'
86
- Mongoid::Document::ClassMethods.send :include, Sorcery::Model
87
-
88
- Mongoid::Document.send :define_method, :sorcery_adapter do
89
- @sorcery_adapter ||= Sorcery::Adapters::MongoidAdapter.new(self)
90
- end
91
-
92
- Mongoid::Document::ClassMethods.send :define_method, :sorcery_adapter do
93
- Sorcery::Adapters::MongoidAdapter.from(self)
94
- end
95
- end
96
-
97
- if defined?(MongoMapper)
98
- require 'sorcery/adapters/mongo_mapper_adapter'
99
- MongoMapper::Document.send(:plugin, Sorcery::Adapters::MongoMapperAdapter::Wrapper)
100
- end
101
-
102
- if defined?(DataMapper)
103
- require 'sorcery/adapters/data_mapper_adapter'
104
- DataMapper::Model.append_extensions(Sorcery::Model)
105
-
106
- DataMapper::Model.append_inclusions(Sorcery::Adapters::DataMapperAdapter::Wrapper)
107
- end
108
-
109
81
  require 'sorcery/engine' if defined?(Rails)
110
82
  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
@@ -5,7 +5,7 @@ module Sorcery
5
5
  include InstanceMethods
6
6
  Config.submodules.each do |mod|
7
7
  begin
8
- include Submodules.const_get(mod.to_s.split('_').map { |p| p.capitalize }.join)
8
+ include Submodules.const_get(mod.to_s.split('_').map(&:capitalize).join)
9
9
  rescue NameError
10
10
  # don't stop on a missing submodule.
11
11
  end
@@ -16,13 +16,13 @@ module Sorcery
16
16
  end
17
17
 
18
18
  module InstanceMethods
19
- # To be used as before_filter.
19
+ # To be used as before_action.
20
20
  # Will trigger auto-login attempts via the call to logged_in?
21
21
  # If all attempts to auto-login fail, the failure callback will be called.
22
22
  def require_login
23
- if !logged_in?
24
- session[:return_to_url] = request.url if Config.save_return_to_url && request.get?
25
- self.send(Config.not_authenticated_action)
23
+ unless logged_in?
24
+ session[:return_to_url] = request.url if Config.save_return_to_url && request.get? && !request.xhr?
25
+ send(Config.not_authenticated_action)
26
26
  end
27
27
  end
28
28
 
@@ -34,7 +34,7 @@ module Sorcery
34
34
  if user
35
35
  old_session = session.dup.to_hash
36
36
  reset_sorcery_session
37
- old_session.each_pair do |k,v|
37
+ old_session.each_pair do |k, v|
38
38
  session[k.to_sym] = v
39
39
  end
40
40
  form_authenticity_token
@@ -59,11 +59,11 @@ module Sorcery
59
59
  # Resets the session and runs hooks before and after.
60
60
  def logout
61
61
  if logged_in?
62
- @current_user = current_user if @current_user.nil?
63
- before_logout!(@current_user)
64
- reset_sorcery_session
65
- after_logout!
62
+ user = current_user
63
+ before_logout!
66
64
  @current_user = nil
65
+ reset_sorcery_session
66
+ after_logout!(user)
67
67
  end
68
68
  end
69
69
 
@@ -87,7 +87,7 @@ module Sorcery
87
87
  # used when a user tries to access a page while logged out, is asked to login,
88
88
  # and we want to return him back to the page he originally wanted.
89
89
  def redirect_back_or_to(url, flash_hash = {})
90
- redirect_to(session[:return_to_url] || url, :flash => flash_hash)
90
+ redirect_to(session[:return_to_url] || url, flash: flash_hash)
91
91
  session[:return_to_url] = nil
92
92
  end
93
93
 
@@ -102,7 +102,7 @@ module Sorcery
102
102
  #
103
103
  # @param [<User-Model>] user the user instance.
104
104
  # @return - do not depend on the return value.
105
- def auto_login(user, should_remember = false)
105
+ def auto_login(user, _should_remember = false)
106
106
  session[:user_id] = user.id.to_s
107
107
  @current_user = user
108
108
  end
@@ -132,26 +132,24 @@ module Sorcery
132
132
  end
133
133
 
134
134
  def after_login!(user, credentials = [])
135
- Config.after_login.each {|c| self.send(c, user, credentials)}
135
+ Config.after_login.each { |c| send(c, user, credentials) }
136
136
  end
137
137
 
138
138
  def after_failed_login!(credentials)
139
- Config.after_failed_login.each {|c| self.send(c, credentials)}
139
+ Config.after_failed_login.each { |c| send(c, credentials) }
140
140
  end
141
141
 
142
- def before_logout!(user)
143
- Config.before_logout.each {|c| self.send(c, user)}
142
+ def before_logout!
143
+ Config.before_logout.each { |c| send(c) }
144
144
  end
145
145
 
146
- def after_logout!
147
- Config.after_logout.each {|c| self.send(c)}
146
+ def after_logout!(user)
147
+ Config.after_logout.each { |c| send(c, user) }
148
148
  end
149
149
 
150
150
  def user_class
151
151
  @user_class ||= Config.user_class.to_s.constantize
152
152
  end
153
-
154
153
  end
155
-
156
- end
154
+ end
157
155
  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
@@ -19,6 +19,9 @@ module Sorcery
19
19
  require 'sorcery/providers/google'
20
20
  require 'sorcery/providers/jira'
21
21
  require 'sorcery/providers/salesforce'
22
+ require 'sorcery/providers/paypal'
23
+ require 'sorcery/providers/slack'
24
+ require 'sorcery/providers/wechat'
22
25
 
23
26
  Config.module_eval do
24
27
  class << self
@@ -87,19 +90,18 @@ module Sorcery
87
90
  end
88
91
 
89
92
  # for backwards compatibility
90
- def access_token(*args)
93
+ def access_token(*_args)
91
94
  @access_token
92
95
  end
93
96
 
94
-
95
97
  # this method should be somewhere else. It only does something once per application per provider.
96
98
  def sorcery_fixup_callback_url(provider)
97
99
  provider.original_callback_url ||= provider.callback_url
98
100
  if provider.original_callback_url.present? && provider.original_callback_url[0] == '/'
99
- uri = URI.parse(request.url.gsub(/\?.*$/,''))
101
+ uri = URI.parse(request.url.gsub(/\?.*$/, ''))
100
102
  uri.path = ''
101
103
  uri.query = nil
102
- uri.scheme = 'https' if(request.env['HTTP_X_FORWARDED_PROTO'] == 'https')
104
+ uri.scheme = 'https' if request.env['HTTP_X_FORWARDED_PROTO'] == 'https'
103
105
  host = uri.to_s
104
106
  provider.callback_url = "#{host}#{@provider.original_callback_url}"
105
107
  end
@@ -139,7 +141,7 @@ module Sorcery
139
141
  current_user.add_provider_to_user(provider_name.to_s, @user_hash[:uid].to_s)
140
142
  end
141
143
 
142
- # Initialize new user from provider informations.
144
+ # Initialize new user from provider informations.
143
145
  # If a provider doesn't give required informations or username/email is already taken,
144
146
  # we store provider/user infos into a session and can be rendered into registration form
145
147
  def create_and_validate_from(provider_name)
@@ -150,12 +152,14 @@ module Sorcery
150
152
 
151
153
  user, saved = user_class.create_and_validate_from_provider(provider_name, @user_hash[:uid], attrs)
152
154
 
153
- session[:incomplete_user] = {
154
- :provider => {config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider_name},
155
- :user_hash => attrs
156
- } unless saved
155
+ unless saved
156
+ session[:incomplete_user] = {
157
+ provider: { config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider_name },
158
+ user_hash: attrs
159
+ }
160
+ end
157
161
 
158
- return user
162
+ user
159
163
  end
160
164
 
161
165
  # this method automatically creates a new user from the data in the external user hash.
@@ -184,15 +188,19 @@ module Sorcery
184
188
 
185
189
  def user_attrs(user_info_mapping, user_hash)
186
190
  attrs = {}
187
- user_info_mapping.each do |k,v|
188
- if (varr = v.split("/")).size > 1
189
- attribute_value = varr.inject(user_hash[:user_info]) {|hash, value| hash[value]} rescue nil
191
+ user_info_mapping.each do |k, v|
192
+ if (varr = v.split('/')).size > 1
193
+ attribute_value = begin
194
+ varr.inject(user_hash[:user_info]) { |hash, value| hash[value] }
195
+ rescue
196
+ nil
197
+ end
190
198
  attribute_value.nil? ? attrs : attrs.merge!(k => attribute_value)
191
199
  else
192
200
  attrs.merge!(k => user_hash[:user_info][v])
193
201
  end
194
202
  end
195
- return attrs
203
+ attrs
196
204
  end
197
205
  end
198
206
  end