sorcery 0.6.0 → 0.7.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.
- data/Gemfile +2 -2
- data/Gemfile.lock +97 -82
- data/README.rdoc +14 -4
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/lib/generators/sorcery_migration/templates/core.rb +1 -1
- data/lib/generators/sorcery_migration/templates/reset_password.rb +4 -0
- data/lib/sorcery/controller/adapters/sinatra.rb +12 -1
- data/lib/sorcery/controller/submodules/activity_logging.rb +18 -1
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +2 -1
- data/lib/sorcery/controller/submodules/external/protocols/certs/ca-bundle.crt +5182 -0
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +10 -6
- data/lib/sorcery/controller/submodules/external/providers/github.rb +80 -0
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +5 -0
- data/lib/sorcery/controller/submodules/external.rb +10 -3
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
- data/lib/sorcery/controller/submodules/remember_me.rb +13 -4
- data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
- data/lib/sorcery/controller.rb +26 -6
- data/lib/sorcery/crypto_providers/aes256.rb +7 -3
- data/lib/sorcery/engine.rb +1 -0
- data/lib/sorcery/initializers/initializer.rb +81 -60
- data/lib/sorcery/model/adapters/active_record.rb +2 -1
- data/lib/sorcery/model/adapters/mongoid.rb +7 -2
- data/lib/sorcery/model/submodules/brute_force_protection.rb +5 -3
- data/lib/sorcery/model/submodules/remember_me.rb +1 -1
- data/lib/sorcery/model/submodules/reset_password.rb +1 -2
- data/lib/sorcery/model/submodules/user_activation.rb +1 -2
- data/lib/sorcery/model/temporary_token.rb +5 -0
- data/lib/sorcery/model.rb +13 -11
- data/lib/sorcery/test_helpers/internal/rails.rb +1 -1
- data/lib/sorcery/test_helpers/rails.rb +2 -2
- data/lib/sorcery/test_helpers/sinatra.rb +1 -1
- data/lib/sorcery.rb +1 -0
- data/sorcery.gemspec +31 -24
- data/spec/Gemfile +2 -2
- data/spec/Gemfile.lock +36 -37
- data/spec/README.md +26 -0
- data/spec/rails3/Gemfile +2 -0
- data/spec/rails3/Gemfile.lock +38 -16
- data/spec/rails3/app/controllers/application_controller.rb +40 -22
- data/spec/rails3/app/views/application/index.html.erb +17 -0
- data/spec/rails3/spec/controller_activity_logging_spec.rb +23 -0
- data/spec/rails3/spec/controller_oauth2_spec.rb +62 -21
- data/spec/rails3/spec/controller_remember_me_spec.rb +37 -6
- data/spec/rails3/spec/controller_spec.rb +30 -0
- data/spec/rails3/spec/integration_spec.rb +23 -0
- data/spec/rails3/spec/spec_helper.rb +6 -3
- data/spec/rails3_mongoid/Gemfile.lock +14 -16
- data/spec/rails3_mongoid/spec/controller_spec.rb +130 -0
- data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -0
- data/spec/shared_examples/user_shared_examples.rb +7 -7
- data/spec/sinatra/Gemfile.lock +14 -16
- data/spec/sinatra/spec/controller_oauth2_spec.rb +3 -6
- data/spec/sinatra/spec/controller_spec.rb +7 -0
- data/spec/sinatra_modular/Gemfile.lock +14 -16
- data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +3 -6
- metadata +18 -13
- data/spec/rails3/public/index.html +0 -239
data/Gemfile
CHANGED
|
@@ -2,8 +2,8 @@ source "http://rubygems.org"
|
|
|
2
2
|
# Add dependencies required to use your gem here.
|
|
3
3
|
# Example:
|
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
|
5
|
-
gem 'oauth', "
|
|
6
|
-
gem 'oauth2', "
|
|
5
|
+
gem 'oauth', "~> 0.4.4"
|
|
6
|
+
gem 'oauth2', "~> 0.5.1"
|
|
7
7
|
|
|
8
8
|
# Add dependencies to develop your gem here.
|
|
9
9
|
# Include everything needed to run rake, tests, features, etc.
|
data/Gemfile.lock
CHANGED
|
@@ -1,100 +1,108 @@
|
|
|
1
1
|
GEM
|
|
2
2
|
remote: http://rubygems.org/
|
|
3
3
|
specs:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
rack (~> 1.
|
|
15
|
-
rack-mount (~> 0.
|
|
16
|
-
rack-test (~> 0.
|
|
17
|
-
|
|
18
|
-
activemodel (3.0
|
|
19
|
-
activesupport (= 3.0
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
4
|
+
actionmailer (3.1.0)
|
|
5
|
+
actionpack (= 3.1.0)
|
|
6
|
+
mail (~> 2.3.0)
|
|
7
|
+
actionpack (3.1.0)
|
|
8
|
+
activemodel (= 3.1.0)
|
|
9
|
+
activesupport (= 3.1.0)
|
|
10
|
+
builder (~> 3.0.0)
|
|
11
|
+
erubis (~> 2.7.0)
|
|
12
|
+
i18n (~> 0.6)
|
|
13
|
+
rack (~> 1.3.2)
|
|
14
|
+
rack-cache (~> 1.0.3)
|
|
15
|
+
rack-mount (~> 0.8.2)
|
|
16
|
+
rack-test (~> 0.6.1)
|
|
17
|
+
sprockets (~> 2.0.0)
|
|
18
|
+
activemodel (3.1.0)
|
|
19
|
+
activesupport (= 3.1.0)
|
|
20
|
+
bcrypt-ruby (~> 3.0.0)
|
|
21
|
+
builder (~> 3.0.0)
|
|
22
|
+
i18n (~> 0.6)
|
|
23
|
+
activerecord (3.1.0)
|
|
24
|
+
activemodel (= 3.1.0)
|
|
25
|
+
activesupport (= 3.1.0)
|
|
26
|
+
arel (~> 2.2.1)
|
|
27
|
+
tzinfo (~> 0.3.29)
|
|
28
|
+
activeresource (3.1.0)
|
|
29
|
+
activemodel (= 3.1.0)
|
|
30
|
+
activesupport (= 3.1.0)
|
|
31
|
+
activesupport (3.1.0)
|
|
32
|
+
multi_json (~> 1.0)
|
|
33
|
+
addressable (2.2.6)
|
|
32
34
|
archive-tar-minitar (0.5.2)
|
|
33
|
-
arel (2.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
faraday (0.
|
|
42
|
-
addressable (~> 2.2.
|
|
35
|
+
arel (2.2.1)
|
|
36
|
+
bcrypt-ruby (3.0.0)
|
|
37
|
+
bson (1.3.1)
|
|
38
|
+
bson_ext (1.3.1)
|
|
39
|
+
builder (3.0.0)
|
|
40
|
+
columnize (0.3.4)
|
|
41
|
+
diff-lcs (1.1.3)
|
|
42
|
+
erubis (2.7.0)
|
|
43
|
+
faraday (0.7.4)
|
|
44
|
+
addressable (~> 2.2.6)
|
|
43
45
|
multipart-post (~> 1.1.0)
|
|
44
46
|
rack (< 2, >= 1.1.0)
|
|
45
47
|
git (1.2.5)
|
|
46
|
-
|
|
48
|
+
hike (1.2.1)
|
|
49
|
+
i18n (0.6.0)
|
|
47
50
|
jeweler (1.5.2)
|
|
48
51
|
bundler (~> 1.0.0)
|
|
49
52
|
git (>= 1.2.5)
|
|
50
53
|
rake
|
|
51
|
-
json (1.5.
|
|
52
|
-
linecache19 (0.5.
|
|
54
|
+
json (1.5.4)
|
|
55
|
+
linecache19 (0.5.12)
|
|
53
56
|
ruby_core_source (>= 0.1.4)
|
|
54
|
-
mail (2.
|
|
55
|
-
activesupport (>= 2.3.6)
|
|
57
|
+
mail (2.3.0)
|
|
56
58
|
i18n (>= 0.4.0)
|
|
57
59
|
mime-types (~> 1.16)
|
|
58
60
|
treetop (~> 1.4.8)
|
|
59
61
|
mime-types (1.16)
|
|
60
|
-
mongo (1.3.
|
|
61
|
-
bson (>= 1.3.
|
|
62
|
-
mongoid (2.0
|
|
62
|
+
mongo (1.3.1)
|
|
63
|
+
bson (>= 1.3.1)
|
|
64
|
+
mongoid (2.2.0)
|
|
63
65
|
activemodel (~> 3.0)
|
|
64
66
|
mongo (~> 1.3)
|
|
65
67
|
tzinfo (~> 0.3.22)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
rack (1.
|
|
75
|
-
|
|
68
|
+
multi_json (1.0.3)
|
|
69
|
+
multipart-post (1.1.3)
|
|
70
|
+
oauth (0.4.5)
|
|
71
|
+
oauth2 (0.5.1)
|
|
72
|
+
faraday (~> 0.7.4)
|
|
73
|
+
multi_json (~> 1.0.3)
|
|
74
|
+
polyglot (0.3.2)
|
|
75
|
+
rack (1.3.3)
|
|
76
|
+
rack-cache (1.0.3)
|
|
77
|
+
rack (>= 0.4)
|
|
78
|
+
rack-mount (0.8.3)
|
|
76
79
|
rack (>= 1.0.0)
|
|
77
|
-
rack-
|
|
80
|
+
rack-ssl (1.3.2)
|
|
81
|
+
rack
|
|
82
|
+
rack-test (0.6.1)
|
|
78
83
|
rack (>= 1.0)
|
|
79
|
-
rails (3.0
|
|
80
|
-
actionmailer (= 3.0
|
|
81
|
-
actionpack (= 3.0
|
|
82
|
-
activerecord (= 3.0
|
|
83
|
-
activeresource (= 3.0
|
|
84
|
-
activesupport (= 3.0
|
|
84
|
+
rails (3.1.0)
|
|
85
|
+
actionmailer (= 3.1.0)
|
|
86
|
+
actionpack (= 3.1.0)
|
|
87
|
+
activerecord (= 3.1.0)
|
|
88
|
+
activeresource (= 3.1.0)
|
|
89
|
+
activesupport (= 3.1.0)
|
|
85
90
|
bundler (~> 1.0)
|
|
86
|
-
railties (= 3.0
|
|
87
|
-
railties (3.0
|
|
88
|
-
actionpack (= 3.0
|
|
89
|
-
activesupport (= 3.0
|
|
91
|
+
railties (= 3.1.0)
|
|
92
|
+
railties (3.1.0)
|
|
93
|
+
actionpack (= 3.1.0)
|
|
94
|
+
activesupport (= 3.1.0)
|
|
95
|
+
rack-ssl (~> 1.3.2)
|
|
90
96
|
rake (>= 0.8.7)
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
rdoc (~> 3.4)
|
|
98
|
+
thor (~> 0.14.6)
|
|
99
|
+
rake (0.9.2)
|
|
100
|
+
rdoc (3.9.4)
|
|
93
101
|
rspec (2.5.0)
|
|
94
102
|
rspec-core (~> 2.5.0)
|
|
95
103
|
rspec-expectations (~> 2.5.0)
|
|
96
104
|
rspec-mocks (~> 2.5.0)
|
|
97
|
-
rspec-core (2.5.
|
|
105
|
+
rspec-core (2.5.2)
|
|
98
106
|
rspec-expectations (2.5.0)
|
|
99
107
|
diff-lcs (~> 1.1.2)
|
|
100
108
|
rspec-mocks (2.5.0)
|
|
@@ -103,7 +111,7 @@ GEM
|
|
|
103
111
|
activesupport (~> 3.0)
|
|
104
112
|
railties (~> 3.0)
|
|
105
113
|
rspec (~> 2.5.0)
|
|
106
|
-
ruby-debug-base19 (0.11.
|
|
114
|
+
ruby-debug-base19 (0.11.25)
|
|
107
115
|
columnize (>= 0.3.1)
|
|
108
116
|
linecache19 (>= 0.5.11)
|
|
109
117
|
ruby_core_source (>= 0.1.4)
|
|
@@ -111,19 +119,26 @@ GEM
|
|
|
111
119
|
columnize (>= 0.3.1)
|
|
112
120
|
linecache19 (>= 0.5.11)
|
|
113
121
|
ruby-debug-base19 (>= 0.11.19)
|
|
114
|
-
ruby_core_source (0.1.
|
|
122
|
+
ruby_core_source (0.1.5)
|
|
115
123
|
archive-tar-minitar (>= 0.5.2)
|
|
116
|
-
simplecov (0.
|
|
117
|
-
simplecov-html (
|
|
118
|
-
simplecov-html (0.
|
|
119
|
-
|
|
124
|
+
simplecov (0.4.2)
|
|
125
|
+
simplecov-html (~> 0.4.4)
|
|
126
|
+
simplecov-html (0.4.5)
|
|
127
|
+
sprockets (2.0.0)
|
|
128
|
+
hike (~> 1.2)
|
|
129
|
+
rack (~> 1.0)
|
|
130
|
+
tilt (!= 1.3.0, ~> 1.1)
|
|
131
|
+
sqlite3 (1.3.4)
|
|
132
|
+
sqlite3-ruby (1.3.3)
|
|
133
|
+
sqlite3 (>= 1.3.3)
|
|
120
134
|
thor (0.14.6)
|
|
135
|
+
tilt (1.3.3)
|
|
121
136
|
timecop (0.3.5)
|
|
122
|
-
treetop (1.4.
|
|
137
|
+
treetop (1.4.10)
|
|
138
|
+
polyglot
|
|
123
139
|
polyglot (>= 0.3.1)
|
|
124
|
-
tzinfo (0.3.
|
|
125
|
-
|
|
126
|
-
yard (0.6.4)
|
|
140
|
+
tzinfo (0.3.29)
|
|
141
|
+
yard (0.6.8)
|
|
127
142
|
|
|
128
143
|
PLATFORMS
|
|
129
144
|
ruby
|
|
@@ -134,8 +149,8 @@ DEPENDENCIES
|
|
|
134
149
|
jeweler (~> 1.5.2)
|
|
135
150
|
json (>= 1.5.1)
|
|
136
151
|
mongoid (~> 2.0)
|
|
137
|
-
oauth (
|
|
138
|
-
oauth2 (
|
|
152
|
+
oauth (~> 0.4.4)
|
|
153
|
+
oauth2 (~> 0.5.1)
|
|
139
154
|
rails (>= 3.0.0)
|
|
140
155
|
rspec (~> 2.5.0)
|
|
141
156
|
rspec-rails (~> 2.5.0)
|
data/README.rdoc
CHANGED
|
@@ -5,7 +5,7 @@ Supports ActiveRecord and Mongoid.
|
|
|
5
5
|
Inspired by restful_authentication, Authlogic and Devise.
|
|
6
6
|
Crypto code taken almost unchanged from Authlogic.
|
|
7
7
|
OAuth code inspired by OmniAuth and Ryan Bates's railscasts about it.
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
|
|
10
10
|
== Philosophy
|
|
11
11
|
|
|
@@ -24,12 +24,13 @@ Hopefully, I've achieved this. If not, let me know.
|
|
|
24
24
|
|
|
25
25
|
== Useful Links:
|
|
26
26
|
|
|
27
|
+
Railscast: http://railscasts.com/episodes/283-authentication-with-sorcery
|
|
27
28
|
|
|
28
29
|
Example Rails 3 app using sorcery: https://github.com/NoamB/sorcery-example-app
|
|
29
30
|
|
|
30
31
|
Example Sinatra app using sorcery: https://github.com/NoamB/sorcery-example-app-sinatra
|
|
31
32
|
|
|
32
|
-
Documentation: http://rubydoc.info/gems/sorcery/0.
|
|
33
|
+
Documentation: http://rubydoc.info/gems/sorcery/0.7.0/frames
|
|
33
34
|
|
|
34
35
|
Check out the tutorials in the github wiki!
|
|
35
36
|
|
|
@@ -42,9 +43,10 @@ Below is a summary of the library methods. Most method names are self explaining
|
|
|
42
43
|
# core
|
|
43
44
|
require_login # this is a before filter
|
|
44
45
|
login(username,password,remember_me = false)
|
|
46
|
+
auto_login(user)# login without credentials
|
|
45
47
|
logout
|
|
46
|
-
logged_in?
|
|
47
|
-
current_user
|
|
48
|
+
logged_in? # available to view
|
|
49
|
+
current_user # available to view
|
|
48
50
|
redirect_back_or_to # used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
|
|
49
51
|
@user.external? # external users, such as facebook/twitter etc.
|
|
50
52
|
User.authenticates_with_sorcery!
|
|
@@ -61,6 +63,7 @@ Below is a summary of the library methods. Most method names are self explaining
|
|
|
61
63
|
create_from(provider) # create the user in the local app db.
|
|
62
64
|
|
|
63
65
|
# remember me
|
|
66
|
+
auto_login(user, should_remember=false) # login without credentials, optional remember_me
|
|
64
67
|
remember_me!
|
|
65
68
|
forget_me!
|
|
66
69
|
|
|
@@ -106,6 +109,7 @@ For your convenience, Sorcery includes a migrations generator for Rails, which c
|
|
|
106
109
|
|
|
107
110
|
rails g sorcery_migration [list of submodules]
|
|
108
111
|
|
|
112
|
+
Note: There is no migration for the session_timeout module.
|
|
109
113
|
For example, for only the core functionality use:
|
|
110
114
|
|
|
111
115
|
rails g sorcery_migration core
|
|
@@ -116,7 +120,12 @@ To generate migrations for both the core AND 'remember_me' submodule:
|
|
|
116
120
|
|
|
117
121
|
These migrations use the default fields. You can choose to use these migrations or make your own tables and fields. Sorcery tries not to impose a database structure and naming scheme on your application.
|
|
118
122
|
|
|
123
|
+
Finally, add sorcery to the the model that you will use for authentication:
|
|
119
124
|
|
|
125
|
+
class User < ActiveRecord::Base
|
|
126
|
+
authenticates_with_sorcery!
|
|
127
|
+
end
|
|
128
|
+
|
|
120
129
|
== Sinatra Configuration:
|
|
121
130
|
|
|
122
131
|
|
|
@@ -150,6 +159,7 @@ Core (see lib/sorcery/model.rb and lib/sorcery/controller.rb):
|
|
|
150
159
|
* login/logout, optional return user to requested url on login, configurable redirect for non-logged-in users.
|
|
151
160
|
* password encryption, algorithms: bcrypt(default), md5, sha1, sha256, sha512, aes256, custom(yours!), none. Configurable stretches and salt.
|
|
152
161
|
* configurable attribute names for username, password and email.
|
|
162
|
+
* allow multiple fields to serve as username.
|
|
153
163
|
|
|
154
164
|
User Activation (see lib/sorcery/model/submodules/user_activation.rb):
|
|
155
165
|
* User activation by email with optional success email.
|
data/Rakefile
CHANGED
|
@@ -25,9 +25,9 @@ Jeweler::Tasks.new do |gem|
|
|
|
25
25
|
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
|
26
26
|
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
|
27
27
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
|
28
|
-
gem.add_runtime_dependency 'bcrypt-ruby', '~>
|
|
29
|
-
gem.add_runtime_dependency 'oauth', '
|
|
30
|
-
gem.add_runtime_dependency 'oauth2', '
|
|
28
|
+
gem.add_runtime_dependency 'bcrypt-ruby', '~> 3.0.0'
|
|
29
|
+
gem.add_runtime_dependency 'oauth', '~> 0.4.4'
|
|
30
|
+
gem.add_runtime_dependency 'oauth2', '~> 0.5.1'
|
|
31
31
|
end
|
|
32
32
|
Jeweler::RubygemsDotOrgTasks.new
|
|
33
33
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.7.0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class SorceryCore < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
|
3
3
|
create_table :users do |t|
|
|
4
|
-
t.string :username, :null => false # if you use another
|
|
4
|
+
t.string :username, :null => false # if you use another field as a username, for example email, you can safely remove this field.
|
|
5
5
|
t.string :email, :default => nil # if you use this field as a username, you might want to make it :null => false.
|
|
6
6
|
t.string :crypted_password, :default => nil
|
|
7
7
|
t.string :salt, :default => nil
|
|
@@ -3,9 +3,13 @@ class SorceryResetPassword < ActiveRecord::Migration
|
|
|
3
3
|
add_column :users, :reset_password_token, :string, :default => nil
|
|
4
4
|
add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
|
|
5
5
|
add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
|
|
6
|
+
|
|
7
|
+
add_index :users, :reset_password_token
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
def self.down
|
|
11
|
+
remove_index :users, :reset_password_token
|
|
12
|
+
|
|
9
13
|
remove_column :users, :reset_password_email_sent_at
|
|
10
14
|
remove_column :users, :reset_password_token_expires_at
|
|
11
15
|
remove_column :users, :reset_password_token
|
|
@@ -80,15 +80,26 @@ module Sorcery
|
|
|
80
80
|
def initialize(request, response)
|
|
81
81
|
@request = request
|
|
82
82
|
@response = response
|
|
83
|
+
@secure = false
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
def [](key)
|
|
86
|
-
@request.cookies[key.to_s]
|
|
87
|
+
value = @request.cookies[key.to_s]
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
def []=(key, value)
|
|
91
|
+
if @secure
|
|
92
|
+
value.merge(:secret => Config.sinatra_cookie_secret)
|
|
93
|
+
@secure = false
|
|
94
|
+
end
|
|
90
95
|
@response.set_cookie(key, value)
|
|
91
96
|
end
|
|
97
|
+
|
|
98
|
+
# mark cookie as signed, which will light a flag, which will cause the next set_cookie to be encrypted.
|
|
99
|
+
def signed
|
|
100
|
+
@secure = true
|
|
101
|
+
self
|
|
102
|
+
end
|
|
92
103
|
end
|
|
93
104
|
|
|
94
105
|
module ClassMethods
|
|
@@ -14,6 +14,20 @@ module Sorcery
|
|
|
14
14
|
module ActivityLogging
|
|
15
15
|
def self.included(base)
|
|
16
16
|
base.send(:include, InstanceMethods)
|
|
17
|
+
Config.module_eval do
|
|
18
|
+
class << self
|
|
19
|
+
attr_accessor :register_login_time
|
|
20
|
+
attr_accessor :register_logout_time
|
|
21
|
+
attr_accessor :register_last_activity_time
|
|
22
|
+
|
|
23
|
+
def merge_activity_logging_defaults!
|
|
24
|
+
@defaults.merge!(:@register_login_time => true,
|
|
25
|
+
:@register_logout_time => true,
|
|
26
|
+
:@register_last_activity_time => true)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
merge_activity_logging_defaults!
|
|
30
|
+
end
|
|
17
31
|
Config.after_login << :register_login_time_to_db
|
|
18
32
|
Config.before_logout << :register_logout_time_to_db
|
|
19
33
|
base.after_filter :register_last_activity_time_to_db
|
|
@@ -37,6 +51,7 @@ module Sorcery
|
|
|
37
51
|
# registers last login time on every login.
|
|
38
52
|
# This runs as a hook just after a successful login.
|
|
39
53
|
def register_login_time_to_db(user, credentials)
|
|
54
|
+
return unless Config.register_login_time
|
|
40
55
|
user.send(:"#{user.sorcery_config.last_login_at_attribute_name}=", Time.now.utc.to_s(:db))
|
|
41
56
|
user.save!(:validate => false)
|
|
42
57
|
end
|
|
@@ -44,6 +59,7 @@ module Sorcery
|
|
|
44
59
|
# registers last logout time on every logout.
|
|
45
60
|
# This runs as a hook just before a logout.
|
|
46
61
|
def register_logout_time_to_db(user)
|
|
62
|
+
return unless Config.register_logout_time
|
|
47
63
|
user.send(:"#{user.sorcery_config.last_logout_at_attribute_name}=", Time.now.utc.to_s(:db))
|
|
48
64
|
user.save!(:validate => false)
|
|
49
65
|
end
|
|
@@ -51,7 +67,8 @@ module Sorcery
|
|
|
51
67
|
# Updates last activity time on every request.
|
|
52
68
|
# The only exception is logout - we do not update activity on logout
|
|
53
69
|
def register_last_activity_time_to_db
|
|
54
|
-
return
|
|
70
|
+
return unless Config.register_last_activity_time
|
|
71
|
+
return unless logged_in?
|
|
55
72
|
current_user.send(:"#{current_user.sorcery_config.last_activity_at_attribute_name}=", Time.now.utc.to_s(:db))
|
|
56
73
|
current_user.save!(:validate => false)
|
|
57
74
|
end
|
|
@@ -29,7 +29,8 @@ 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.
|
|
32
|
+
user.send(:"#{user_class.sorcery_config.failed_logins_count_attribute_name}=", 0)
|
|
33
|
+
user.save!
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
end
|