sorcery 0.12.0 → 0.13.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 (83) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +20 -0
  3. data/.rubocop.yml +52 -2
  4. data/.rubocop_todo.yml +1 -429
  5. data/.travis.yml +11 -21
  6. data/CHANGELOG.md +16 -0
  7. data/Gemfile +2 -2
  8. data/{LICENSE.txt → LICENSE.md} +1 -1
  9. data/README.md +7 -1
  10. data/gemfiles/{active_record-rails40.gemfile → active_record_rails_40.gemfile} +1 -2
  11. data/gemfiles/{active_record-rails41.gemfile → active_record_rails_41.gemfile} +1 -2
  12. data/gemfiles/{active_record-rails42.gemfile → active_record_rails_42.gemfile} +1 -2
  13. data/lib/generators/sorcery/USAGE +1 -1
  14. data/lib/generators/sorcery/install_generator.rb +21 -21
  15. data/lib/generators/sorcery/templates/initializer.rb +19 -1
  16. data/lib/sorcery/adapters/active_record_adapter.rb +1 -1
  17. data/lib/sorcery/adapters/mongoid_adapter.rb +23 -11
  18. data/lib/sorcery/controller.rb +22 -16
  19. data/lib/sorcery/controller/config.rb +2 -0
  20. data/lib/sorcery/controller/submodules/activity_logging.rb +4 -0
  21. data/lib/sorcery/controller/submodules/external.rb +37 -33
  22. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -0
  23. data/lib/sorcery/controller/submodules/remember_me.rb +1 -7
  24. data/lib/sorcery/controller/submodules/session_timeout.rb +25 -4
  25. data/lib/sorcery/crypto_providers/aes256.rb +1 -0
  26. data/lib/sorcery/crypto_providers/bcrypt.rb +2 -1
  27. data/lib/sorcery/engine.rb +10 -3
  28. data/lib/sorcery/model.rb +9 -6
  29. data/lib/sorcery/model/config.rb +3 -3
  30. data/lib/sorcery/model/submodules/brute_force_protection.rb +6 -7
  31. data/lib/sorcery/model/submodules/external.rb +4 -3
  32. data/lib/sorcery/model/submodules/magic_login.rb +29 -36
  33. data/lib/sorcery/model/submodules/reset_password.rb +5 -4
  34. data/lib/sorcery/model/submodules/user_activation.rb +1 -1
  35. data/lib/sorcery/protocols/oauth.rb +1 -0
  36. data/lib/sorcery/providers/auth0.rb +46 -0
  37. data/lib/sorcery/providers/heroku.rb +1 -0
  38. data/lib/sorcery/providers/instagram.rb +73 -0
  39. data/lib/sorcery/providers/linkedin.rb +1 -1
  40. data/lib/sorcery/providers/vk.rb +1 -1
  41. data/lib/sorcery/providers/wechat.rb +8 -6
  42. data/lib/sorcery/test_helpers/internal.rb +5 -4
  43. data/lib/sorcery/test_helpers/internal/rails.rb +11 -11
  44. data/lib/sorcery/version.rb +1 -1
  45. data/sorcery.gemspec +25 -9
  46. data/spec/active_record/user_activation_spec.rb +2 -2
  47. data/spec/active_record/user_activity_logging_spec.rb +2 -2
  48. data/spec/active_record/user_brute_force_protection_spec.rb +2 -2
  49. data/spec/active_record/user_magic_login_spec.rb +4 -4
  50. data/spec/active_record/user_oauth_spec.rb +2 -2
  51. data/spec/active_record/user_remember_me_spec.rb +2 -2
  52. data/spec/active_record/user_reset_password_spec.rb +2 -2
  53. data/spec/active_record/user_spec.rb +0 -10
  54. data/spec/controllers/controller_http_basic_auth_spec.rb +1 -1
  55. data/spec/controllers/controller_oauth2_spec.rb +195 -123
  56. data/spec/controllers/controller_oauth_spec.rb +7 -7
  57. data/spec/controllers/controller_remember_me_spec.rb +11 -6
  58. data/spec/controllers/controller_session_timeout_spec.rb +90 -3
  59. data/spec/controllers/controller_spec.rb +2 -2
  60. data/spec/orm/active_record.rb +2 -2
  61. data/spec/providers/vk_spec.rb +13 -12
  62. data/spec/rails_app/app/controllers/sorcery_controller.rb +83 -32
  63. data/spec/rails_app/app/mailers/sorcery_mailer.rb +1 -1
  64. data/spec/rails_app/config/application.rb +8 -3
  65. data/spec/rails_app/config/boot.rb +1 -1
  66. data/spec/rails_app/config/environment.rb +1 -1
  67. data/spec/rails_app/config/routes.rb +7 -0
  68. data/spec/rails_app/config/secrets.yml +4 -0
  69. data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +2 -2
  70. data/spec/rails_app/db/migrate/invalidate_active_sessions/20180221093235_add_invalidate_active_sessions_before_to_users.rb +9 -0
  71. data/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb +3 -3
  72. data/spec/rails_app/db/schema.rb +7 -9
  73. data/spec/shared_examples/user_magic_login_shared_examples.rb +50 -50
  74. data/spec/shared_examples/user_oauth_shared_examples.rb +1 -1
  75. data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -1
  76. data/spec/shared_examples/user_reset_password_shared_examples.rb +3 -3
  77. data/spec/shared_examples/user_shared_examples.rb +41 -43
  78. data/spec/sorcery_crypto_providers_spec.rb +1 -1
  79. data/spec/spec.opts +1 -1
  80. data/spec/spec_helper.rb +2 -2
  81. data/spec/support/migration_helper.rb +19 -0
  82. metadata +60 -38
  83. data/spec/rails_app/config/initializers/secret_token.rb +0 -7
@@ -1,20 +1,15 @@
1
1
  language: ruby
2
2
  rvm:
3
- - jruby
4
3
  - 2.2.9
5
4
  - 2.3.6
6
5
  - 2.4.3
7
6
  - 2.5.0
8
7
 
9
- env:
10
- global:
11
- - JRUBY_OPTS="--2.0"
12
-
13
8
  gemfile:
14
9
  - Gemfile
15
- - gemfiles/active_record-rails40.gemfile
16
- - gemfiles/active_record-rails41.gemfile
17
- - gemfiles/active_record-rails42.gemfile
10
+ - gemfiles/active_record_rails_40.gemfile
11
+ - gemfiles/active_record_rails_41.gemfile
12
+ - gemfiles/active_record_rails_42.gemfile
18
13
 
19
14
  before_script:
20
15
  - mysql -e 'create database sorcery_test;'
@@ -24,25 +19,20 @@ before_install:
24
19
  - gem update bundler
25
20
 
26
21
  matrix:
27
- allow_failures:
28
- - rvm: jruby
29
-
30
22
  exclude:
31
23
  - rvm: 2.2.9
32
- gemfile: gemfiles/active_record-rails40.gemfile
24
+ gemfile: gemfiles/active_record_rails_40.gemfile
33
25
  - rvm: 2.3.6
34
- gemfile: gemfiles/active_record-rails40.gemfile
26
+ gemfile: gemfiles/active_record_rails_40.gemfile
35
27
  - rvm: 2.4.3
36
- gemfile: gemfiles/active_record-rails40.gemfile
28
+ gemfile: gemfiles/active_record_rails_40.gemfile
37
29
  - rvm: 2.4.3
38
- gemfile: gemfiles/active_record-rails41.gemfile
30
+ gemfile: gemfiles/active_record_rails_41.gemfile
39
31
  - rvm: 2.4.3
40
- gemfile: gemfiles/active_record-rails42.gemfile
32
+ gemfile: gemfiles/active_record_rails_42.gemfile
41
33
  - rvm: 2.5.0
42
- gemfile: gemfiles/active_record-rails40.gemfile
34
+ gemfile: gemfiles/active_record_rails_40.gemfile
43
35
  - rvm: 2.5.0
44
- gemfile: gemfiles/active_record-rails41.gemfile
36
+ gemfile: gemfiles/active_record_rails_41.gemfile
45
37
  - rvm: 2.5.0
46
- gemfile: gemfiles/active_record-rails42.gemfile
47
- - rvm: jruby
48
- gemfile: Gemfile
38
+ gemfile: gemfiles/active_record_rails_42.gemfile
@@ -1,6 +1,22 @@
1
1
  # Changelog
2
2
  ## HEAD
3
3
 
4
+ ## 0.13.0
5
+
6
+ * Add support for Rails 5.2 / Ruby 2.5 [#129](https://github.com/Sorcery/sorcery/pull/129)
7
+ * Fix migration files not being generated [#128](https://github.com/Sorcery/sorcery/pull/128)
8
+ * Add support for ActionController::API [#133](https://github.com/Sorcery/sorcery/pull/133), [#150](https://github.com/Sorcery/sorcery/pull/150), [#159](https://github.com/Sorcery/sorcery/pull/159)
9
+ * Update activation email to use after_commit callback [#130](https://github.com/Sorcery/sorcery/pull/130)
10
+ * Add opt-in `invalidate_active_sessions!` method [#110](https://github.com/Sorcery/sorcery/pull/110)
11
+ * Pass along `remember_me` to `#auto_login` [#136](https://github.com/Sorcery/sorcery/pull/136)
12
+ * Respect SessionTimeout on login via RememberMe [#102](https://github.com/Sorcery/sorcery/pull/102)
13
+ * Added `demodulize` on authentication class name association name fetch [#147](https://github.com/Sorcery/sorcery/pull/147)
14
+ * Remove Gemnasium badge [#140](https://github.com/Sorcery/sorcery/pull/140)
15
+ * Add Instragram provider [#51](https://github.com/Sorcery/sorcery/pull/51)
16
+ * Remove `publish_actions` permission for facebook [#139](https://github.com/Sorcery/sorcery/pull/139)
17
+ * Prepare for 1.0.0 [#157](https://github.com/Sorcery/sorcery/pull/157)
18
+ * Add Auth0 provider [#160](https://github.com/Sorcery/sorcery/pull/160)
19
+
4
20
  ## 0.12.0
5
21
 
6
22
  * Fix magic_login not inheriting from migration_class_name [#99](https://github.com/Sorcery/sorcery/pull/99)
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '~> 5.1.0'
3
+ gem 'pry'
4
+ gem 'rails', '~> 5.2.0'
4
5
  gem 'rails-controller-testing'
5
6
  gem 'sqlite3'
6
- gem 'pry'
7
7
 
8
8
  gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Noam Ben-Ari <mailto:nbenari@gmail.com>
1
+ Copyright (c) 2010 [Noam Ben-Ari](mailto:nbenari@gmail.com)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/sorcery.svg)](https://rubygems.org/gems/sorcery)
4
4
  [![Gem Downloads](https://img.shields.io/gem/dt/sorcery.svg)](https://rubygems.org/gems/sorcery)
5
5
  [![Build Status](https://travis-ci.org/Sorcery/sorcery.svg?branch=master)](https://travis-ci.org/Sorcery/sorcery)
6
- [![Dependency Status](https://gemnasium.com/badges/github.com/Sorcery/sorcery.svg)](https://gemnasium.com/github.com/Sorcery/sorcery)
7
6
  [![Code Climate](https://codeclimate.com/github/Sorcery/sorcery.svg)](https://codeclimate.com/github/Sorcery/sorcery)
8
7
  [![Inline docs](http://inch-ci.org/github/Sorcery/sorcery.svg?branch=master)](http://inch-ci.org/github/Sorcery/sorcery)
9
8
  [![Join the chat at https://gitter.im/Sorcery/sorcery](https://badges.gitter.im/join_chat.svg)](https://gitter.im/Sorcery/sorcery?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -103,6 +102,12 @@ User.load_from_reset_password_token(token)
103
102
  @user.change_password!(new_password)
104
103
  ```
105
104
 
105
+ ### Session Timeout
106
+
107
+ ```ruby
108
+ invalidate_active_sessions! #Invalidate all sessions with a login_time or last_action_time before the current time. Must Opt-in
109
+ ```
110
+
106
111
  ### User Activation
107
112
 
108
113
  ```ruby
@@ -184,6 +189,7 @@ Inside the initializer, the comments will tell you what each setting does.
184
189
 
185
190
  - Configurable session timeout
186
191
  - Optionally session timeout will be calculated from last user action
192
+ - Optionally enable a method to clear all active sessions, expects an `invalidate_sessions_before` datetime attribute.
187
193
 
188
194
  **Brute Force Protection** (see [lib/sorcery/model/submodules/brute_force_protection.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/brute_force_protection.rb)):
189
195
 
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', platform: :mri
4
- gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
3
  gem 'rails', '~> 4.0.1'
4
+ gem 'sqlite3', platform: :mri
6
5
 
7
6
  gemspec path: '..'
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', platform: :mri
4
- gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
3
  gem 'rails', '~> 4.1.0'
4
+ gem 'sqlite3', platform: :mri
6
5
 
7
6
  gemspec path: '..'
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', platform: :mri
4
- gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
3
  gem 'rails', '~> 4.2.0'
4
+ gem 'sqlite3', platform: :mri
6
5
 
7
6
  gemspec path: '..'
@@ -1,6 +1,6 @@
1
1
  Description:
2
2
  Generates the necessary files to get you up and running with Sorcery gem
3
-
3
+
4
4
  Examples:
5
5
  rails generate sorcery:install
6
6
 
@@ -7,7 +7,7 @@ module Sorcery
7
7
  include Rails::Generators::Migration
8
8
  include Sorcery::Generators::Helpers
9
9
 
10
- source_root File.expand_path('../templates', __FILE__)
10
+ source_root File.expand_path('templates', __dir__)
11
11
 
12
12
  argument :submodules, optional: true, type: :array, banner: 'submodules'
13
13
 
@@ -21,9 +21,9 @@ module Sorcery
21
21
  desc: "Specify if you want to add submodules to an existing model\n\t\t\t # (will generate migrations files, and add submodules to config file)"
22
22
 
23
23
  def check_deprecated_options
24
- if options[:migrations]
25
- warn('[DEPRECATED] `--migrations` option is deprecated, please use `--only-submodules` instead')
26
- end
24
+ return unless options[:migrations]
25
+
26
+ warn('[DEPRECATED] `--migrations` option is deprecated, please use `--only-submodules` instead')
27
27
  end
28
28
 
29
29
  # Copy the initializer file to config/initializers folder.
@@ -33,23 +33,22 @@ module Sorcery
33
33
 
34
34
  def configure_initializer_file
35
35
  # Add submodules to the initializer file.
36
- if submodules
37
- submodule_names = submodules.collect { |submodule| ':' + submodule }
36
+ return unless submodules
38
37
 
39
- gsub_file sorcery_config_path, /submodules = \[.*\]/ do |str|
40
- current_submodule_names = (str =~ /\[(.*)\]/ ? Regexp.last_match(1) : '').delete(' ').split(',')
41
- "submodules = [#{(current_submodule_names | submodule_names).join(', ')}]"
42
- end
38
+ submodule_names = submodules.collect { |submodule| ':' + submodule }
39
+
40
+ gsub_file sorcery_config_path, /submodules = \[.*\]/ do |str|
41
+ current_submodule_names = (str =~ /\[(.*)\]/ ? Regexp.last_match(1) : '').delete(' ').split(',')
42
+ "submodules = [#{(current_submodule_names | submodule_names).join(', ')}]"
43
43
  end
44
44
  end
45
45
 
46
46
  def configure_model
47
47
  # Generate the model and add 'authenticates_with_sorcery!' unless you passed --only-submodules
48
- unless only_submodules?
49
- generate "model #{model_class_name} --skip-migration"
48
+ return if only_submodules?
50
49
 
51
- inject_sorcery_to_model
52
- end
50
+ generate "model #{model_class_name} --skip-migration"
51
+ inject_sorcery_to_model
53
52
  end
54
53
 
55
54
  def inject_sorcery_to_model
@@ -61,14 +60,15 @@ module Sorcery
61
60
  # Copy the migrations files to db/migrate folder
62
61
  def copy_migration_files
63
62
  # Copy core migration file in all cases except when you pass --only-submodules.
64
- return unless defined?(Sorcery::Generators::InstallGenerator::ActiveRecord)
63
+ return unless defined?(ActiveRecord)
64
+
65
65
  migration_template 'migration/core.rb', 'db/migrate/sorcery_core.rb', migration_class_name: migration_class_name unless only_submodules?
66
66
 
67
- if submodules
68
- submodules.each do |submodule|
69
- unless submodule == 'http_basic_auth' || submodule == 'session_timeout' || submodule == 'core'
70
- migration_template "migration/#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb", migration_class_name: migration_class_name
71
- end
67
+ return unless submodules
68
+
69
+ submodules.each do |submodule|
70
+ unless %w[http_basic_auth session_timeout core].include?(submodule)
71
+ migration_template "migration/#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb", migration_class_name: migration_class_name
72
72
  end
73
73
  end
74
74
  end
@@ -79,7 +79,7 @@ module Sorcery
79
79
  sleep 1 # make sure each time we get a different timestamp
80
80
  Time.new.utc.strftime('%Y%m%d%H%M%S')
81
81
  else
82
- '%.3d' % (current_migration_number(dirname) + 1)
82
+ format('%.3d', (current_migration_number(dirname) + 1))
83
83
  end
84
84
  end
85
85
 
@@ -46,6 +46,11 @@ Rails.application.config.sorcery.configure do |config|
46
46
  #
47
47
  # config.session_timeout_from_last_action =
48
48
 
49
+ # Invalidate active sessions Requires an `invalidate_sessions_before` timestamp column
50
+ # Default: `false`
51
+ #
52
+ # config.session_timeout_invalidate_active_sessions_enabled =
53
+
49
54
  # -- http_basic_auth --
50
55
  # What realm to display for which controller name. For example {"My App" => "Application"}
51
56
  # Default: `{"application" => "Application"}`
@@ -114,11 +119,17 @@ Rails.application.config.sorcery.configure do |config|
114
119
  # config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
115
120
  # config.facebook.user_info_path = "me?fields=email"
116
121
  # config.facebook.user_info_mapping = {:email => "email"}
117
- # config.facebook.access_permissions = ["email", "publish_actions"]
122
+ # config.facebook.access_permissions = ["email"]
118
123
  # config.facebook.display = "page"
119
124
  # config.facebook.api_version = "v2.3"
120
125
  # config.facebook.parse = :json
121
126
  #
127
+ # config.instagram.key = ""
128
+ # config.instagram.secret = ""
129
+ # config.instagram.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=instagram"
130
+ # config.instagram.user_info_mapping = {:email => "username"}
131
+ # config.instagram.access_permissions = ["basic", "public_content", "follower_list", "comments", "relationships", "likes"]
132
+ #
122
133
  # config.github.key = ""
123
134
  # config.github.secret = ""
124
135
  # config.github.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=github"
@@ -134,6 +145,13 @@ Rails.application.config.sorcery.configure do |config|
134
145
  # config.wechat.secret = ""
135
146
  # config.wechat.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=wechat"
136
147
  #
148
+ # For Auth0, site is required and should match the domain provided by Auth0.
149
+ #
150
+ # config.auth0.key = ""
151
+ # config.auth0.secret = ""
152
+ # config.auth0.callback_url = "https://0.0.0.0:3000/oauth/callback?provider=auth0"
153
+ # config.auth0.site = "https://example.auth0.com"
154
+ #
137
155
  # config.google.key = ""
138
156
  # config.google.secret = ""
139
157
  # config.google.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=google"
@@ -35,7 +35,7 @@ module Sorcery
35
35
  end
36
36
 
37
37
  def define_callback(time, event, method_name, options = {})
38
- @klass.send "#{time}_#{event}", method_name, options.slice(:if)
38
+ @klass.send "#{time}_#{event}", method_name, options.slice(:if, :on)
39
39
  end
40
40
 
41
41
  def find_by_oauth_credentials(provider, uid)
@@ -10,7 +10,7 @@ module Sorcery
10
10
  attrs[name] = value.utc if value.is_a?(ActiveSupport::TimeWithZone)
11
11
  @model.send(:"#{name}=", value)
12
12
  end
13
- @model.class.where(:_id => @model.id).update_all(attrs)
13
+ @model.class.where(_id: @model.id).update_all(attrs)
14
14
  end
15
15
 
16
16
  def update_attribute(name, value)
@@ -23,21 +23,29 @@ module Sorcery
23
23
  end
24
24
 
25
25
  def mongoid_4?
26
- Gem::Version.new(::Mongoid::VERSION) >= Gem::Version.new("4.0.0.alpha")
26
+ Gem::Version.new(::Mongoid::VERSION) >= Gem::Version.new('4.0.0.alpha')
27
27
  end
28
28
 
29
29
  class << self
30
-
31
- def define_field(name, type, options={})
30
+ def define_field(name, type, options = {})
32
31
  @klass.field name, options.slice(:default).merge(type: type)
33
32
  end
34
33
 
35
- def define_callback(time, event, method_name, options={})
36
- @klass.send "#{time}_#{event}", method_name, options.slice(:if)
34
+ def define_callback(time, event, method_name, options = {})
35
+ @klass.send callback_name(time, event, options), method_name, options.slice(:if)
36
+ end
37
+
38
+ def callback_name(time, event, options)
39
+ if event == :commit
40
+ options[:on] == :create ? "#{time}_create" : "#{time}_save"
41
+ else
42
+ "#{time}_#{event}"
43
+ end
37
44
  end
38
45
 
39
46
  def credential_regex(credential)
40
- return { :$regex => /^#{Regexp.escape(credential)}$/i } if (@klass.sorcery_config.downcase_username_before_authenticating)
47
+ return { :$regex => /^#{Regexp.escape(credential)}$/i } if @klass.sorcery_config.downcase_username_before_authenticating
48
+
41
49
  credential
42
50
  end
43
51
 
@@ -73,7 +81,7 @@ module Sorcery
73
81
  end
74
82
 
75
83
  def find_by_username(username)
76
- query = @klass.sorcery_config.username_attribute_names.map {|name| {name => username}}
84
+ query = @klass.sorcery_config.username_attribute_names.map { |name| { name => username } }
77
85
  @klass.any_of(*query).first
78
86
  end
79
87
 
@@ -87,9 +95,13 @@ module Sorcery
87
95
 
88
96
  def get_current_users
89
97
  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])
98
+ @klass.where(
99
+ config.last_activity_at_attribute_name.ne => nil
100
+ ).where(
101
+ "this.#{config.last_logout_at_attribute_name} == null || this.#{config.last_activity_at_attribute_name} > this.#{config.last_logout_at_attribute_name}"
102
+ ).where(
103
+ config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc
104
+ ).order_by(%i[_id asc])
93
105
  end
94
106
  end
95
107
  end
@@ -4,11 +4,14 @@ module Sorcery
4
4
  klass.class_eval do
5
5
  include InstanceMethods
6
6
  Config.submodules.each do |mod|
7
+ # FIXME: Is there a cleaner way to handle missing submodules?
8
+ # rubocop:disable Lint/HandleExceptions
7
9
  begin
8
10
  include Submodules.const_get(mod.to_s.split('_').map(&:capitalize).join)
9
11
  rescue NameError
10
12
  # don't stop on a missing submodule.
11
13
  end
14
+ # rubocop:enable Lint/HandleExceptions
12
15
  end
13
16
  end
14
17
  Config.update!
@@ -20,10 +23,10 @@ module Sorcery
20
23
  # Will trigger auto-login attempts via the call to logged_in?
21
24
  # If all attempts to auto-login fail, the failure callback will be called.
22
25
  def require_login
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
- end
26
+ return if logged_in?
27
+
28
+ session[:return_to_url] = request.url if Config.save_return_to_url && request.get? && !request.xhr?
29
+ send(Config.not_authenticated_action)
27
30
  end
28
31
 
29
32
  # Takes credentials and returns a user on successful authentication.
@@ -37,7 +40,10 @@ module Sorcery
37
40
 
38
41
  yield(user, failure_reason) if block_given?
39
42
 
43
+ # FIXME: Does using `break` or `return nil` change functionality?
44
+ # rubocop:disable Lint/NonLocalExitFromIterator
40
45
  return
46
+ # rubocop:enable Lint/NonLocalExitFromIterator
41
47
  end
42
48
 
43
49
  old_session = session.dup.to_hash
@@ -47,30 +53,26 @@ module Sorcery
47
53
  end
48
54
  form_authenticity_token
49
55
 
50
- auto_login(user)
56
+ auto_login(user, credentials[2])
51
57
  after_login!(user, credentials)
52
58
 
53
59
  block_given? ? yield(current_user, nil) : current_user
54
60
  end
55
61
  end
56
62
 
57
- # put this into the catch block to rescue undefined method `destroy_session'
58
- # hotfix for https://github.com/NoamB/sorcery/issues/464
59
- # can be removed when Rails 4.1 is out
60
63
  def reset_sorcery_session
61
64
  reset_session # protect from session fixation attacks
62
- rescue NoMethodError
63
65
  end
64
66
 
65
67
  # Resets the session and runs hooks before and after.
66
68
  def logout
67
- if logged_in?
68
- user = current_user
69
- before_logout!
70
- @current_user = nil
71
- reset_sorcery_session
72
- after_logout!(user)
73
- end
69
+ return unless logged_in?
70
+
71
+ user = current_user
72
+ before_logout!
73
+ @current_user = nil
74
+ reset_sorcery_session
75
+ after_logout!(user)
74
76
  end
75
77
 
76
78
  def logged_in?
@@ -153,6 +155,10 @@ module Sorcery
153
155
  Config.after_logout.each { |c| send(c, user) }
154
156
  end
155
157
 
158
+ def after_remember_me!(user)
159
+ Config.after_remember_me.each { |c| send(c, user) }
160
+ end
161
+
156
162
  def user_class
157
163
  @user_class ||= Config.user_class.to_s.constantize
158
164
  rescue NameError