sorcery 0.3.1 → 0.4.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 (131) hide show
  1. data/Gemfile +3 -2
  2. data/Gemfile.lock +13 -11
  3. data/README.rdoc +89 -61
  4. data/Rakefile +4 -4
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery_migration/templates/core.rb +2 -2
  7. data/lib/sorcery.rb +1 -0
  8. data/lib/sorcery/controller.rb +16 -18
  9. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  10. data/lib/sorcery/crypto_providers/bcrypt.rb +1 -1
  11. data/lib/sorcery/crypto_providers/common.rb +35 -0
  12. data/lib/sorcery/crypto_providers/md5.rb +3 -23
  13. data/lib/sorcery/crypto_providers/sha1.rb +4 -16
  14. data/lib/sorcery/crypto_providers/sha256.rb +3 -23
  15. data/lib/sorcery/crypto_providers/sha512.rb +3 -23
  16. data/lib/sorcery/engine.rb +4 -0
  17. data/lib/sorcery/initializers/initializer.rb +86 -0
  18. data/lib/sorcery/model.rb +4 -2
  19. data/lib/sorcery/railties/tasks.rake +10 -0
  20. data/lib/sorcery/sinatra.rb +0 -9
  21. data/lib/sorcery/test_helpers.rb +12 -0
  22. data/lib/sorcery/test_helpers/rails.rb +6 -9
  23. data/lib/sorcery/test_helpers/sinatra.rb +6 -9
  24. data/sorcery.gemspec +137 -146
  25. data/spec/Gemfile +2 -2
  26. data/spec/Gemfile.lock +10 -10
  27. data/spec/Rakefile +1 -0
  28. data/spec/rails3/{app_root/.gitignore → .gitignore} +0 -0
  29. data/spec/rails3/.rspec +1 -1
  30. data/spec/rails3/{app_root/Gemfile → Gemfile} +4 -4
  31. data/spec/rails3/{app_root/Gemfile.lock → Gemfile.lock} +20 -20
  32. data/spec/rails3/{app_root/README → README} +0 -0
  33. data/spec/rails3/{app_root/Rakefile → Rakefile} +1 -0
  34. data/spec/rails3/{app_root/Rakefile.unused → Rakefile.unused} +0 -0
  35. data/spec/rails3/{app_root/app → app}/controllers/application_controller.rb +0 -0
  36. data/spec/rails3/{app_root/app → app}/helpers/application_helper.rb +0 -0
  37. data/spec/rails3/{app_root/app → app}/mailers/sorcery_mailer.rb +0 -0
  38. data/spec/rails3/{app_root/app → app}/models/authentication.rb +0 -0
  39. data/spec/rails3/{app_root/app → app}/models/user.rb +0 -0
  40. data/spec/rails3/{app_root/app → app}/views/layouts/application.html.erb +0 -0
  41. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.html.erb +0 -0
  42. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.text.erb +0 -0
  43. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.html.erb +0 -0
  44. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.text.erb +0 -0
  45. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.html.erb +0 -0
  46. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.text.erb +0 -0
  47. data/spec/rails3/{app_root/config.ru → config.ru} +0 -0
  48. data/spec/rails3/{app_root/config → config}/application.rb +0 -0
  49. data/spec/rails3/{app_root/config → config}/boot.rb +0 -0
  50. data/spec/rails3/config/database.yml +27 -0
  51. data/spec/rails3/{app_root/config → config}/environment.rb +0 -0
  52. data/spec/rails3/{app_root/config → config}/environments/development.rb +0 -0
  53. data/spec/rails3/{app_root/config → config}/environments/in_memory.rb +0 -0
  54. data/spec/rails3/{app_root/config → config}/environments/production.rb +0 -0
  55. data/spec/rails3/{app_root/config → config}/environments/test.rb +0 -0
  56. data/spec/rails3/{app_root/config → config}/initializers/backtrace_silencers.rb +0 -0
  57. data/spec/rails3/{app_root/config → config}/initializers/inflections.rb +0 -0
  58. data/spec/rails3/{app_root/config → config}/initializers/mime_types.rb +0 -0
  59. data/spec/rails3/{app_root/config → config}/initializers/secret_token.rb +0 -0
  60. data/spec/rails3/{app_root/config → config}/initializers/session_store.rb +0 -0
  61. data/spec/rails3/{app_root/config → config}/locales/en.yml +0 -0
  62. data/spec/rails3/{app_root/config → config}/routes.rb +0 -0
  63. data/spec/rails3/{app_root/db → db}/migrate/activation/20101224223622_add_activation_to_users.rb +0 -0
  64. data/spec/rails3/{app_root/db → db}/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -0
  65. data/spec/rails3/{app_root/db → db}/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
  66. data/spec/rails3/{app_root/db → db}/migrate/core/20101224223620_create_users.rb +0 -0
  67. data/spec/rails3/{app_root/db → db}/migrate/external/20101224223628_create_authentications.rb +0 -0
  68. data/spec/rails3/{app_root/db → db}/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
  69. data/spec/rails3/{app_root/db → db}/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
  70. data/spec/rails3/{app_root/db → db}/schema.rb +0 -0
  71. data/spec/rails3/{app_root/db → db}/seeds.rb +0 -0
  72. data/spec/rails3/{app_root/lib → lib}/tasks/.gitkeep +0 -0
  73. data/spec/rails3/{app_root/public → public}/404.html +0 -0
  74. data/spec/rails3/{app_root/public → public}/422.html +0 -0
  75. data/spec/rails3/{app_root/public → public}/500.html +0 -0
  76. data/spec/rails3/{app_root/public → public}/favicon.ico +0 -0
  77. data/spec/rails3/{app_root/public → public}/images/rails.png +0 -0
  78. data/spec/rails3/{app_root/public → public}/index.html +0 -0
  79. data/spec/rails3/{app_root/public → public}/javascripts/application.js +0 -0
  80. data/spec/rails3/{app_root/public → public}/javascripts/controls.js +0 -0
  81. data/spec/rails3/{app_root/public → public}/javascripts/dragdrop.js +0 -0
  82. data/spec/rails3/{app_root/public → public}/javascripts/effects.js +0 -0
  83. data/spec/rails3/{app_root/public → public}/javascripts/prototype.js +0 -0
  84. data/spec/rails3/{app_root/public → public}/javascripts/rails.js +0 -0
  85. data/spec/rails3/{app_root/public → public}/robots.txt +0 -0
  86. data/spec/rails3/{app_root/public → public}/stylesheets/.gitkeep +0 -0
  87. data/spec/rails3/{app_root/script → script}/rails +0 -0
  88. data/spec/rails3/{app_root/spec → spec}/controller_activity_logging_spec.rb +0 -0
  89. data/spec/rails3/{app_root/spec → spec}/controller_brute_force_protection_spec.rb +3 -2
  90. data/spec/rails3/{app_root/spec → spec}/controller_http_basic_auth_spec.rb +0 -0
  91. data/spec/rails3/{app_root/spec → spec}/controller_oauth2_spec.rb +10 -9
  92. data/spec/rails3/{app_root/spec → spec}/controller_oauth_spec.rb +5 -5
  93. data/spec/rails3/{app_root/spec → spec}/controller_remember_me_spec.rb +0 -0
  94. data/spec/rails3/{app_root/spec → spec}/controller_session_timeout_spec.rb +8 -4
  95. data/spec/rails3/{app_root/spec → spec}/controller_spec.rb +0 -0
  96. data/spec/rails3/spec/spec.opts +2 -0
  97. data/spec/rails3/{app_root/spec → spec}/spec_helper.orig.rb +0 -0
  98. data/spec/rails3/spec/spec_helper.rb +70 -0
  99. data/spec/rails3/{app_root/spec → spec}/user_activation_spec.rb +5 -1
  100. data/spec/rails3/{app_root/spec → spec}/user_activity_logging_spec.rb +0 -0
  101. data/spec/rails3/{app_root/spec → spec}/user_brute_force_protection_spec.rb +0 -0
  102. data/spec/rails3/{app_root/spec → spec}/user_oauth_spec.rb +3 -3
  103. data/spec/rails3/{app_root/spec → spec}/user_remember_me_spec.rb +0 -0
  104. data/spec/rails3/{app_root/spec → spec}/user_reset_password_spec.rb +7 -3
  105. data/spec/rails3/{app_root/spec → spec}/user_spec.rb +3 -9
  106. data/spec/rails3/{app_root/vendor → vendor}/plugins/.gitkeep +0 -0
  107. data/spec/sinatra/Gemfile +3 -3
  108. data/spec/sinatra/Gemfile.lock +17 -17
  109. data/spec/sinatra/Rakefile +1 -0
  110. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +3 -2
  111. data/spec/sinatra/spec/controller_oauth2_spec.rb +10 -9
  112. data/spec/sinatra/spec/controller_oauth_spec.rb +5 -5
  113. data/spec/sinatra/spec/controller_session_timeout_spec.rb +8 -4
  114. data/spec/sinatra/spec/spec.opts +2 -4
  115. data/spec/sinatra/spec/spec_helper.rb +2 -1
  116. data/spec/sorcery_crypto_providers_spec.rb +5 -4
  117. data/spec/spec.opts +2 -0
  118. data/spec/spec_helper.rb +3 -4
  119. metadata +148 -149
  120. data/lib/sorcery/controller/submodules/email.rb +0 -44
  121. data/lib/sorcery/controller/submodules/oauth.rb +0 -95
  122. data/spec/rails3/app_root/.rspec +0 -1
  123. data/spec/rails3/app_root/config/database.yml +0 -27
  124. data/spec/rails3/app_root/spec/spec_helper.rb +0 -62
  125. data/spec/sinatra/spec/user_activation_spec.rb +0 -188
  126. data/spec/sinatra/spec/user_activity_logging_spec.rb +0 -36
  127. data/spec/sinatra/spec/user_brute_force_protection_spec.rb +0 -76
  128. data/spec/sinatra/spec/user_oauth_spec.rb +0 -39
  129. data/spec/sinatra/spec/user_remember_me_spec.rb +0 -66
  130. data/spec/sinatra/spec/user_reset_password_spec.rb +0 -178
  131. data/spec/sinatra/spec/user_spec.rb +0 -317
data/Gemfile CHANGED
@@ -9,12 +9,13 @@ gem 'oauth2', ">= 0.1.1"
9
9
  # Add dependencies to develop your gem here.
10
10
  # Include everything needed to run rake, tests, features, etc.
11
11
  group :development do
12
- gem "rspec", "~> 2.3.0"
13
- gem 'rspec-rails'
12
+ gem "rspec", "~> 2.5.0"
13
+ gem 'rspec-rails', "~> 2.5.0"
14
14
  gem 'ruby-debug19'
15
15
  gem 'sqlite3-ruby', :require => 'sqlite3'
16
16
  gem "yard", "~> 0.6.0"
17
17
  gem "bundler", "~> 1.0.0"
18
18
  gem "jeweler", "~> 1.5.2"
19
19
  gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
20
+ gem 'timecop'
20
21
  end
data/Gemfile.lock CHANGED
@@ -81,19 +81,19 @@ GEM
81
81
  rake (>= 0.8.7)
82
82
  thor (~> 0.14.4)
83
83
  rake (0.8.7)
84
- rspec (2.3.0)
85
- rspec-core (~> 2.3.0)
86
- rspec-expectations (~> 2.3.0)
87
- rspec-mocks (~> 2.3.0)
88
- rspec-core (2.3.1)
89
- rspec-expectations (2.3.0)
84
+ rspec (2.5.0)
85
+ rspec-core (~> 2.5.0)
86
+ rspec-expectations (~> 2.5.0)
87
+ rspec-mocks (~> 2.5.0)
88
+ rspec-core (2.5.1)
89
+ rspec-expectations (2.5.0)
90
90
  diff-lcs (~> 1.1.2)
91
- rspec-mocks (2.3.0)
92
- rspec-rails (2.3.1)
91
+ rspec-mocks (2.5.0)
92
+ rspec-rails (2.5.0)
93
93
  actionpack (~> 3.0)
94
94
  activesupport (~> 3.0)
95
95
  railties (~> 3.0)
96
- rspec (~> 2.3.0)
96
+ rspec (~> 2.5.0)
97
97
  ruby-debug-base19 (0.11.24)
98
98
  columnize (>= 0.3.1)
99
99
  linecache19 (>= 0.5.11)
@@ -109,6 +109,7 @@ GEM
109
109
  simplecov-html (0.3.9)
110
110
  sqlite3-ruby (1.3.2)
111
111
  thor (0.14.6)
112
+ timecop (0.3.5)
112
113
  treetop (1.4.9)
113
114
  polyglot (>= 0.3.1)
114
115
  tzinfo (0.3.23)
@@ -124,9 +125,10 @@ DEPENDENCIES
124
125
  oauth (>= 0.4.4)
125
126
  oauth2 (>= 0.1.1)
126
127
  rails (>= 3.0.0)
127
- rspec (~> 2.3.0)
128
- rspec-rails
128
+ rspec (~> 2.5.0)
129
+ rspec-rails (~> 2.5.0)
129
130
  ruby-debug19
130
131
  simplecov (>= 0.3.8)
131
132
  sqlite3-ruby
133
+ timecop
132
134
  yard (~> 0.6.0)
data/README.rdoc CHANGED
@@ -28,11 +28,53 @@ Example Rails 3 app using sorcery: https://github.com/NoamB/sorcery-example-app
28
28
 
29
29
  Example Sinatra app using sorcery: https://github.com/NoamB/sorcery-example-app-sinatra
30
30
 
31
- Documentation: http://rubydoc.info/gems/sorcery/0.3.1/frames
31
+ Documentation: http://rubydoc.info/gems/sorcery/0.4.0/frames
32
32
 
33
33
  Check out the tutorials in the github wiki!
34
34
 
35
35
 
36
+ == API Summary
37
+
38
+
39
+ Below is a summary of the library methods. Most method names are self explaining and the rest are commented:
40
+
41
+ # core
42
+ require_login # this is a before filter
43
+ login(username,password,remember_me = false)
44
+ logout
45
+ logged_in?
46
+ current_user
47
+ 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.
48
+ @user.external? # external users, such as facebook/twitter etc.
49
+ User.authenticates_with_sorcery!
50
+
51
+ # activity logging
52
+ current_users
53
+
54
+ # http basic auth
55
+ require_login_from_http_basic # this is a before filter
56
+
57
+ # external
58
+ login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
59
+ login_from(provider) # tries to login from the external provider's callback.
60
+ create_from(provider) # create the user in the local app db.
61
+
62
+ # remember me
63
+ remember_me!
64
+ forget_me!
65
+
66
+ # reset password
67
+ User.load_from_reset_password_token(token)
68
+ @user.deliver_reset_password_instructions!
69
+ @user.reset_password!(params)
70
+
71
+ # user activation
72
+ User.load_from_activation_token(token)
73
+ @user.activate!
74
+
75
+ Please see the tutorials in the github wiki for detailed usage information.
76
+
77
+
36
78
  == Installation:
37
79
 
38
80
 
@@ -49,29 +91,15 @@ Otherwise simply
49
91
  gem install sorcery
50
92
 
51
93
 
52
- == Configuration:
53
-
94
+ == Rails 3 Configuration:
54
95
 
55
- 1. config/application.rb
56
96
 
57
- config.sorcery.submodules = [:user_activation, :remember_me] # add the submodules you want to use
58
- # You can also configure here any controller and any controller-submodule option here. For example:
59
- config.sorcery.session_timeout = 10.minutes
97
+ For Rails 3 create an initializer file using:
60
98
 
61
- 2. app/models/user.rb (or another model of your choice, but a User class is assumed by default)
99
+ rake sorcery:bootstrap
62
100
 
63
- activate_sorcery! do |config|
64
- config.user_activation_mailer = MyMailer
65
- config.username_attribute_name = :email
66
- end
67
-
68
- 3. app/controllers/application_controller.rb (OPTIONAL: this is actually needed only in some cases)
69
-
70
- activate_sorcery! do |config|
71
- config.session_timeout = 10.minutes
72
- end
73
-
74
- The configuration options vary with the submodules you've chosen to use, so check the documentation or the wiki tutorials regarding the specific submodule.
101
+ This will create the file as config/initializers/sorcery.rb .
102
+ Inside it the comments will tell you everything you need to know.
75
103
 
76
104
  For your convenience, Sorcery includes a migrations generator for Rails, which can be used like so:
77
105
 
@@ -88,44 +116,30 @@ To generate migrations for both the core AND 'remember_me' submodule:
88
116
  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.
89
117
 
90
118
 
91
- == API Summary
92
-
93
- Below is a summary of the library methods. Most method names are self explaining and the rest are commented:
94
-
95
- # core
96
- require_login # this is a before filter
97
- login(username,password,remember_me = false)
98
- logout
99
- logged_in?
100
- current_user
101
- 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.
102
- @user.external? # external users, such as facebook/twitter etc.
103
-
104
- # activity logging
105
- current_users
106
-
107
- # http basic auth
108
- require_login_from_http_basic # this is a before filter
119
+ == Sinatra Configuration:
109
120
 
110
- # external
111
- login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
112
- login_from(provider) # tries to login from the external provider's callback.
113
- create_from(provider) # create the user in the local app db.
114
121
 
115
- # remember me
116
- remember_me!
117
- forget_me!
122
+ For Sinatra you'll need to create the initializer manually. You can do it in the main app file or in a separate file you require (see example in example app). The code looks as follows:
118
123
 
119
- # reset password
120
- User.load_from_reset_password_token(token)
121
- @user.deliver_reset_password_instructions!
122
- @user.reset_password!(params)
124
+ Sorcery::Controller::Config.submodules = [] # specify here the submodules you want to include
125
+
126
+ Sorcery::Controller::Config.configure do |config|
127
+ config.session_timeout = 10.minutes
128
+ ...
129
+ ...
130
+
131
+ config.user_config do |user|
132
+ user.username_attribute_name = :email
133
+ ...
134
+ ...
135
+
136
+ end
137
+ end
123
138
 
124
- # user activation
125
- User.load_from_activation_token(token)
126
- @user.activate!
139
+ Finally, to make all the code above take effect, we'll need to re-include the sorcery controller module:
127
140
 
128
- Please see the tutorials in the github wiki for detailed usage information.
141
+ include Sorcery::Controller::Adapters::Sinatra
142
+ include Sorcery::Controller
129
143
 
130
144
 
131
145
  == Full Features List by module:
@@ -180,19 +194,32 @@ External (see lib/sorcery/controller/submodules/external.rb):
180
194
 
181
195
 
182
196
  I've got many plans which include (by priority):
197
+ * Forgot username, maybe as part of the reset_password module
183
198
  * Scoping logins (to a subdomain or another arbitrary field)
184
- * Simple auth (no user)
185
- * Switching authentication mode at runtime (Maintenance mode)
186
199
  * Mongoid support
187
200
  * Other reset password strategies (security questions?)
188
201
  * Other brute force protection strategies (captcha)
189
202
  * Have an idea? Let me know, and it might get into the gem!
190
203
 
191
204
  Other stuff:
205
+ * Improve specs speed
206
+ * Provide an easy way to run specs after install
192
207
  * Improve documentation
193
208
  * Tty to reduce the number of library methods, and find better names to some
194
209
 
195
210
 
211
+ == Backward compatibility
212
+
213
+
214
+ While the lib is young and evolving fast I'm breaking backward compatibility quite often.
215
+ I'm constantly finding better ways to do things and throwing away old ways.
216
+ To let you know when things are changing in a non-compatible way, I'm bumping the minor version of the gem.
217
+ The patch version changes are backward compatible.
218
+
219
+ In short, an app that works with x.3.1 should be able to upgrade to x.3.2 with no code changes.
220
+ The same cannot be said about upgrading to x.4.0 and above, however.
221
+
222
+
196
223
  == Contributing to sorcery
197
224
 
198
225
 
@@ -200,17 +227,18 @@ Your feedback is very welcome and will make this gem much much better for you, m
200
227
  Besides feedback on code, features, suggestions and bug reports, you may want to actually make an impact on the code.
201
228
  For this:
202
229
 
203
- * Fork the project.
204
- * Make your feature addition or bug fix.
205
- * Add tests for it. I've used RSpec so far, please remain consistent with it.
206
- * Commit, do not mess with Rakefiles, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
207
- * Send me a pull request. Bonus points for topic branches.
230
+ * Fork it.
231
+ * Fix it.
232
+ * Test it.
233
+ * Commit it.
234
+ * Send me a pull request so I'll... Pull it.
208
235
 
209
- If you feel my work has made your life easier, and you would like to thank me through a donation, my paypal email is in the contact details.
236
+ If you feel sorcery has made your life easier, and you would like to express your thanks via a donation, my paypal email is in the contact details.
210
237
 
211
238
 
212
239
  == Contact
213
240
 
241
+
214
242
  Feel free to ask questions using these contact details:
215
243
 
216
244
  email: nbenari@gmail.com ( also for paypal )
data/Rakefile CHANGED
@@ -41,11 +41,11 @@ end
41
41
  require 'yard'
42
42
  YARD::Rake::YardocTask.new
43
43
 
44
- desc 'Default: Run all specs.'
45
- task :default => :all_specs
44
+ desc 'Default: Run all sorcery specs.'
45
+ task :default => :all_sorcery_specs
46
46
 
47
- desc "Run all specs"
48
- task :all_specs do
47
+ desc "Run all sorcery specs"
48
+ task :all_sorcery_specs do
49
49
  Dir['spec/**/Rakefile'].each do |rakefile|
50
50
  directory_name = File.dirname(rakefile)
51
51
  sh <<-CMD
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -1,8 +1,8 @@
1
1
  class SorceryCore < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :users do |t|
4
- t.string :username, :null => false
5
- t.string :email, :default => nil
4
+ t.string :username, :null => false # if you use another filed as a username, for example email, you can safely remove this field.
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
8
8
 
data/lib/sorcery.rb CHANGED
@@ -36,6 +36,7 @@ module Sorcery
36
36
  end
37
37
  end
38
38
  module CryptoProviders
39
+ autoload :Common, 'sorcery/crypto_providers/common'
39
40
  autoload :AES256, 'sorcery/crypto_providers/aes256'
40
41
  autoload :BCrypt, 'sorcery/crypto_providers/bcrypt'
41
42
  autoload :MD5, 'sorcery/crypto_providers/md5'
@@ -2,7 +2,6 @@ module Sorcery
2
2
  module Controller
3
3
  def self.included(klass)
4
4
  klass.class_eval do
5
- extend ClassMethods
6
5
  include InstanceMethods
7
6
  Config.submodules.each do |mod|
8
7
  begin
@@ -11,19 +10,9 @@ module Sorcery
11
10
  # don't stop on a missing submodule.
12
11
  end
13
12
  end
14
- Config.update!
15
- end
16
- end
17
-
18
- module ClassMethods
19
- def activate_sorcery!(&block)
20
- yield Config if block_given?
21
- after_config!
22
- end
23
-
24
- def after_config!
25
- Config.after_config.each {|c| send(c)}
26
13
  end
14
+ Config.update!
15
+ Config.configure!
27
16
  end
28
17
 
29
18
  module InstanceMethods
@@ -126,7 +115,7 @@ module Sorcery
126
115
  class << self
127
116
  attr_accessor :submodules,
128
117
 
129
- :user_class, # what class to use as the user class. Set automatically when you call activate_sorcery! in the User class.
118
+ :user_class, # what class to use as the user class. Set automatically when you call authenticates_with_sorcery! in the User class.
130
119
 
131
120
  :not_authenticated_action, # what controller action to call for non-authenticated users.
132
121
 
@@ -137,9 +126,7 @@ module Sorcery
137
126
  :after_login,
138
127
  :after_failed_login,
139
128
  :before_logout,
140
- :after_logout,
141
- :after_config
142
-
129
+ :after_logout
143
130
 
144
131
  def init!
145
132
  @defaults = {
@@ -151,7 +138,6 @@ module Sorcery
151
138
  :@after_failed_login => [],
152
139
  :@before_logout => [],
153
140
  :@after_logout => [],
154
- :@after_config => [],
155
141
  :@save_return_to_url => true
156
142
  }
157
143
  end
@@ -168,6 +154,18 @@ module Sorcery
168
154
  instance_variable_set(k,v) if !instance_variable_defined?(k)
169
155
  end
170
156
  end
157
+
158
+ def user_config(&blk)
159
+ block_given? ? @user_config = blk : @user_config
160
+ end
161
+
162
+ def configure(&blk)
163
+ @configure_blk = blk
164
+ end
165
+
166
+ def configure!
167
+ @configure_blk.call(self) if @configure_blk
168
+ end
171
169
  end
172
170
  init!
173
171
  reset!
@@ -9,7 +9,7 @@ module Sorcery
9
9
  base.send(:include, InstanceMethods)
10
10
  Config.module_eval do
11
11
  class << self
12
- attr_accessor :controller_to_realm_map # how many failed logins allowed.
12
+ attr_accessor :controller_to_realm_map # What realm to display for which controller name.
13
13
 
14
14
  def merge_http_basic_auth_defaults!
15
15
  @defaults.merge!(:@controller_to_realm_map => {"application" => "Application"})
@@ -42,7 +42,7 @@ module Sorcery
42
42
  # This is the :cost option for the BCrpyt library. The higher the cost the more secure it is and the longer is take the generate a hash. By default this is 10.
43
43
  # Set this to whatever you want, play around with it to get that perfect balance between security and performance.
44
44
  def cost
45
- @cost ||= 1
45
+ @cost ||= 10
46
46
  end
47
47
  attr_writer :cost
48
48
  alias :stretches= :cost=
@@ -0,0 +1,35 @@
1
+ module Sorcery
2
+ module CryptoProviders
3
+ module Common
4
+ def self.included(base)
5
+ base.class_eval do
6
+ class << self
7
+ attr_accessor :join_token
8
+
9
+ # The number of times to loop through the encryption.
10
+ def stretches
11
+ @stretches ||= 1
12
+ end
13
+ attr_writer :stretches
14
+
15
+ def encrypt(*tokens)
16
+ digest = tokens.flatten.join(join_token)
17
+ stretches.times { digest = secure_digest(digest) }
18
+ digest
19
+ end
20
+
21
+ # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
22
+ def matches?(crypted, *tokens)
23
+ encrypt(*tokens) == crypted
24
+ end
25
+
26
+ def reset!
27
+ @stretches = 1
28
+ @join_token = nil
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end