sorcery 0.7.0 → 0.8.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 (204) hide show
  1. data/.travis.yml +3 -0
  2. data/Gemfile +9 -6
  3. data/Gemfile.lock +106 -75
  4. data/README.rdoc +42 -55
  5. data/Rakefile +32 -7
  6. data/VERSION +1 -1
  7. data/lib/generators/sorcery/USAGE +22 -0
  8. data/lib/generators/sorcery/install_generator.rb +77 -0
  9. data/lib/generators/sorcery/templates/initializer.rb +417 -0
  10. data/lib/generators/sorcery/templates/migration/activity_logging.rb +17 -0
  11. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +13 -0
  12. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/core.rb +2 -2
  13. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/external.rb +1 -1
  14. data/lib/generators/sorcery/templates/migration/remember_me.rb +15 -0
  15. data/lib/generators/sorcery/templates/migration/reset_password.rb +17 -0
  16. data/lib/generators/sorcery/templates/migration/user_activation.rb +17 -0
  17. data/lib/sorcery/controller/submodules/activity_logging.rb +8 -11
  18. data/lib/sorcery/controller/submodules/brute_force_protection.rb +2 -3
  19. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +25 -10
  20. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +20 -5
  21. data/lib/sorcery/controller/submodules/external/providers/github.rb +15 -4
  22. data/lib/sorcery/controller/submodules/external/providers/google.rb +90 -0
  23. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +101 -0
  24. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +91 -0
  25. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +3 -2
  26. data/lib/sorcery/controller/submodules/external/providers/vkontakte.rb +94 -0
  27. data/lib/sorcery/controller/submodules/external.rb +89 -15
  28. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  29. data/lib/sorcery/controller/submodules/remember_me.rb +26 -15
  30. data/lib/sorcery/controller/submodules/session_timeout.rb +3 -3
  31. data/lib/sorcery/controller.rb +55 -46
  32. data/lib/sorcery/crypto_providers/bcrypt.rb +1 -0
  33. data/lib/sorcery/model/adapters/active_record.rb +21 -1
  34. data/lib/sorcery/model/adapters/mongo_mapper.rb +56 -0
  35. data/lib/sorcery/model/adapters/mongoid.rb +23 -4
  36. data/lib/sorcery/model/submodules/activity_logging.rb +4 -4
  37. data/lib/sorcery/model/submodules/brute_force_protection.rb +54 -15
  38. data/lib/sorcery/model/submodules/remember_me.rb +12 -7
  39. data/lib/sorcery/model/submodules/reset_password.rb +27 -11
  40. data/lib/sorcery/model/submodules/user_activation.rb +27 -8
  41. data/lib/sorcery/model/temporary_token.rb +4 -2
  42. data/lib/sorcery/model.rb +78 -47
  43. data/lib/sorcery/railties/tasks.rake +2 -0
  44. data/lib/sorcery.rb +10 -8
  45. data/sorcery.gemspec +107 -228
  46. data/spec/Gemfile +1 -1
  47. data/spec/Gemfile.lock +27 -23
  48. data/spec/README.md +12 -7
  49. data/spec/rails3/Gemfile +3 -3
  50. data/spec/rails3/Gemfile.lock +62 -55
  51. data/spec/rails3/app/controllers/application_controller.rb +85 -2
  52. data/spec/rails3/app/mailers/sorcery_mailer.rb +7 -0
  53. data/spec/rails3/app/views/sorcery_mailer/send_unlock_token_email.text.erb +1 -0
  54. data/spec/rails3/config/environments/in_memory.rb +35 -0
  55. data/spec/rails3/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +2 -0
  56. data/spec/rails3/spec/controller_activity_logging_spec.rb +16 -6
  57. data/spec/rails3/spec/controller_brute_force_protection_spec.rb +25 -3
  58. data/spec/rails3/spec/controller_oauth2_spec.rb +260 -20
  59. data/spec/rails3/spec/controller_oauth_spec.rb +111 -6
  60. data/spec/rails3/spec/controller_session_timeout_spec.rb +4 -4
  61. data/spec/rails3/spec/controller_spec.rb +37 -2
  62. data/spec/rails3/spec/integration_spec.rb +15 -15
  63. data/spec/rails3/spec/spec_helper.rb +0 -2
  64. data/spec/rails3_mongo_mapper/.gitignore +4 -0
  65. data/spec/rails3_mongo_mapper/.rspec +1 -0
  66. data/spec/{sinatra_modular → rails3_mongo_mapper}/Gemfile +6 -5
  67. data/spec/rails3_mongo_mapper/Gemfile.lock +156 -0
  68. data/spec/{sinatra → rails3_mongo_mapper}/Rakefile +3 -3
  69. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +122 -0
  70. data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +2 -0
  71. data/spec/rails3_mongo_mapper/app/models/authentication.rb +6 -0
  72. data/spec/rails3_mongo_mapper/app/models/user.rb +5 -0
  73. data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +14 -0
  74. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +17 -0
  75. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +9 -0
  76. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
  77. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
  78. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
  79. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
  80. data/spec/rails3_mongo_mapper/config/application.rb +51 -0
  81. data/spec/rails3_mongo_mapper/config/boot.rb +13 -0
  82. data/spec/rails3_mongo_mapper/config/environment.rb +5 -0
  83. data/spec/rails3_mongo_mapper/config/environments/development.rb +30 -0
  84. data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
  85. data/spec/rails3_mongo_mapper/config/environments/production.rb +49 -0
  86. data/spec/rails3_mongo_mapper/config/environments/test.rb +35 -0
  87. data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +7 -0
  88. data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +10 -0
  89. data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +5 -0
  90. data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +2 -0
  91. data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +7 -0
  92. data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +8 -0
  93. data/spec/rails3_mongo_mapper/config/locales/en.yml +5 -0
  94. data/spec/rails3_mongo_mapper/config/routes.rb +59 -0
  95. data/spec/rails3_mongo_mapper/config.ru +4 -0
  96. data/spec/rails3_mongo_mapper/db/schema.rb +23 -0
  97. data/spec/rails3_mongo_mapper/db/seeds.rb +7 -0
  98. data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
  99. data/spec/rails3_mongo_mapper/public/404.html +26 -0
  100. data/spec/rails3_mongo_mapper/public/422.html +26 -0
  101. data/spec/rails3_mongo_mapper/public/500.html +26 -0
  102. data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
  103. data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
  104. data/spec/rails3_mongo_mapper/public/javascripts/application.js +2 -0
  105. data/spec/rails3_mongo_mapper/public/javascripts/controls.js +965 -0
  106. data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +974 -0
  107. data/spec/rails3_mongo_mapper/public/javascripts/effects.js +1123 -0
  108. data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +6001 -0
  109. data/spec/rails3_mongo_mapper/public/javascripts/rails.js +175 -0
  110. data/spec/rails3_mongo_mapper/public/robots.txt +5 -0
  111. data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
  112. data/spec/rails3_mongo_mapper/script/rails +6 -0
  113. data/spec/rails3_mongo_mapper/spec/controller_spec.rb +170 -0
  114. data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +27 -0
  115. data/spec/rails3_mongo_mapper/spec/spec_helper.rb +55 -0
  116. data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +9 -0
  117. data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +8 -0
  118. data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +8 -0
  119. data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +8 -0
  120. data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +8 -0
  121. data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +8 -0
  122. data/spec/rails3_mongo_mapper/spec/user_spec.rb +37 -0
  123. data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
  124. data/spec/rails3_mongoid/Gemfile +2 -1
  125. data/spec/rails3_mongoid/Gemfile.lock +47 -42
  126. data/spec/rails3_mongoid/app/controllers/application_controller.rb +19 -0
  127. data/spec/rails3_mongoid/config/mongoid.yml +1 -1
  128. data/spec/rails3_mongoid/script/rails +0 -0
  129. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +105 -0
  130. data/spec/rails3_mongoid/spec/controller_spec.rb +52 -1
  131. data/spec/rails3_mongoid/spec/user_spec.rb +1 -0
  132. data/spec/shared_examples/controller_oauth2_shared_examples.rb +20 -1
  133. data/spec/shared_examples/controller_oauth_shared_examples.rb +18 -0
  134. data/spec/shared_examples/user_activation_shared_examples.rb +72 -42
  135. data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -1
  136. data/spec/shared_examples/user_reset_password_shared_examples.rb +81 -28
  137. data/spec/shared_examples/user_shared_examples.rb +29 -1
  138. data/spec/sorcery_crypto_providers_spec.rb +14 -1
  139. metadata +111 -229
  140. data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +0 -24
  141. data/lib/generators/sorcery_migration/templates/activity_logging.rb +0 -17
  142. data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +0 -11
  143. data/lib/generators/sorcery_migration/templates/remember_me.rb +0 -15
  144. data/lib/generators/sorcery_migration/templates/reset_password.rb +0 -17
  145. data/lib/generators/sorcery_migration/templates/user_activation.rb +0 -17
  146. data/lib/sorcery/controller/adapters/sinatra.rb +0 -115
  147. data/lib/sorcery/initializers/initializer.rb +0 -199
  148. data/lib/sorcery/sinatra.rb +0 -4
  149. data/lib/sorcery/test_helpers/internal/sinatra.rb +0 -74
  150. data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +0 -74
  151. data/lib/sorcery/test_helpers/sinatra.rb +0 -88
  152. data/spec/rails3/Rakefile.unused +0 -7
  153. data/spec/sinatra/Gemfile +0 -15
  154. data/spec/sinatra/Gemfile.lock +0 -115
  155. data/spec/sinatra/authentication.rb +0 -3
  156. data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  157. data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  158. data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  159. data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +0 -16
  160. data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  161. data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  162. data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  163. data/spec/sinatra/filters.rb +0 -27
  164. data/spec/sinatra/modular.rb +0 -157
  165. data/spec/sinatra/myapp.rb +0 -133
  166. data/spec/sinatra/spec/controller_activity_logging_spec.rb +0 -85
  167. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +0 -70
  168. data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +0 -53
  169. data/spec/sinatra/spec/controller_oauth2_spec.rb +0 -96
  170. data/spec/sinatra/spec/controller_oauth_spec.rb +0 -100
  171. data/spec/sinatra/spec/controller_remember_me_spec.rb +0 -64
  172. data/spec/sinatra/spec/controller_session_timeout_spec.rb +0 -57
  173. data/spec/sinatra/spec/controller_spec.rb +0 -127
  174. data/spec/sinatra/spec/spec_helper.rb +0 -45
  175. data/spec/sinatra/user.rb +0 -6
  176. data/spec/sinatra/views/test_login.erb +0 -4
  177. data/spec/sinatra_modular/Gemfile.lock +0 -115
  178. data/spec/sinatra_modular/Rakefile +0 -11
  179. data/spec/sinatra_modular/authentication.rb +0 -3
  180. data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  181. data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  182. data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  183. data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +0 -16
  184. data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  185. data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  186. data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  187. data/spec/sinatra_modular/filters.rb +0 -27
  188. data/spec/sinatra_modular/modular.rb +0 -157
  189. data/spec/sinatra_modular/myapp.rb +0 -133
  190. data/spec/sinatra_modular/sorcery_mailer.rb +0 -25
  191. data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +0 -85
  192. data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +0 -70
  193. data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +0 -53
  194. data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +0 -96
  195. data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +0 -100
  196. data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +0 -64
  197. data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +0 -57
  198. data/spec/sinatra_modular/spec_modular/controller_spec.rb +0 -116
  199. data/spec/sinatra_modular/spec_modular/spec.opts +0 -2
  200. data/spec/sinatra_modular/spec_modular/spec_helper.rb +0 -51
  201. data/spec/sinatra_modular/user.rb +0 -6
  202. data/spec/sinatra_modular/views/test_login.erb +0 -4
  203. /data/spec/{sinatra → rails3_mongo_mapper/app/mailers}/sorcery_mailer.rb +0 -0
  204. /data/spec/{sinatra → rails3_mongo_mapper}/spec/spec.opts +0 -0
@@ -0,0 +1,417 @@
1
+ # The first thing you need to configure is which modules you need in your app.
2
+ # The default is nothing which will include only core features (password encryption, login/logout).
3
+ # Available submodules are: :user_activation, :http_basic_auth, :remember_me,
4
+ # :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :external
5
+ Rails.application.config.sorcery.submodules = []
6
+
7
+ # Here you can configure each submodule's features.
8
+ Rails.application.config.sorcery.configure do |config|
9
+ # -- core --
10
+ # What controller action to call for non-authenticated users. You can also
11
+ # override the 'not_authenticated' method of course.
12
+ # Default: `:not_authenticated`
13
+ #
14
+ # config.not_authenticated_action =
15
+
16
+
17
+ # When a non logged in user tries to enter a page that requires login, save
18
+ # the URL he wanted to reach, and send him there after login, using 'redirect_back_or_to'.
19
+ # Default: `true`
20
+ #
21
+ # config.save_return_to_url =
22
+
23
+
24
+ # Set domain option for cookies; Useful for remember_me submodule.
25
+ # Default: `nil`
26
+ #
27
+ # config.cookie_domain =
28
+
29
+
30
+ # -- remember_me --
31
+ # allow the remember_me cookie to settable through AJAX
32
+ # Default: `true`
33
+ #
34
+ # user.remember_me_httponly =
35
+
36
+
37
+ # -- session timeout --
38
+ # How long in seconds to keep the session alive.
39
+ # Default: `3600`
40
+ #
41
+ # config.session_timeout =
42
+
43
+
44
+ # Use the last action as the beginning of session timeout.
45
+ # Default: `false`
46
+ #
47
+ # config.session_timeout_from_last_action =
48
+
49
+
50
+ # -- http_basic_auth --
51
+ # What realm to display for which controller name. For example {"My App" => "Application"}
52
+ # Default: `{"application" => "Application"}`
53
+ #
54
+ # config.controller_to_realm_map =
55
+
56
+
57
+ # -- activity logging --
58
+ # will register the time of last user login, every login.
59
+ # Default: `true`
60
+ #
61
+ # config.register_login_time =
62
+
63
+
64
+ # will register the time of last user logout, every logout.
65
+ # Default: `true`
66
+ #
67
+ # config.register_logout_time =
68
+
69
+
70
+ # will register the time of last user action, every action.
71
+ # Default: `true`
72
+ #
73
+ # config.register_last_activity_time =
74
+
75
+
76
+ # -- external --
77
+ # What providers are supported by this app, i.e. [:twitter, :facebook, :github, :google, :liveid] .
78
+ # Default: `[]`
79
+ #
80
+ # config.external_providers =
81
+
82
+
83
+ # You can change it by your local ca_file. i.e. '/etc/pki/tls/certs/ca-bundle.crt'
84
+ # Path to ca_file. By default use a internal ca-bundle.crt.
85
+ # Default: `'path/to/ca_file'`
86
+ #
87
+ # config.ca_file =
88
+
89
+
90
+ # For information about LinkedIn API:
91
+ # - user info fields go to https://developer.linkedin.com/documents/profile-fields
92
+ # - access permissions go to https://developer.linkedin.com/documents/authentication#granting
93
+ #
94
+ # config.linkedin.key = ""
95
+ # config.linkedin.secret = ""
96
+ # config.linkedin.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=linkedin"
97
+ # config.linkedin.user_info_fields = ['first-name', 'last-name']
98
+ # config.linkedin.user_info_mapping = {first_name: "firstName", last_name: "lastName"}
99
+ # config.linkedin.access_permissions = ['r_basicprofile']
100
+ #
101
+ # Twitter wil not accept any requests nor redirect uri containing localhost,
102
+ # make sure you use 0.0.0.0:3000 to access your app in development
103
+ #
104
+ # config.twitter.key = ""
105
+ # config.twitter.secret = ""
106
+ # config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter"
107
+ # config.twitter.user_info_mapping = {:email => "screen_name"}
108
+ #
109
+ # config.facebook.key = ""
110
+ # config.facebook.secret = ""
111
+ # config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
112
+ # config.facebook.user_info_mapping = {:email => "name"}
113
+ # config.facebook.access_permissions = ["email", "publish_stream"]
114
+ #
115
+ # config.github.key = ""
116
+ # config.github.secret = ""
117
+ # config.github.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=github"
118
+ # config.github.user_info_mapping = {:email => "name"}
119
+ #
120
+ # config.google.key = ""
121
+ # config.google.secret = ""
122
+ # config.google.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=google"
123
+ # config.google.user_info_mapping = {:email => "email", :username => "name"}
124
+ #
125
+ # To use liveid in development mode you have to replace mydomain.com with
126
+ # a valid domain even in development. To use a valid domain in development
127
+ # simply add your domain in your /etc/hosts file in front of 127.0.0.1
128
+ #
129
+ # config.liveid.key = ""
130
+ # config.liveid.secret = ""
131
+ # config.liveid.callback_url = "http://mydomain.com:3000/oauth/callback?provider=liveid"
132
+ # config.liveid.user_info_mapping = {:username => "name"}
133
+
134
+
135
+ # --- user config ---
136
+ config.user_config do |user|
137
+ # -- core --
138
+ # specify username attributes, for example: [:username, :email].
139
+ # Default: `[:username]`
140
+ #
141
+ # user.username_attribute_names =
142
+
143
+
144
+ # change *virtual* password attribute, the one which is used until an encrypted one is generated.
145
+ # Default: `:password`
146
+ #
147
+ # user.password_attribute_name =
148
+
149
+
150
+ # downcase the username before trying to authenticate, default is false
151
+ # Default: `false`
152
+ #
153
+ # user.downcase_username_before_authenticating =
154
+
155
+
156
+ # change default email attribute.
157
+ # Default: `:email`
158
+ #
159
+ # user.email_attribute_name =
160
+
161
+
162
+ # change default crypted_password attribute.
163
+ # Default: `:crypted_password`
164
+ #
165
+ # user.crypted_password_attribute_name =
166
+
167
+
168
+ # what pattern to use to join the password with the salt
169
+ # Default: `""`
170
+ #
171
+ # user.salt_join_token =
172
+
173
+
174
+ # change default salt attribute.
175
+ # Default: `:salt`
176
+ #
177
+ # user.salt_attribute_name =
178
+
179
+
180
+ # how many times to apply encryption to the password.
181
+ # Default: `nil`
182
+ #
183
+ # user.stretches =
184
+
185
+
186
+ # encryption key used to encrypt reversible encryptions such as AES256.
187
+ # WARNING: If used for users' passwords, changing this key will leave passwords undecryptable!
188
+ # Default: `nil`
189
+ #
190
+ # user.encryption_key =
191
+
192
+
193
+ # use an external encryption class.
194
+ # Default: `nil`
195
+ #
196
+ # user.custom_encryption_provider =
197
+
198
+
199
+ # encryption algorithm name. See 'encryption_algorithm=' for available options.
200
+ # Default: `:bcrypt`
201
+ #
202
+ # user.encryption_algorithm =
203
+
204
+
205
+ # make this configuration inheritable for subclasses. Useful for ActiveRecord's STI.
206
+ # Default: `false`
207
+ #
208
+ # user.subclasses_inherit_config =
209
+
210
+
211
+ # -- user_activation --
212
+ # the attribute name to hold activation state (active/pending).
213
+ # Default: `:activation_state`
214
+ #
215
+ # user.activation_state_attribute_name =
216
+
217
+
218
+ # the attribute name to hold activation code (sent by email).
219
+ # Default: `:activation_token`
220
+ #
221
+ # user.activation_token_attribute_name =
222
+
223
+
224
+ # the attribute name to hold activation code expiration date.
225
+ # Default: `:activation_token_expires_at`
226
+ #
227
+ # user.activation_token_expires_at_attribute_name =
228
+
229
+
230
+ # how many seconds before the activation code expires. nil for never expires.
231
+ # Default: `nil`
232
+ #
233
+ # user.activation_token_expiration_period =
234
+
235
+
236
+ # your mailer class. Required.
237
+ # Default: `nil`
238
+ #
239
+ # user.user_activation_mailer =
240
+
241
+
242
+ # when true sorcery will not automatically
243
+ # email activation details and allow you to
244
+ # manually handle how and when email is sent.
245
+ # Default: `false`
246
+ #
247
+ # user.activation_mailer_disabled =
248
+
249
+
250
+ # activation needed email method on your mailer class.
251
+ # Default: `:activation_needed_email`
252
+ #
253
+ # user.activation_needed_email_method_name =
254
+
255
+
256
+ # activation success email method on your mailer class.
257
+ # Default: `:activation_success_email`
258
+ #
259
+ # user.activation_success_email_method_name =
260
+
261
+
262
+ # do you want to prevent or allow users that did not activate by email to login?
263
+ # Default: `true`
264
+ #
265
+ # user.prevent_non_active_users_to_login =
266
+
267
+
268
+ # -- reset_password --
269
+ # reset password code attribute name.
270
+ # Default: `:reset_password_token`
271
+ #
272
+ # user.reset_password_token_attribute_name =
273
+
274
+
275
+ # expires at attribute name.
276
+ # Default: `:reset_password_token_expires_at`
277
+ #
278
+ # user.reset_password_token_expires_at_attribute_name =
279
+
280
+
281
+ # when was email sent, used for hammering protection.
282
+ # Default: `:reset_password_email_sent_at`
283
+ #
284
+ # user.reset_password_email_sent_at_attribute_name =
285
+
286
+
287
+ # mailer class. Needed.
288
+ # Default: `nil`
289
+ #
290
+ # user.reset_password_mailer =
291
+
292
+
293
+ # reset password email method on your mailer class.
294
+ # Default: `:reset_password_email`
295
+ #
296
+ # user.reset_password_email_method_name =
297
+
298
+
299
+ # when true sorcery will not automatically
300
+ # email password reset details and allow you to
301
+ # manually handle how and when email is sent
302
+ # Default: `false`
303
+ #
304
+ # user.reset_password_mailer_disabled =
305
+
306
+
307
+ # how many seconds before the reset request expires. nil for never expires.
308
+ # Default: `nil`
309
+ #
310
+ # user.reset_password_expiration_period =
311
+
312
+
313
+ # hammering protection, how long to wait before allowing another email to be sent.
314
+ # Default: `5 * 60`
315
+ #
316
+ # user.reset_password_time_between_emails =
317
+
318
+
319
+ # -- brute_force_protection --
320
+ # Failed logins attribute name.
321
+ # Default: `:failed_logins_count`
322
+ #
323
+ # user.failed_logins_count_attribute_name =
324
+
325
+
326
+ # This field indicates whether user is banned and when it will be active again.
327
+ # Default: `:lock_expires_at`
328
+ #
329
+ # user.lock_expires_at_attribute_name =
330
+
331
+
332
+ # How many failed logins allowed.
333
+ # Default: `50`
334
+ #
335
+ # user.consecutive_login_retries_amount_limit =
336
+
337
+
338
+ # How long the user should be banned. in seconds. 0 for permanent.
339
+ # Default: `60 * 60`
340
+ #
341
+ # user.login_lock_time_period =
342
+
343
+ # Unlock token attribute name
344
+ # Default: `:unlock_token`
345
+ #
346
+ # user.unlock_token_attribute_name =
347
+
348
+ # Unlock token mailer method
349
+ # Default: `:send_unlock_token_email`
350
+ #
351
+ # user.unlock_token_email_method_name =
352
+
353
+ # when true sorcery will not automatically
354
+ # send email with unlock token
355
+ # Default: `false`
356
+ #
357
+ # user.unlock_token_mailer_disabled = true
358
+
359
+ # Unlock token mailer class
360
+ # Default: `nil`
361
+ #
362
+ # user.unlock_token_mailer = UserMailer
363
+
364
+ # -- activity logging --
365
+ # Last login attribute name.
366
+ # Default: `:last_login_at`
367
+ #
368
+ # user.last_login_at_attribute_name =
369
+
370
+
371
+ # Last logout attribute name.
372
+ # Default: `:last_logout_at`
373
+ #
374
+ # user.last_logout_at_attribute_name =
375
+
376
+
377
+ # Last activity attribute name.
378
+ # Default: `:last_activity_at`
379
+ #
380
+ # user.last_activity_at_attribute_name =
381
+
382
+
383
+ # How long since last activity is he user defined logged out?
384
+ # Default: `10 * 60`
385
+ #
386
+ # user.activity_timeout =
387
+
388
+
389
+ # -- external --
390
+ # Class which holds the various external provider data for this user.
391
+ # Default: `nil`
392
+ #
393
+ # user.authentications_class =
394
+
395
+
396
+ # User's identifier in authentications class.
397
+ # Default: `:user_id`
398
+ #
399
+ # user.authentications_user_id_attribute_name =
400
+
401
+
402
+ # Provider's identifier in authentications class.
403
+ # Default: `:provider`
404
+ #
405
+ # user.provider_attribute_name =
406
+
407
+
408
+ # User's external unique identifier in authentications class.
409
+ # Default: `:uid`
410
+ #
411
+ # user.provider_uid_attribute_name =
412
+ end
413
+
414
+ # This line must come after the 'user config' block.
415
+ # Define which model authenticates with sorcery.
416
+ config.user_class = "<%= model_class_name %>"
417
+ end
@@ -0,0 +1,17 @@
1
+ class SorceryActivityLogging < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :<%= model_class_name.tableize %>, :last_login_at, :datetime, :default => nil
4
+ add_column :<%= model_class_name.tableize %>, :last_logout_at, :datetime, :default => nil
5
+ add_column :<%= model_class_name.tableize %>, :last_activity_at, :datetime, :default => nil
6
+
7
+ add_index :<%= model_class_name.tableize %>, [:last_logout_at, :last_activity_at]
8
+ end
9
+
10
+ def self.down
11
+ remove_index :<%= model_class_name.tableize %>, [:last_logout_at, :last_activity_at]
12
+
13
+ remove_column :<%= model_class_name.tableize %>, :last_activity_at
14
+ remove_column :<%= model_class_name.tableize %>, :last_logout_at
15
+ remove_column :<%= model_class_name.tableize %>, :last_login_at
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ class SorceryBruteForceProtection < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :<%= model_class_name.tableize %>, :failed_logins_count, :integer, :default => 0
4
+ add_column :<%= model_class_name.tableize %>, :lock_expires_at, :datetime, :default => nil
5
+ add_column :<%= model_class_name.tableize %>, :unlock_token, :string, :default => nil
6
+ end
7
+
8
+ def self.down
9
+ remove_column :<%= model_class_name.tableize %>, :lock_expires_at
10
+ remove_column :<%= model_class_name.tableize %>, :failed_logins_count
11
+ remove_column :<%= model_class_name.tableize %>, :unlock_token
12
+ end
13
+ end
@@ -1,6 +1,6 @@
1
1
  class SorceryCore < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :users do |t|
3
+ create_table :<%= model_class_name.tableize %> do |t|
4
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
@@ -11,6 +11,6 @@ class SorceryCore < ActiveRecord::Migration
11
11
  end
12
12
 
13
13
  def self.down
14
- drop_table :users
14
+ drop_table :<%= model_class_name.tableize %>
15
15
  end
16
16
  end
@@ -1,7 +1,7 @@
1
1
  class SorceryExternal < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :authentications do |t|
4
- t.integer :user_id, :null => false
4
+ t.integer :<%= model_class_name.tableize.singularize %>_id, :null => false
5
5
  t.string :provider, :uid, :null => false
6
6
 
7
7
  t.timestamps
@@ -0,0 +1,15 @@
1
+ class SorceryRememberMe < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :<%= model_class_name.tableize %>, :remember_me_token, :string, :default => nil
4
+ add_column :<%= model_class_name.tableize %>, :remember_me_token_expires_at, :datetime, :default => nil
5
+
6
+ add_index :<%= model_class_name.tableize %>, :remember_me_token
7
+ end
8
+
9
+ def self.down
10
+ remove_index :<%= model_class_name.tableize %>, :remember_me_token
11
+
12
+ remove_column :<%= model_class_name.tableize %>, :remember_me_token_expires_at
13
+ remove_column :<%= model_class_name.tableize %>, :remember_me_token
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ class SorceryResetPassword < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :<%= model_class_name.tableize %>, :reset_password_token, :string, :default => nil
4
+ add_column :<%= model_class_name.tableize %>, :reset_password_token_expires_at, :datetime, :default => nil
5
+ add_column :<%= model_class_name.tableize %>, :reset_password_email_sent_at, :datetime, :default => nil
6
+
7
+ add_index :<%= model_class_name.tableize %>, :reset_password_token
8
+ end
9
+
10
+ def self.down
11
+ remove_index :<%= model_class_name.tableize %>, :reset_password_token
12
+
13
+ remove_column :<%= model_class_name.tableize %>, :reset_password_email_sent_at
14
+ remove_column :<%= model_class_name.tableize %>, :reset_password_token_expires_at
15
+ remove_column :<%= model_class_name.tableize %>, :reset_password_token
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class SorceryUserActivation < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :<%= model_class_name.tableize %>, :activation_state, :string, :default => nil
4
+ add_column :<%= model_class_name.tableize %>, :activation_token, :string, :default => nil
5
+ add_column :<%= model_class_name.tableize %>, :activation_token_expires_at, :datetime, :default => nil
6
+
7
+ add_index :<%= model_class_name.tableize %>, :activation_token
8
+ end
9
+
10
+ def self.down
11
+ remove_index :<%= model_class_name.tableize %>, :activation_token
12
+
13
+ remove_column :<%= model_class_name.tableize %>, :activation_token_expires_at
14
+ remove_column :<%= model_class_name.tableize %>, :activation_token
15
+ remove_column :<%= model_class_name.tableize %>, :activation_state
16
+ end
17
+ end
@@ -21,15 +21,15 @@ module Sorcery
21
21
  attr_accessor :register_last_activity_time
22
22
 
23
23
  def merge_activity_logging_defaults!
24
- @defaults.merge!(:@register_login_time => true,
25
- :@register_logout_time => true,
24
+ @defaults.merge!(:@register_login_time => true,
25
+ :@register_logout_time => true,
26
26
  :@register_last_activity_time => true)
27
27
  end
28
28
  end
29
29
  merge_activity_logging_defaults!
30
30
  end
31
- Config.after_login << :register_login_time_to_db
32
- Config.before_logout << :register_logout_time_to_db
31
+ Config.after_login << :register_login_time_to_db
32
+ Config.before_logout << :register_logout_time_to_db
33
33
  base.after_filter :register_last_activity_time_to_db
34
34
  end
35
35
 
@@ -52,16 +52,14 @@ module Sorcery
52
52
  # This runs as a hook just after a successful login.
53
53
  def register_login_time_to_db(user, credentials)
54
54
  return unless Config.register_login_time
55
- user.send(:"#{user.sorcery_config.last_login_at_attribute_name}=", Time.now.utc.to_s(:db))
56
- user.save!(:validate => false)
55
+ user.update_single_attribute(user.sorcery_config.last_login_at_attribute_name, Time.now.in_time_zone)
57
56
  end
58
57
 
59
58
  # registers last logout time on every logout.
60
59
  # This runs as a hook just before a logout.
61
60
  def register_logout_time_to_db(user)
62
61
  return unless Config.register_logout_time
63
- user.send(:"#{user.sorcery_config.last_logout_at_attribute_name}=", Time.now.utc.to_s(:db))
64
- user.save!(:validate => false)
62
+ user.update_single_attribute(user.sorcery_config.last_logout_at_attribute_name, Time.now.in_time_zone)
65
63
  end
66
64
 
67
65
  # Updates last activity time on every request.
@@ -69,11 +67,10 @@ module Sorcery
69
67
  def register_last_activity_time_to_db
70
68
  return unless Config.register_last_activity_time
71
69
  return unless logged_in?
72
- current_user.send(:"#{current_user.sorcery_config.last_activity_at_attribute_name}=", Time.now.utc.to_s(:db))
73
- current_user.save!(:validate => false)
70
+ current_user.update_single_attribute(current_user.sorcery_config.last_activity_at_attribute_name, Time.now.in_time_zone)
74
71
  end
75
72
  end
76
73
  end
77
74
  end
78
75
  end
79
- end
76
+ end
@@ -29,11 +29,10 @@ 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.send(:"#{user_class.sorcery_config.failed_logins_count_attribute_name}=", 0)
33
- user.save!
32
+ user.update_many_attributes(user_class.sorcery_config.failed_logins_count_attribute_name => 0)
34
33
  end
35
34
  end
36
35
  end
37
36
  end
38
37
  end
39
- end
38
+ end
@@ -8,19 +8,34 @@ module Sorcery
8
8
  def oauth_version
9
9
  "2.0"
10
10
  end
11
-
11
+
12
12
  def authorize_url(options = {})
13
+ client = build_client(options)
14
+ client.auth_code.authorize_url(
15
+ :redirect_uri => @callback_url,
16
+ :scope => @scope,
17
+ :display => @display
18
+ )
19
+ end
20
+
21
+ def get_access_token(args, options = {})
22
+ client = build_client(options)
23
+ client.auth_code.get_token(
24
+ args[:code],
25
+ { :redirect_uri => @callback_url, :parse => options.delete(:parse) }, options
26
+ )
27
+ end
28
+
29
+ def build_client(options = {})
13
30
  defaults = {
14
- :site => @site,
15
- :ssl => { :ca_file => Config.ca_file }
31
+ :site => @site,
32
+ :ssl => { :ca_file => Config.ca_file }
16
33
  }
17
- client = ::OAuth2::Client.new(@key, @secret, defaults.merge!(options))
18
- client.authorize_url(:redirect_uri => @callback_url, :scope => @scope)
19
- end
20
-
21
- def get_access_token(args)
22
- client = ::OAuth2::Client.new(@key, @secret, :site => @site, :ssl => { :ca_file => Config.ca_file })
23
- client.get_token(args[:code], :redirect_uri => @callback_url)
34
+ ::OAuth2::Client.new(
35
+ @key,
36
+ @secret,
37
+ defaults.merge!(options)
38
+ )
24
39
  end
25
40
  end
26
41
  end