sorcery 0.9.0 → 0.10.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.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -104
  3. data/CHANGELOG.md +22 -1
  4. data/Gemfile +2 -16
  5. data/README.md +124 -271
  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 +29 -53
  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 +3 -3
  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/adapters/active_record_adapter.rb +7 -18
  19. data/lib/sorcery/controller/config.rb +20 -18
  20. data/lib/sorcery/controller/submodules/activity_logging.rb +7 -15
  21. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  22. data/lib/sorcery/controller/submodules/external.rb +23 -15
  23. data/lib/sorcery/controller/submodules/http_basic_auth.rb +16 -19
  24. data/lib/sorcery/controller/submodules/remember_me.rb +15 -10
  25. data/lib/sorcery/controller/submodules/session_timeout.rb +7 -8
  26. data/lib/sorcery/controller.rb +19 -21
  27. data/lib/sorcery/crypto_providers/aes256.rb +15 -15
  28. data/lib/sorcery/crypto_providers/bcrypt.rb +19 -21
  29. data/lib/sorcery/crypto_providers/common.rb +1 -1
  30. data/lib/sorcery/crypto_providers/md5.rb +5 -5
  31. data/lib/sorcery/crypto_providers/sha1.rb +5 -5
  32. data/lib/sorcery/crypto_providers/sha256.rb +2 -2
  33. data/lib/sorcery/crypto_providers/sha512.rb +3 -3
  34. data/lib/sorcery/engine.rb +3 -8
  35. data/lib/sorcery/model/config.rb +64 -49
  36. data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
  37. data/lib/sorcery/model/submodules/brute_force_protection.rb +23 -23
  38. data/lib/sorcery/model/submodules/external.rb +3 -7
  39. data/lib/sorcery/model/submodules/remember_me.rb +19 -7
  40. data/lib/sorcery/model/submodules/reset_password.rb +32 -36
  41. data/lib/sorcery/model/submodules/user_activation.rb +38 -50
  42. data/lib/sorcery/model/temporary_token.rb +2 -2
  43. data/lib/sorcery/model.rb +27 -31
  44. data/lib/sorcery/protocols/oauth.rb +3 -9
  45. data/lib/sorcery/protocols/oauth2.rb +0 -2
  46. data/lib/sorcery/providers/base.rb +4 -4
  47. data/lib/sorcery/providers/facebook.rb +17 -9
  48. data/lib/sorcery/providers/github.rb +12 -5
  49. data/lib/sorcery/providers/google.rb +3 -5
  50. data/lib/sorcery/providers/heroku.rb +6 -8
  51. data/lib/sorcery/providers/jira.rb +12 -17
  52. data/lib/sorcery/providers/linkedin.rb +6 -8
  53. data/lib/sorcery/providers/liveid.rb +4 -7
  54. data/lib/sorcery/providers/paypal.rb +60 -0
  55. data/lib/sorcery/providers/salesforce.rb +3 -5
  56. data/lib/sorcery/providers/slack.rb +45 -0
  57. data/lib/sorcery/providers/twitter.rb +4 -6
  58. data/lib/sorcery/providers/vk.rb +3 -5
  59. data/lib/sorcery/providers/wechat.rb +79 -0
  60. data/lib/sorcery/providers/xing.rb +8 -11
  61. data/lib/sorcery/test_helpers/internal/rails.rb +16 -8
  62. data/lib/sorcery/test_helpers/internal.rb +10 -10
  63. data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
  64. data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
  65. data/lib/sorcery/version.rb +1 -1
  66. data/lib/sorcery.rb +0 -28
  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 +142 -102
  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/application.rb +7 -7
  89. data/spec/rails_app/config/boot.rb +1 -1
  90. data/spec/rails_app/config/environments/test.rb +1 -1
  91. data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
  92. data/spec/rails_app/config/initializers/session_store.rb +3 -3
  93. data/spec/rails_app/config/routes.rb +11 -1
  94. data/spec/rails_app/config.ru +1 -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 +226 -116
  109. data/spec/sorcery_crypto_providers_spec.rb +63 -76
  110. data/spec/spec_helper.rb +17 -13
  111. metadata +28 -82
  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
  150. data/spec/rails_app/log/development.log +0 -1791
data/README.md CHANGED
@@ -1,95 +1,96 @@
1
- [![Build Status](https://travis-ci.org/NoamB/sorcery.svg?branch=master)](https://travis-ci.org/NoamB/sorcery)
2
- [![Code Climate](https://codeclimate.com/github/NoamB/sorcery.png)](https://codeclimate.com/github/NoamB/sorcery)
3
- [![Inline docs](http://inch-ci.org/github/NoamB/sorcery.png?branch=master)](http://inch-ci.org/github/NoamB/sorcery)
1
+ # Sorcery: Magical Authentication
4
2
 
5
- # sorcery
6
- Magical Authentication for Rails 3 and 4. Supports ActiveRecord,
7
- DataMapper, Mongoid and MongoMapper.
3
+ [![Gem Version](https://badge.fury.io/rb/sorcery.svg)](https://rubygems.org/gems/sorcery)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/sorcery.svg)](https://rubygems.org/gems/sorcery)
5
+ [![Build Status](https://travis-ci.org/Sorcery/sorcery.svg?branch=master)](https://travis-ci.org/Sorcery/sorcery)
6
+ [![Code Climate](https://codeclimate.com/github/Sorcery/sorcery.svg)](https://codeclimate.com/github/Sorcery/sorcery)
7
+ [![Inline docs](http://inch-ci.org/github/Sorcery/sorcery.svg?branch=master)](http://inch-ci.org/github/Sorcery/sorcery)
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)
8
9
 
9
- Inspired by restful_authentication, Authlogic and Devise. Crypto code taken
10
- almost unchanged from Authlogic. OAuth code inspired by OmniAuth and Ryan
11
- Bates's railscasts about it.
10
+ Magical Authentication for Rails. Supports ActiveRecord, DataMapper, Mongoid and MongoMapper.
12
11
 
13
- **What's happening now?** We are working on 1.0 version, which will include some API-breaking changes. It should be released about April 2015.
14
- Until then we'll continue releasing `0.9.x` version with bug fixed.
12
+ Inspired by Restful Authentication, Authlogic and Devise. Crypto code taken almost unchanged from Authlogic. OAuth code inspired by OmniAuth and Ryan Bates's Railscast about it.
15
13
 
16
- **Rails 4 status:** [Sorcery 0.9.0](http://rubygems.org/gems/sorcery/versions/0.9.0) is fully tested and ready for Rails 4.0, 4.1 and 4.2.
17
- **Mongoid status:** Version 0.9.0 works with Mongoid 4.
14
+ ### Philosophy
18
15
 
19
- https://github.com/NoamB/sorcery/wiki/Simple-Password-Authentication
16
+ Sorcery is a stripped-down, bare-bones authentication library, with which you can write your own authentication flow. It was built with a few goals in mind:
20
17
 
21
- ## Philosophy
22
-
23
- Sorcery is a stripped-down, bare-bones authentication library, with which you
24
- can write your own authentication flow. It was built with a few goals in mind:
25
-
26
- * Less is more - less than 20 public methods to remember for the entire
27
- feature-set make the lib easy to 'get'.
28
- * No built-in or generated code - use the library's methods inside *your
29
- own* MVC structures, and don't fight to fix someone else's.
30
- * Magic yes, Voodoo no - the lib should be easy to hack for most developers.
31
- * Configuration over Confusion - Centralized (1 file), Simple & short
32
- configuration as possible, not drowning in syntactic sugar.
33
- * Keep MVC cleanly separated - DB is for models, sessions are for
34
- controllers. Models stay unaware of sessions.
35
-
36
-
37
- Hopefully, I've achieved this. If not, let me know.
18
+ - Less is more - less than 20 public methods to remember for the entire feature-set make the lib easy to 'get'.
19
+ - No built-in or generated code - use the library's methods inside *your own* MVC structures, and don't fight to fix someone else's.
20
+ - Magic yes, Voodoo no - the lib should be easy to hack for most developers.
21
+ - Configuration over Confusion - Centralized (1 file), Simple & short configuration as possible, not drowning in syntactic sugar.
22
+ - Keep MVC cleanly separated - DB is for models, sessions are for controllers. Models stay unaware of sessions.
38
23
 
39
24
  ## Useful Links
40
25
 
41
- [Documentation](http://rubydoc.info/gems/sorcery) |
42
- [Railscast](http://railscasts.com/episodes/283-authentication-with-sorcery) | [Simple tutorial](https://github.com/NoamB/sorcery/wiki/Simple-Password-Authentication) | [Example Rails 3 app](https://github.com/NoamB/sorcery-example-app)
26
+ - [Documentation](http://rubydoc.info/gems/sorcery)
27
+ - [Railscast](http://railscasts.com/episodes/283-authentication-with-sorcery)
28
+ - [Simple tutorial](https://github.com/Sorcery/sorcery/wiki/Simple-Password-Authentication)
29
+ - [Example Rails app](https://github.com/Sorcery/sorcery-example-app)
43
30
 
44
- Check out the tutorials in the [Wiki](https://github.com/NoamB/sorcery/wiki) for more!
31
+ Check out the tutorials in the [wiki](https://github.com/Sorcery/sorcery/wiki) for more:
32
+
33
+ - [DataMapper Support](https://github.com/Sorcery/sorcery/wiki/DataMapper-Support)
34
+ - [DelayedJob Integration](https://github.com/Sorcery/sorcery/wiki/DelayedJob-Integration)
35
+ - [Simple Password Authentication](https://github.com/Sorcery/sorcery/wiki/Simple-Password-Authentication)
36
+ - [Single Table Inheritance Support](https://github.com/Sorcery/sorcery/wiki/Single-Table-Inheritance-Support)
37
+ - [Upgrading](https://github.com/Sorcery/sorcery/wiki/Upgrading)
45
38
 
46
39
  ## API Summary
47
40
 
48
41
  Below is a summary of the library methods. Most method names are self
49
42
  explaining and the rest are commented:
50
43
 
44
+ ### Core
51
45
 
52
- ### core
53
46
  ```ruby
54
- require_login # this is a before filter
47
+ require_login # This is a before action
55
48
  login(email, password, remember_me = false)
56
- auto_login(user)# login without credentials
49
+ auto_login(user) # Login without credentials
57
50
  logout
58
- logged_in? # available to view
59
- current_user # available to view
60
- 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.
61
- @user.external? # external users, such as facebook/twitter etc.
51
+ logged_in? # Available in views
52
+ current_user # Available in views
53
+ redirect_back_or_to # Use 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
54
+ @user.external? # Users who signed up using Facebook, Twitter, etc.
55
+ @user.active_for_authentication? # Add this method to define behaviour that will prevent selected users from signing in
56
+ @user.valid_password?('secret') # Compares 'secret' with the actual user's password, returns true if they match
62
57
  User.authenticates_with_sorcery!
63
58
  ```
64
59
 
65
- ### http basic auth
60
+ ### HTTP Basic Auth
61
+
66
62
  ```ruby
67
- require_login_from_http_basic # this is a before filter
63
+ require_login_from_http_basic # This is a before action
68
64
  ```
69
65
 
70
- ### external
66
+ ### External
67
+
71
68
  ```ruby
72
- login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
73
- login_from(provider) # tries to login from the external provider's callback.
74
- create_from(provider) # create the user in the local app db.
69
+ login_at(provider) # Sends the user to an external service (Facebook, Twitter, etc.) to authenticate
70
+ login_from(provider) # Tries to login from the external provider's callback
71
+ create_from(provider) # Create the user in the local app database
75
72
  ```
76
73
 
77
- ### remember me
74
+ ### Remember Me
75
+
78
76
  ```ruby
79
- auto_login(user, should_remember=false) # login without credentials, optional remember_me
77
+ auto_login(user, should_remember = false) # Login without credentials, optional remember_me
80
78
  remember_me!
81
79
  forget_me!
80
+ force_forget_me! # Forgets all sessions by clearing the token, even if remember_me_token_persist_globally is set to true
82
81
  ```
83
82
 
84
- ### reset password
83
+ ### Reset Password
84
+
85
85
  ```ruby
86
86
  User.load_from_reset_password_token(token)
87
- @user.generate_reset_password_token! # if you want to send the email by youself
88
- @user.deliver_reset_password_instructions! # generates the token and sends the email
87
+ @user.generate_reset_password_token! # Use if you want to send the email by yourself
88
+ @user.deliver_reset_password_instructions! # Generates the token and sends the email
89
89
  @user.change_password!(new_password)
90
90
  ```
91
91
 
92
- ### user activation
92
+ ### User Activation
93
+
93
94
  ```ruby
94
95
  User.load_from_activation_token(token)
95
96
  @user.setup_activation
@@ -100,272 +101,124 @@ Please see the tutorials in the github wiki for detailed usage information.
100
101
 
101
102
  ## Installation
102
103
 
103
- If using bundler, first add 'sorcery' to your Gemfile:
104
+ Add this line to your application's Gemfile:
104
105
 
105
106
  ```ruby
106
- gem "sorcery"
107
+ gem 'sorcery'
107
108
  ```
108
109
 
109
- And run
110
+ And then execute:
110
111
 
111
- ```ruby
112
- bundle install
113
- ```
112
+ $ bundle
114
113
 
115
- Otherwise simply
114
+ Or install it yourself as:
116
115
 
117
- ```ruby
118
- gem install sorcery
119
- ```
116
+ $ gem install sorcery
120
117
 
121
- ## Rails configuration
118
+ ## Configuration
122
119
 
123
- ```bash
124
- rails generate sorcery:install
125
- ```
120
+ Run the following command to generate the core migration file, the initializer file and the
121
+ `User` model class.
126
122
 
127
- This will generate the core migration file, the initializer file and the
128
- 'User' model class.
123
+ $ rails generate sorcery:install
129
124
 
130
- ```bash
131
- rails generate sorcery:install remember_me reset_password
132
- ```
125
+ Run the following command generate the migrations files for remember_me and reset_password submodules and will create the initializer file (and add submodules to it), and create the `User` model class.
133
126
 
134
- This will generate the migrations files for remember_me and reset_password
135
- submodules and will create the initializer file (and add submodules to it),
136
- and create the 'User' model class.
127
+ $ rails generate sorcery:install remember_me reset_password
137
128
 
138
- ```bash
139
- rails generate sorcery:install --model Person
140
- ```
129
+ Run the following command to generate the core migration file, the initializer and change the model class (in the initializer and migration files) to the class `Person` (and its pluralized version, 'people')
141
130
 
142
- This will generate the core migration file, the initializer and change the
143
- model class (in the initializer and migration files) to the class 'Person'
144
- (and its pluralized version, 'people')
131
+ $ rails generate sorcery:install --model Person
145
132
 
146
- ```bash
147
- rails generate sorcery:install http_basic_auth external remember_me --only-submodules
148
- ```
133
+ Run the following command to generate only the migration files for the specified submodules and will add them to the initializer file.
149
134
 
150
- This will generate only the migration files for the specified submodules and
151
- will add them to the initializer file.
135
+ $ rails generate sorcery:install http_basic_auth external remember_me --only-submodules
152
136
 
153
137
  Inside the initializer, the comments will tell you what each setting does.
154
138
 
155
- ## DelayedJob Integration
156
-
157
- By default emails are sent synchronously. You can send them asynchronously by
158
- using the [delayed_job gem](https://github.com/collectiveidea/delayed_job).
159
-
160
- After implementing the `delayed_job` into your project add the code below at
161
- the end of the `config/initializers/sorcery.rb` file. After that all emails
162
- will be sent asynchronously.
163
-
164
- ```ruby
165
- module Sorcery
166
- module Model
167
- module InstanceMethods
168
- def generic_send_email(method, mailer)
169
- config = sorcery_config
170
- mail = config.send(mailer).delay.send(config.send(method), self)
171
- end
172
- end
173
- end
174
- end
175
- ```
176
-
177
- Sidekiq and Resque integrations are coming soon.
178
-
179
- ## Single Table Inheritance (STI) Support
180
- STI is supported via a single setting in config/initializers/sorcery.rb.
181
-
182
- ## Full Features List by module
183
-
184
- **Core** (see [lib/sorcery/model.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model.rb) and
185
- [lib/sorcery/controller.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller.rb)):
186
-
187
- * login/logout, optional return user to requested url on login, configurable
188
- redirect for non-logged-in users.
189
- * password encryption, algorithms: bcrypt(default), md5, sha1, sha256,
190
- sha512, aes256, custom(yours!), none. Configurable stretches and salt.
191
- * configurable attribute names for username, password and email.
192
- * allow multiple fields to serve as username.
193
-
194
-
195
- **User Activation** (see [lib/sorcery/model/submodules/user_activation.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/user_activation.rb)):
196
-
197
- * User activation by email with optional success email.
198
- * configurable attribute names.
199
- * configurable mailer, method name, and attribute name.
200
- * configurable temporary token expiration.
201
- * Optionally prevent non-active users to login.
139
+ ## Full Features List by Module
202
140
 
141
+ **Core** (see [lib/sorcery/model.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model.rb) and [lib/sorcery/controller.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/controller.rb)):
203
142
 
204
- **Reset Password** (see [lib/sorcery/model/submodules/reset_password.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/reset_password.rb)):
143
+ - Login / logout, optional return user to requested url on login, configurable redirect for non-logged-in users.
144
+ - Password encryption, algorithms: bcrypt (default), MD5, SHA-1, SHA-256, SHA-512, AES or custom. Configurable stretches and salt.
145
+ - Configurable attribute names for username, password and email.
146
+ - Allow multiple fields to serve as username.
205
147
 
206
- * Reset password with email verification.
207
- * configurable mailer, method name, and attribute name.
208
- * configurable temporary token expiration.
209
- * configurable time between emails (hammering protection).
148
+ **User Activation** (see [lib/sorcery/model/submodules/user_activation.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/user_activation.rb)):
210
149
 
150
+ - User activation by email with optional success email
151
+ - Configurable attribute names
152
+ - Configurable mailer, method name, and attribute name
153
+ - Configurable temporary token expiration
154
+ - Optionally prevent non-active users to login
211
155
 
212
- **Remember Me** (see [lib/sorcery/model/submodules/remember_me.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/remember_me.rb)):
156
+ **Reset Password** (see [lib/sorcery/model/submodules/reset_password.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/reset_password.rb)):
213
157
 
214
- * Remember me with configurable expiration.
215
- * configurable attribute names.
158
+ - Reset password with email verification
159
+ - Configurable mailer, method name, and attribute name
160
+ - Configurable temporary token expiration
161
+ - Configurable time between emails (hammering protection)
216
162
 
163
+ **Remember Me** (see [lib/sorcery/model/submodules/remember_me.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/remember_me.rb)):
217
164
 
218
- **Session Timeout** (see [lib/sorcery/controller/submodules/session_timeout.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/session_timeout.rb)):
165
+ - Remember me with configurable expiration
166
+ - Configurable attribute names
167
+ - Configurable to persist globally (supporting multiple browsers at the same time), or starting anew after each login
219
168
 
220
- * Configurable session timeout.
221
- * Optionally session timeout will be calculated from last user action.
169
+ **Session Timeout** (see [lib/sorcery/controller/submodules/session_timeout.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/controller/submodules/session_timeout.rb)):
222
170
 
171
+ - Configurable session timeout
172
+ - Optionally session timeout will be calculated from last user action
223
173
 
224
- **Brute Force Protection** (see [lib/sorcery/model/submodules/brute_force_protection.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/brute_force_protection.rb)):
174
+ **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)):
225
175
 
226
- * Brute force login hammering protection.
227
- * configurable logins before lock and lock duration.
176
+ - Brute force login hammering protection
177
+ - configurable logins before lock and lock duration
228
178
 
179
+ **Basic HTTP Authentication** (see [lib/sorcery/controller/submodules/http_basic_auth.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/controller/submodules/http_basic_auth.rb)):
229
180
 
230
- **Basic HTTP Authentication** (see [lib/sorcery/controller/submodules/http_basic_auth.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/http_basic_auth.rb)):
181
+ - A before action for requesting authentication with HTTP Basic
182
+ - Automatic login from HTTP Basic
183
+ - Automatic login is disabled if session key changed
231
184
 
232
- * A before filter for requesting authentication with HTTP Basic.
233
- * automatic login from HTTP Basic.
234
- * automatic login is disabled if session key changed.
185
+ **Activity Logging** (see [lib/sorcery/model/submodules/activity_logging.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/activity_logging.rb)):
235
186
 
187
+ - Automatic logging of last login, last logout, last activity time and IP address for last login
188
+ - Configurable timeout by which to decide whether to include a user in the list of logged in users
236
189
 
237
- **Activity Logging** (see [lib/sorcery/model/submodules/activity_logging.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/activity_logging.rb)):
190
+ **External** (see [lib/sorcery/controller/submodules/external.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/controller/submodules/external.rb)):
238
191
 
239
- * automatic logging of last login, last logout, last activity time and IP
240
- address for last login.
241
- * an easy method of collecting the list of currently logged in users.
242
- * configurable timeout by which to decide whether to include a user in the
243
- list of logged in users.
192
+ - OAuth1 and OAuth2 support (currently: Twitter, Facebook, Github, Google, Heroku, LinkedIn, VK, LiveID, Xing, Salesforce)
193
+ - Configurable database column names
194
+ - Authentications table
244
195
 
196
+ ## Planned Features
245
197
 
246
- **External** (see [lib/sorcery/controller/submodules/external.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/external.rb)):
198
+ - Passing a block to encrypt, allowing the developer to define his own mix of salting and encrypting
199
+ - Forgot username, maybe as part of the reset_password module
200
+ - Scoping logins (to a subdomain or another arbitrary field)
201
+ - Allowing storing the salt and encrypted password in the same DB field for extra security
202
+ - Other reset password strategies (security questions?)
203
+ - Other brute force protection strategies (captcha)
247
204
 
248
- * OAuth1 and OAuth2 support (currently: Twitter, Facebook, Github, Google, Heroku,
249
- LinkedIn, VK, LiveID, Xing, and Salesforce)
250
- * configurable db field names and authentications table.
205
+ Have an idea? Let us know, and it might get into the gem!
251
206
 
207
+ ## Contributing
252
208
 
253
- ## Next Planned Features
254
-
255
- I've got some thoughts which include (unordered):
256
-
257
- * Passing a block to encrypt, allowing the developer to define his own mix
258
- of salting and encrypting
259
- * Forgot username, maybe as part of the reset_password module
260
- * Scoping logins (to a subdomain or another arbitrary field)
261
- * Allowing storing the salt and crypted password in the same DB field for
262
- extra security
263
- * Other reset password strategies (security questions?)
264
- * Other brute force protection strategies (captcha)
265
-
266
-
267
- Have an idea? Let me know, and it might get into the gem!
268
-
269
- ## Backward compatibility
270
-
271
- While the lib is young and evolving fast I'm breaking backward compatibility
272
- quite often. I'm constantly finding better ways to do things and throwing away
273
- old ways. To let you know when things are changing in a non-compatible way,
274
- I'm bumping the minor version of the gem. The patch version changes are
275
- backward compatible.
276
-
277
- In short, an app that works with x.3.1 should be able to upgrade to x.3.2 with
278
- no code changes. The same cannot be said about upgrading to x.4.0 and above,
279
- however.
280
-
281
- ## DataMapper Support
282
-
283
- Important notes:
284
-
285
- * Expected to work with DM adapters: dm-mysql-adapter,
286
- dm-redis-adapter.
287
- * Submodules DM adapter dependent: activity_logging (dm-mysql-adapter)
288
- * Usage: include DataMapper::Resource in user model, follow sorcery
289
- instructions (remember to add property id, validators and accessor
290
- attributes such as password and password_confirmation)
291
- * Option downcase__username_before_authenticating and dm-mysql,
292
- http://datamapper.lighthouseapp.com/projects/20609/tickets/1105-add-support-for-definingchanging-default-collation
293
-
294
- ## Upgrading
295
-
296
- Important notes while upgrading:
297
-
298
- * If you are upgrading from <= **0.8.6** and you use Sorcery model methods in your app,
299
- you might need to change them from `user.method` to `user.sorcery_adapter.method` and from
300
- `User.method` to `User.sorcery_adapter_method`
301
-
302
- * If you are upgrading from <= **0.8.5** and you're using Sorcery test helpers,
303
- you need to change the way you include them to following code:
304
-
305
- ```ruby
306
- RSpec.configure do |config|
307
- config.include Sorcery::TestHelpers::Rails::Controller, type: :controller
308
- config.include Sorcery::TestHelpers::Rails::Integration, type: :feature
309
- end
310
- ```
311
-
312
- * If are upgrading to **0.8.2** and use activity_logging feature with
313
- ActiveRecord, you will have to add a new column
314
- `last_login_from_ip_address`
315
- [#465](https://github.com/NoamB/sorcery/issues/465)
316
- * Sinatra support existed until **v0.7.0** (including), but was dropped
317
- later due to being a maintenance nightmare.
318
- * If upgrading from <= **0.6.1 to >= **0.7.0** you need to change
319
- 'username
320
- _attribute_name' to 'username_attribute_names' in initializer.
321
- * If upgrading from <= **v0.5.1** to >= **v0.5.2** you need to explicitly
322
- set your user_class model in the initializer file.
323
-
324
- ```ruby
325
- # This line must come after the 'user config' block.
326
- config.user_class = User
327
- ```
328
-
329
-
330
- ## Contributing to sorcery
331
-
332
- Your feedback is very welcome and will make this gem much much better for you,
333
- me and everyone else. Besides feedback on code, features, suggestions and bug
334
- reports, you may want to actually make an impact on the code. For this:
335
-
336
- * Fork it.
337
- * Fix it.
338
- * Test it.
339
- * Commit it.
340
- * Send me a pull request so I'll... Pull it.
341
-
209
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Sorcery/sorcery.
342
210
 
343
211
  If you feel sorcery has made your life easier, and you would like to express
344
- your thanks via a donation, my paypal email is in the contact details.
212
+ your thanks via a donation, my PayPal email is in the contact details.
345
213
 
346
214
  ## Contact
347
215
 
348
216
  Feel free to ask questions using these contact details:
349
217
 
350
- #### Noam Ben-Ari
351
-
352
- email: nbenari@gmail.com ( also for paypal )
353
-
354
- twitter: @nbenari
355
-
356
- #### Kir Shatrov
357
-
358
- email: shatrov@me.com
359
-
360
- twitter: @Kiiiir
361
-
362
- #### Grzegorz Witek
363
-
364
- email: arnvald.to@gmail.com
365
-
366
- twitter: @arnvald
218
+ - Noam Ben-Ari: [nbenari@gmail.com](mailto:nbenari@gmail.com) (also PayPal), [Twitter](https://twitter.com/nbenari)
219
+ - Kir Shatrov: [shatrov@me.com](mailto:shatrov@me.com), [Twitter](https://twitter.com/Kiiiir)
220
+ - Grzegorz Witek: [arnvald.to@gmail.com](mailto:arnvald.to@gmail.com), [Twitter](https://twitter.com/arnvald)
367
221
 
368
- ## Copyright
222
+ ## License
369
223
 
370
- Copyright (c) 2010-2014 Noam Ben Ari (nbenari@gmail.com). See LICENSE.txt for
371
- further details.
224
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
3
  require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,9 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '~> 4.0.0'
4
-
5
- gem 'mongoid', '~> 4.0.0'
6
3
  gem 'sqlite3', platform: :mri
7
4
  gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
+ gem 'rails', '~> 4.2.0'
8
6
 
9
7
  gemspec path: '..'
@@ -4,16 +4,16 @@ module Sorcery
4
4
  private
5
5
 
6
6
  def sorcery_config_path
7
- "config/initializers/sorcery.rb"
7
+ 'config/initializers/sorcery.rb'
8
8
  end
9
9
 
10
10
  # Either return the model passed in a classified form or return the default "User".
11
11
  def model_class_name
12
- options[:model] ? options[:model].classify : "User"
12
+ options[:model] ? options[:model].classify : 'User'
13
13
  end
14
14
 
15
15
  def model_path
16
- @model_path ||= File.join("app", "models", "#{file_path}.rb")
16
+ @model_path ||= File.join('app', 'models', "#{file_path}.rb")
17
17
  end
18
18
 
19
19
  def file_path
@@ -33,7 +33,7 @@ module Sorcery
33
33
  [namespace.to_s] + [model_class_name]
34
34
  else
35
35
  [model_class_name]
36
- end.join("::")
36
+ end.join('::')
37
37
  end
38
38
  end
39
39
  end
@@ -9,36 +9,35 @@ module Sorcery
9
9
 
10
10
  source_root File.expand_path('../templates', __FILE__)
11
11
 
12
- argument :submodules, :optional => true, :type => :array, :banner => "submodules"
12
+ argument :submodules, optional: true, type: :array, banner: 'submodules'
13
13
 
14
- class_option :model, :optional => true, :type => :string, :banner => "model",
15
- :desc => "Specify the model class name if you will use anything other than 'User'"
14
+ class_option :model, optional: true, type: :string, banner: 'model',
15
+ desc: "Specify the model class name if you will use anything other than 'User'"
16
16
 
17
- class_option :migrations, :optional => true, :type => :boolean, :banner => "migrations",
18
- :desc => "[DEPRECATED] Please use --only-submodules option instead"
19
-
20
- class_option :only_submodules, :optional => true, :type => :boolean, :banner => "only-submodules",
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)"
17
+ class_option :migrations, optional: true, type: :boolean, banner: 'migrations',
18
+ desc: '[DEPRECATED] Please use --only-submodules option instead'
22
19
 
20
+ class_option :only_submodules, optional: true, type: :boolean, banner: 'only-submodules',
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)"
23
22
 
24
23
  def check_deprecated_options
25
24
  if options[:migrations]
26
- warn("[DEPRECATED] `--migrations` option is deprecated, please use `--only-submodules` instead")
25
+ warn('[DEPRECATED] `--migrations` option is deprecated, please use `--only-submodules` instead')
27
26
  end
28
27
  end
29
28
 
30
29
  # Copy the initializer file to config/initializers folder.
31
30
  def copy_initializer_file
32
- template "initializer.rb", sorcery_config_path unless only_submodules?
31
+ template 'initializer.rb', sorcery_config_path unless only_submodules?
33
32
  end
34
33
 
35
34
  def configure_initializer_file
36
35
  # Add submodules to the initializer file.
37
36
  if submodules
38
- submodule_names = submodules.collect{ |submodule| ':' + submodule }
37
+ submodule_names = submodules.collect { |submodule| ':' + submodule }
39
38
 
40
39
  gsub_file sorcery_config_path, /submodules = \[.*\]/ do |str|
41
- current_submodule_names = (str =~ /\[(.*)\]/ ? $1 : '').delete(' ').split(',')
40
+ current_submodule_names = (str =~ /\[(.*)\]/ ? Regexp.last_match(1) : '').delete(' ').split(',')
42
41
  "submodules = [#{(current_submodule_names | submodule_names).join(', ')}]"
43
42
  end
44
43
  end
@@ -54,7 +53,7 @@ module Sorcery
54
53
  end
55
54
 
56
55
  def inject_sorcery_to_model
57
- indents = " " * (namespaced? ? 2 : 1)
56
+ indents = ' ' * (namespaced? ? 2 : 1)
58
57
 
59
58
  inject_into_class(model_path, model_class_name, "#{indents}authenticates_with_sorcery!\n")
60
59
  end
@@ -63,33 +62,40 @@ module Sorcery
63
62
  def copy_migration_files
64
63
  # Copy core migration file in all cases except when you pass --only-submodules.
65
64
  return unless defined?(Sorcery::Generators::InstallGenerator::ActiveRecord)
66
- migration_template "migration/core.rb", "db/migrate/sorcery_core.rb" unless only_submodules?
65
+ migration_template 'migration/core.rb', 'db/migrate/sorcery_core.rb', migration_class_name: migration_class_name unless only_submodules?
67
66
 
68
67
  if submodules
69
68
  submodules.each do |submodule|
70
- unless submodule == "http_basic_auth" || submodule == "session_timeout" || submodule == "core"
71
- migration_template "migration/#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb"
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
72
71
  end
73
72
  end
74
73
  end
75
-
76
74
  end
77
75
 
78
76
  # Define the next_migration_number method (necessary for the migration_template method to work)
79
77
  def self.next_migration_number(dirname)
80
78
  if ActiveRecord::Base.timestamped_migrations
81
79
  sleep 1 # make sure each time we get a different timestamp
82
- Time.new.utc.strftime("%Y%m%d%H%M%S")
80
+ Time.new.utc.strftime('%Y%m%d%H%M%S')
83
81
  else
84
- "%.3d" % (current_migration_number(dirname) + 1)
82
+ '%.3d' % (current_migration_number(dirname) + 1)
85
83
  end
86
84
  end
87
85
 
88
86
  private
87
+
89
88
  def only_submodules?
90
89
  options[:migrations] || options[:only_submodules]
91
90
  end
92
91
 
92
+ def migration_class_name
93
+ if Rails::VERSION::MAJOR >= 5
94
+ "ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
95
+ else
96
+ 'ActiveRecord::Migration'
97
+ end
98
+ end
93
99
  end
94
100
  end
95
101
  end