sorcery 0.8.1 → 0.9.1

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 (353) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +56 -0
  3. data/.travis.yml +130 -1
  4. data/CHANGELOG.md +279 -0
  5. data/Gemfile +18 -23
  6. data/README.md +372 -0
  7. data/Rakefile +3 -78
  8. data/gemfiles/active_record-rails40.gemfile +7 -0
  9. data/gemfiles/active_record-rails41.gemfile +7 -0
  10. data/gemfiles/mongo_mapper-rails40.gemfile +9 -0
  11. data/gemfiles/mongo_mapper-rails41.gemfile +9 -0
  12. data/gemfiles/mongoid-rails40.gemfile +9 -0
  13. data/gemfiles/mongoid-rails41.gemfile +9 -0
  14. data/gemfiles/mongoid3-rails32.gemfile +9 -0
  15. data/lib/generators/sorcery/USAGE +1 -1
  16. data/lib/generators/sorcery/helpers.rb +40 -0
  17. data/lib/generators/sorcery/install_generator.rb +38 -20
  18. data/lib/generators/sorcery/templates/initializer.rb +53 -16
  19. data/lib/generators/sorcery/templates/migration/activity_logging.rb +3 -10
  20. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -7
  21. data/lib/generators/sorcery/templates/migration/core.rb +5 -8
  22. data/lib/generators/sorcery/templates/migration/external.rb +3 -5
  23. data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -9
  24. data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -10
  25. data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -10
  26. data/lib/sorcery/adapters/active_record_adapter.rb +120 -0
  27. data/lib/sorcery/adapters/base_adapter.rb +30 -0
  28. data/lib/sorcery/adapters/data_mapper_adapter.rb +176 -0
  29. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +110 -0
  30. data/lib/sorcery/adapters/mongoid_adapter.rb +97 -0
  31. data/lib/sorcery/controller/config.rb +65 -0
  32. data/lib/sorcery/controller/submodules/activity_logging.rb +27 -21
  33. data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
  34. data/lib/sorcery/controller/submodules/external.rb +107 -75
  35. data/lib/sorcery/controller/submodules/remember_me.rb +5 -5
  36. data/lib/sorcery/controller/submodules/session_timeout.rb +11 -7
  37. data/lib/sorcery/controller.rb +27 -76
  38. data/lib/sorcery/model/config.rb +96 -0
  39. data/lib/sorcery/model/submodules/activity_logging.rb +32 -12
  40. data/lib/sorcery/model/submodules/brute_force_protection.rb +36 -36
  41. data/lib/sorcery/model/submodules/external.rb +53 -9
  42. data/lib/sorcery/model/submodules/remember_me.rb +15 -19
  43. data/lib/sorcery/model/submodules/reset_password.rb +36 -33
  44. data/lib/sorcery/model/submodules/user_activation.rb +51 -48
  45. data/lib/sorcery/model/temporary_token.rb +4 -4
  46. data/lib/sorcery/model.rb +85 -175
  47. data/lib/sorcery/protocols/oauth.rb +42 -0
  48. data/lib/sorcery/protocols/oauth2.rb +47 -0
  49. data/lib/sorcery/providers/base.rb +38 -0
  50. data/lib/sorcery/providers/facebook.rb +74 -0
  51. data/lib/sorcery/providers/github.rb +60 -0
  52. data/lib/sorcery/providers/google.rb +51 -0
  53. data/lib/sorcery/providers/heroku.rb +57 -0
  54. data/lib/sorcery/providers/jira.rb +77 -0
  55. data/lib/sorcery/providers/linkedin.rb +66 -0
  56. data/lib/sorcery/providers/liveid.rb +53 -0
  57. data/lib/sorcery/providers/salesforce.rb +50 -0
  58. data/lib/sorcery/providers/twitter.rb +59 -0
  59. data/lib/sorcery/providers/vk.rb +63 -0
  60. data/lib/sorcery/providers/xing.rb +64 -0
  61. data/lib/sorcery/railties/tasks.rake +1 -7
  62. data/lib/sorcery/test_helpers/internal/rails.rb +17 -6
  63. data/lib/sorcery/test_helpers/internal.rb +27 -6
  64. data/lib/sorcery/test_helpers/rails/controller.rb +21 -0
  65. data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
  66. data/lib/sorcery/version.rb +3 -0
  67. data/lib/sorcery.rb +83 -57
  68. data/sorcery.gemspec +24 -363
  69. data/spec/active_record/user_activation_spec.rb +18 -0
  70. data/spec/active_record/user_activity_logging_spec.rb +17 -0
  71. data/spec/{rails3/spec → active_record}/user_brute_force_protection_spec.rb +6 -5
  72. data/spec/{rails3/spec → active_record}/user_oauth_spec.rb +6 -5
  73. data/spec/{rails3/spec → active_record}/user_remember_me_spec.rb +5 -4
  74. data/spec/{rails3/spec → active_record}/user_reset_password_spec.rb +7 -7
  75. data/spec/active_record/user_spec.rb +37 -0
  76. data/spec/controllers/controller_activity_logging_spec.rb +124 -0
  77. data/spec/controllers/controller_brute_force_protection_spec.rb +43 -0
  78. data/spec/controllers/controller_http_basic_auth_spec.rb +68 -0
  79. data/spec/controllers/controller_oauth2_spec.rb +429 -0
  80. data/spec/controllers/controller_oauth_spec.rb +240 -0
  81. data/spec/controllers/controller_remember_me_spec.rb +117 -0
  82. data/spec/controllers/controller_session_timeout_spec.rb +80 -0
  83. data/spec/controllers/controller_spec.rb +218 -0
  84. data/spec/data_mapper/user_activation_spec.rb +10 -0
  85. data/spec/data_mapper/user_activity_logging_spec.rb +14 -0
  86. data/spec/data_mapper/user_brute_force_protection_spec.rb +9 -0
  87. data/spec/data_mapper/user_oauth_spec.rb +9 -0
  88. data/spec/data_mapper/user_remember_me_spec.rb +8 -0
  89. data/spec/data_mapper/user_reset_password_spec.rb +8 -0
  90. data/spec/data_mapper/user_spec.rb +27 -0
  91. data/spec/mongo_mapper/user_activation_spec.rb +9 -0
  92. data/spec/mongo_mapper/user_activity_logging_spec.rb +8 -0
  93. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +8 -0
  94. data/spec/mongo_mapper/user_oauth_spec.rb +8 -0
  95. data/spec/mongo_mapper/user_remember_me_spec.rb +8 -0
  96. data/spec/mongo_mapper/user_reset_password_spec.rb +8 -0
  97. data/spec/mongo_mapper/user_spec.rb +37 -0
  98. data/spec/mongoid/user_activation_spec.rb +9 -0
  99. data/spec/mongoid/user_activity_logging_spec.rb +8 -0
  100. data/spec/mongoid/user_brute_force_protection_spec.rb +8 -0
  101. data/spec/mongoid/user_oauth_spec.rb +8 -0
  102. data/spec/mongoid/user_remember_me_spec.rb +8 -0
  103. data/spec/mongoid/user_reset_password_spec.rb +8 -0
  104. data/spec/mongoid/user_spec.rb +51 -0
  105. data/spec/orm/active_record.rb +21 -0
  106. data/spec/orm/data_mapper.rb +48 -0
  107. data/spec/orm/mongo_mapper.rb +10 -0
  108. data/spec/orm/mongoid.rb +22 -0
  109. data/spec/{rails3/app/models → rails_app/app/active_record}/user.rb +1 -2
  110. data/spec/rails_app/app/active_record/user_provider.rb +3 -0
  111. data/spec/rails_app/app/controllers/sorcery_controller.rb +285 -0
  112. data/spec/rails_app/app/data_mapper/authentication.rb +8 -0
  113. data/spec/rails_app/app/data_mapper/user.rb +7 -0
  114. data/spec/{rails3_mongo_mapper/app/models → rails_app/app/mongo_mapper}/user.rb +2 -0
  115. data/spec/{rails3_mongoid/app/models → rails_app/app/mongoid}/user.rb +2 -0
  116. data/spec/rails_app/app/views/sorcery_mailer/send_unlock_token_email.text.erb +1 -0
  117. data/spec/{rails3_mongo_mapper → rails_app}/config/application.rb +13 -8
  118. data/spec/rails_app/config/boot.rb +4 -0
  119. data/spec/rails_app/config/database.yml +22 -0
  120. data/spec/{rails3_mongo_mapper → rails_app}/config/environments/test.rb +2 -0
  121. data/spec/{rails3_mongoid → rails_app}/config/initializers/session_store.rb +4 -0
  122. data/spec/rails_app/config/routes.rb +51 -0
  123. data/spec/{rails3_mongo_mapper → rails_app}/config.ru +1 -1
  124. data/spec/{rails3 → rails_app}/db/migrate/activation/20101224223622_add_activation_to_users.rb +3 -3
  125. data/spec/{rails3 → rails_app}/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +2 -0
  126. data/spec/{rails3 → rails_app}/db/migrate/core/20101224223620_create_users.rb +2 -2
  127. data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +22 -0
  128. data/spec/rails_app/log/development.log +1791 -0
  129. data/spec/shared_examples/user_activation_shared_examples.rb +137 -98
  130. data/spec/shared_examples/user_activity_logging_shared_examples.rb +86 -13
  131. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +140 -21
  132. data/spec/shared_examples/user_oauth_shared_examples.rb +21 -16
  133. data/spec/shared_examples/user_remember_me_shared_examples.rb +36 -24
  134. data/spec/shared_examples/user_reset_password_shared_examples.rb +163 -130
  135. data/spec/shared_examples/user_shared_examples.rb +370 -195
  136. data/spec/sorcery_crypto_providers_spec.rb +74 -72
  137. data/spec/spec_helper.rb +32 -4
  138. metadata +259 -425
  139. data/Gemfile.lock +0 -192
  140. data/README.rdoc +0 -261
  141. data/VERSION +0 -1
  142. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -35
  143. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -45
  144. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -97
  145. data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -91
  146. data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -90
  147. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -101
  148. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -91
  149. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -92
  150. data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -99
  151. data/lib/sorcery/model/adapters/active_record.rb +0 -49
  152. data/lib/sorcery/model/adapters/mongo_mapper.rb +0 -56
  153. data/lib/sorcery/model/adapters/mongoid.rb +0 -88
  154. data/lib/sorcery/test_helpers/rails.rb +0 -16
  155. data/lib/sorcery/test_helpers.rb +0 -5
  156. data/spec/Gemfile +0 -12
  157. data/spec/Gemfile.lock +0 -129
  158. data/spec/README.md +0 -31
  159. data/spec/Rakefile +0 -12
  160. data/spec/rails3/.gitignore +0 -4
  161. data/spec/rails3/.rspec +0 -1
  162. data/spec/rails3/Gemfile +0 -15
  163. data/spec/rails3/Gemfile.lock +0 -162
  164. data/spec/rails3/README +0 -256
  165. data/spec/rails3/Rakefile +0 -11
  166. data/spec/rails3/app/controllers/application_controller.rb +0 -208
  167. data/spec/rails3/app/views/sorcery_mailer/send_unlock_token_email.text.erb +0 -1
  168. data/spec/rails3/config/application.rb +0 -46
  169. data/spec/rails3/config/boot.rb +0 -13
  170. data/spec/rails3/config/database.yml +0 -27
  171. data/spec/rails3/config/environments/development.rb +0 -26
  172. data/spec/rails3/config/environments/in_memory.rb +0 -35
  173. data/spec/rails3/config/environments/production.rb +0 -49
  174. data/spec/rails3/config/environments/test.rb +0 -35
  175. data/spec/rails3/config/initializers/session_store.rb +0 -8
  176. data/spec/rails3/config/routes.rb +0 -59
  177. data/spec/rails3/config.ru +0 -4
  178. data/spec/rails3/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  179. data/spec/rails3/lib/tasks/.gitkeep +0 -0
  180. data/spec/rails3/public/404.html +0 -26
  181. data/spec/rails3/public/422.html +0 -26
  182. data/spec/rails3/public/500.html +0 -26
  183. data/spec/rails3/public/favicon.ico +0 -0
  184. data/spec/rails3/public/images/rails.png +0 -0
  185. data/spec/rails3/public/javascripts/application.js +0 -2
  186. data/spec/rails3/public/javascripts/controls.js +0 -965
  187. data/spec/rails3/public/javascripts/dragdrop.js +0 -974
  188. data/spec/rails3/public/javascripts/effects.js +0 -1123
  189. data/spec/rails3/public/javascripts/prototype.js +0 -6001
  190. data/spec/rails3/public/javascripts/rails.js +0 -175
  191. data/spec/rails3/public/robots.txt +0 -5
  192. data/spec/rails3/public/stylesheets/.gitkeep +0 -0
  193. data/spec/rails3/script/rails +0 -6
  194. data/spec/rails3/spec/controller_activity_logging_spec.rb +0 -115
  195. data/spec/rails3/spec/controller_brute_force_protection_spec.rb +0 -88
  196. data/spec/rails3/spec/controller_http_basic_auth_spec.rb +0 -50
  197. data/spec/rails3/spec/controller_oauth2_spec.rb +0 -380
  198. data/spec/rails3/spec/controller_oauth_spec.rb +0 -206
  199. data/spec/rails3/spec/controller_remember_me_spec.rb +0 -96
  200. data/spec/rails3/spec/controller_session_timeout_spec.rb +0 -55
  201. data/spec/rails3/spec/controller_spec.rb +0 -177
  202. data/spec/rails3/spec/integration_spec.rb +0 -23
  203. data/spec/rails3/spec/spec.opts +0 -2
  204. data/spec/rails3/spec/spec_helper.orig.rb +0 -27
  205. data/spec/rails3/spec/spec_helper.rb +0 -71
  206. data/spec/rails3/spec/user_activation_spec.rb +0 -16
  207. data/spec/rails3/spec/user_activity_logging_spec.rb +0 -8
  208. data/spec/rails3/spec/user_spec.rb +0 -36
  209. data/spec/rails3/vendor/plugins/.gitkeep +0 -0
  210. data/spec/rails3_mongo_mapper/.gitignore +0 -4
  211. data/spec/rails3_mongo_mapper/.rspec +0 -1
  212. data/spec/rails3_mongo_mapper/Gemfile +0 -16
  213. data/spec/rails3_mongo_mapper/Gemfile.lock +0 -156
  214. data/spec/rails3_mongo_mapper/Rakefile +0 -11
  215. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +0 -122
  216. data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +0 -2
  217. data/spec/rails3_mongo_mapper/app/mailers/sorcery_mailer.rb +0 -25
  218. data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +0 -14
  219. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +0 -17
  220. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +0 -9
  221. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +0 -9
  222. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +0 -16
  223. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +0 -8
  224. data/spec/rails3_mongo_mapper/config/boot.rb +0 -13
  225. data/spec/rails3_mongo_mapper/config/environment.rb +0 -5
  226. data/spec/rails3_mongo_mapper/config/environments/development.rb +0 -30
  227. data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
  228. data/spec/rails3_mongo_mapper/config/environments/production.rb +0 -49
  229. data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +0 -7
  230. data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +0 -10
  231. data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +0 -5
  232. data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +0 -2
  233. data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +0 -7
  234. data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +0 -8
  235. data/spec/rails3_mongo_mapper/config/locales/en.yml +0 -5
  236. data/spec/rails3_mongo_mapper/config/routes.rb +0 -59
  237. data/spec/rails3_mongo_mapper/db/schema.rb +0 -23
  238. data/spec/rails3_mongo_mapper/db/seeds.rb +0 -7
  239. data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
  240. data/spec/rails3_mongo_mapper/public/404.html +0 -26
  241. data/spec/rails3_mongo_mapper/public/422.html +0 -26
  242. data/spec/rails3_mongo_mapper/public/500.html +0 -26
  243. data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
  244. data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
  245. data/spec/rails3_mongo_mapper/public/javascripts/application.js +0 -2
  246. data/spec/rails3_mongo_mapper/public/javascripts/controls.js +0 -965
  247. data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +0 -974
  248. data/spec/rails3_mongo_mapper/public/javascripts/effects.js +0 -1123
  249. data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +0 -6001
  250. data/spec/rails3_mongo_mapper/public/javascripts/rails.js +0 -175
  251. data/spec/rails3_mongo_mapper/public/robots.txt +0 -5
  252. data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
  253. data/spec/rails3_mongo_mapper/script/rails +0 -6
  254. data/spec/rails3_mongo_mapper/spec/controller_spec.rb +0 -170
  255. data/spec/rails3_mongo_mapper/spec/spec.opts +0 -2
  256. data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +0 -27
  257. data/spec/rails3_mongo_mapper/spec/spec_helper.rb +0 -55
  258. data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +0 -9
  259. data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +0 -8
  260. data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +0 -8
  261. data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +0 -8
  262. data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +0 -8
  263. data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +0 -8
  264. data/spec/rails3_mongo_mapper/spec/user_spec.rb +0 -37
  265. data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
  266. data/spec/rails3_mongoid/.gitignore +0 -4
  267. data/spec/rails3_mongoid/.rspec +0 -1
  268. data/spec/rails3_mongoid/Gemfile +0 -15
  269. data/spec/rails3_mongoid/Gemfile.lock +0 -146
  270. data/spec/rails3_mongoid/Rakefile +0 -11
  271. data/spec/rails3_mongoid/app/controllers/application_controller.rb +0 -127
  272. data/spec/rails3_mongoid/app/helpers/application_helper.rb +0 -2
  273. data/spec/rails3_mongoid/app/mailers/sorcery_mailer.rb +0 -25
  274. data/spec/rails3_mongoid/app/views/layouts/application.html.erb +0 -14
  275. data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.html.erb +0 -17
  276. data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.text.erb +0 -9
  277. data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.html.erb +0 -17
  278. data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.text.erb +0 -9
  279. data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.html.erb +0 -16
  280. data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.text.erb +0 -8
  281. data/spec/rails3_mongoid/config/application.rb +0 -51
  282. data/spec/rails3_mongoid/config/boot.rb +0 -13
  283. data/spec/rails3_mongoid/config/environment.rb +0 -5
  284. data/spec/rails3_mongoid/config/environments/development.rb +0 -26
  285. data/spec/rails3_mongoid/config/environments/in_memory.rb +0 -0
  286. data/spec/rails3_mongoid/config/environments/production.rb +0 -49
  287. data/spec/rails3_mongoid/config/environments/test.rb +0 -35
  288. data/spec/rails3_mongoid/config/initializers/backtrace_silencers.rb +0 -7
  289. data/spec/rails3_mongoid/config/initializers/inflections.rb +0 -10
  290. data/spec/rails3_mongoid/config/initializers/mime_types.rb +0 -5
  291. data/spec/rails3_mongoid/config/initializers/secret_token.rb +0 -7
  292. data/spec/rails3_mongoid/config/locales/en.yml +0 -5
  293. data/spec/rails3_mongoid/config/mongoid.yml +0 -7
  294. data/spec/rails3_mongoid/config/routes.rb +0 -59
  295. data/spec/rails3_mongoid/config.ru +0 -4
  296. data/spec/rails3_mongoid/db/schema.rb +0 -23
  297. data/spec/rails3_mongoid/db/seeds.rb +0 -7
  298. data/spec/rails3_mongoid/lib/tasks/.gitkeep +0 -0
  299. data/spec/rails3_mongoid/public/404.html +0 -26
  300. data/spec/rails3_mongoid/public/422.html +0 -26
  301. data/spec/rails3_mongoid/public/500.html +0 -26
  302. data/spec/rails3_mongoid/public/favicon.ico +0 -0
  303. data/spec/rails3_mongoid/public/images/rails.png +0 -0
  304. data/spec/rails3_mongoid/public/javascripts/application.js +0 -2
  305. data/spec/rails3_mongoid/public/javascripts/controls.js +0 -965
  306. data/spec/rails3_mongoid/public/javascripts/dragdrop.js +0 -974
  307. data/spec/rails3_mongoid/public/javascripts/effects.js +0 -1123
  308. data/spec/rails3_mongoid/public/javascripts/prototype.js +0 -6001
  309. data/spec/rails3_mongoid/public/javascripts/rails.js +0 -175
  310. data/spec/rails3_mongoid/public/robots.txt +0 -5
  311. data/spec/rails3_mongoid/public/stylesheets/.gitkeep +0 -0
  312. data/spec/rails3_mongoid/script/rails +0 -6
  313. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +0 -105
  314. data/spec/rails3_mongoid/spec/controller_spec.rb +0 -181
  315. data/spec/rails3_mongoid/spec/spec.opts +0 -2
  316. data/spec/rails3_mongoid/spec/spec_helper.orig.rb +0 -27
  317. data/spec/rails3_mongoid/spec/spec_helper.rb +0 -55
  318. data/spec/rails3_mongoid/spec/user_activation_spec.rb +0 -9
  319. data/spec/rails3_mongoid/spec/user_activity_logging_spec.rb +0 -8
  320. data/spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb +0 -8
  321. data/spec/rails3_mongoid/spec/user_oauth_spec.rb +0 -8
  322. data/spec/rails3_mongoid/spec/user_remember_me_spec.rb +0 -8
  323. data/spec/rails3_mongoid/spec/user_reset_password_spec.rb +0 -8
  324. data/spec/rails3_mongoid/spec/user_spec.rb +0 -38
  325. data/spec/rails3_mongoid/vendor/plugins/.gitkeep +0 -0
  326. data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -56
  327. data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -55
  328. /data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
  329. /data/spec/{rails3/app/models → rails_app/app/active_record}/authentication.rb +0 -0
  330. /data/spec/{rails3 → rails_app}/app/helpers/application_helper.rb +0 -0
  331. /data/spec/{rails3 → rails_app}/app/mailers/sorcery_mailer.rb +0 -0
  332. /data/spec/{rails3_mongo_mapper/app/models → rails_app/app/mongo_mapper}/authentication.rb +0 -0
  333. /data/spec/{rails3_mongoid/app/models → rails_app/app/mongoid}/authentication.rb +0 -0
  334. /data/spec/{rails3 → rails_app}/app/views/application/index.html.erb +0 -0
  335. /data/spec/{rails3 → rails_app}/app/views/layouts/application.html.erb +0 -0
  336. /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_email.html.erb +0 -0
  337. /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_email.text.erb +0 -0
  338. /data/spec/{rails3/app/views/sorcery_mailer/activation_success_email.html.erb → rails_app/app/views/sorcery_mailer/activation_needed_email.html.erb} +0 -0
  339. /data/spec/{rails3_mongo_mapper → rails_app}/app/views/sorcery_mailer/activation_success_email.html.erb +0 -0
  340. /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_success_email.text.erb +0 -0
  341. /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/reset_password_email.html.erb +0 -0
  342. /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/reset_password_email.text.erb +0 -0
  343. /data/spec/{rails3 → rails_app}/config/environment.rb +0 -0
  344. /data/spec/{rails3 → rails_app}/config/initializers/backtrace_silencers.rb +0 -0
  345. /data/spec/{rails3 → rails_app}/config/initializers/inflections.rb +0 -0
  346. /data/spec/{rails3 → rails_app}/config/initializers/mime_types.rb +0 -0
  347. /data/spec/{rails3 → rails_app}/config/initializers/secret_token.rb +0 -0
  348. /data/spec/{rails3 → rails_app}/config/locales/en.yml +0 -0
  349. /data/spec/{rails3 → rails_app}/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
  350. /data/spec/{rails3 → rails_app}/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
  351. /data/spec/{rails3 → rails_app}/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
  352. /data/spec/{rails3 → rails_app}/db/schema.rb +0 -0
  353. /data/spec/{rails3 → rails_app}/db/seeds.rb +0 -0
@@ -9,10 +9,10 @@ module Sorcery
9
9
  Config.module_eval do
10
10
  class << self
11
11
  attr_accessor :session_timeout, # how long in seconds to keep the session alive.
12
-
12
+
13
13
  :session_timeout_from_last_action # use the last action as the beginning of session
14
14
  # timeout.
15
-
15
+
16
16
  def merge_session_timeout_defaults!
17
17
  @defaults.merge!(:@session_timeout => 3600, # 1.hour
18
18
  :@session_timeout_from_last_action => false)
@@ -23,28 +23,32 @@ module Sorcery
23
23
  Config.after_login << :register_login_time
24
24
  base.prepend_before_filter :validate_session
25
25
  end
26
-
26
+
27
27
  module InstanceMethods
28
28
  protected
29
-
29
+
30
30
  # Registers last login to be used as the timeout starting point.
31
31
  # Runs as a hook after a successful login.
32
32
  def register_login_time(user, credentials)
33
33
  session[:login_time] = session[:last_action_time] = Time.now.in_time_zone
34
34
  end
35
-
35
+
36
36
  # Checks if session timeout was reached and expires the current session if so.
37
37
  # To be used as a before_filter, before require_login
38
38
  def validate_session
39
39
  session_to_use = Config.session_timeout_from_last_action ? session[:last_action_time] : session[:login_time]
40
- if session_to_use && (Time.now.in_time_zone - session_to_use > Config.session_timeout)
41
- reset_session
40
+ if session_to_use && sorcery_session_expired?(session_to_use.to_time)
41
+ reset_sorcery_session
42
42
  @current_user = nil
43
43
  else
44
44
  session[:last_action_time] = Time.now.in_time_zone
45
45
  end
46
46
  end
47
47
 
48
+ def sorcery_session_expired?(time)
49
+ Time.now.in_time_zone - time > Config.session_timeout
50
+ end
51
+
48
52
  end
49
53
  end
50
54
  end
@@ -5,7 +5,7 @@ module Sorcery
5
5
  include InstanceMethods
6
6
  Config.submodules.each do |mod|
7
7
  begin
8
- include Submodules.const_get(mod.to_s.split("_").map {|p| p.capitalize}.join(""))
8
+ include Submodules.const_get(mod.to_s.split('_').map { |p| p.capitalize }.join)
9
9
  rescue NameError
10
10
  # don't stop on a missing submodule.
11
11
  end
@@ -28,15 +28,17 @@ module Sorcery
28
28
 
29
29
  # Takes credentials and returns a user on successful authentication.
30
30
  # Runs hooks after login or failed login.
31
- def login(*credentials)
31
+ def login(*credentials)
32
32
  @current_user = nil
33
33
  user = user_class.authenticate(*credentials)
34
34
  if user
35
35
  old_session = session.dup.to_hash
36
- reset_session # protect from session fixation attacks
36
+ reset_sorcery_session
37
37
  old_session.each_pair do |k,v|
38
38
  session[k.to_sym] = v
39
39
  end
40
+ form_authenticity_token
41
+
40
42
  auto_login(user)
41
43
  after_login!(user, credentials)
42
44
  current_user
@@ -46,11 +48,20 @@ module Sorcery
46
48
  end
47
49
  end
48
50
 
51
+ # put this into the catch block to rescue undefined method `destroy_session'
52
+ # hotfix for https://github.com/NoamB/sorcery/issues/464
53
+ # can be removed when Rails 4.1 is out
54
+ def reset_sorcery_session
55
+ reset_session # protect from session fixation attacks
56
+ rescue NoMethodError
57
+ end
58
+
49
59
  # Resets the session and runs hooks before and after.
50
60
  def logout
51
61
  if logged_in?
52
- before_logout!(current_user)
53
- reset_session
62
+ @current_user = current_user if @current_user.nil?
63
+ before_logout!(@current_user)
64
+ reset_sorcery_session
54
65
  after_logout!
55
66
  @current_user = nil
56
67
  end
@@ -61,9 +72,12 @@ module Sorcery
61
72
  end
62
73
 
63
74
  # attempts to auto-login from the sources defined (session, basic_auth, cookie, etc.)
64
- # returns the logged in user if found, false if not (using old restful-authentication trick, nil != false).
75
+ # returns the logged in user if found, nil if not
65
76
  def current_user
66
- @current_user ||= login_from_session || login_from_other_sources unless @current_user == false
77
+ unless defined?(@current_user)
78
+ @current_user = login_from_session || login_from_other_sources || nil
79
+ end
80
+ @current_user
67
81
  end
68
82
 
69
83
  def current_user=(user)
@@ -88,8 +102,8 @@ module Sorcery
88
102
  #
89
103
  # @param [<User-Model>] user the user instance.
90
104
  # @return - do not depend on the return value.
91
- def auto_login(user)
92
- session[:user_id] = user.id
105
+ def auto_login(user, should_remember = false)
106
+ session[:user_id] = user.id.to_s
93
107
  @current_user = user
94
108
  end
95
109
 
@@ -112,11 +126,9 @@ module Sorcery
112
126
  end
113
127
 
114
128
  def login_from_session
115
- @current_user = (user_class.find(session[:user_id]) if session[:user_id]) || false
116
- rescue => exception
117
- return false if defined?(Mongoid) and exception.is_a?(Mongoid::Errors::DocumentNotFound)
118
- return false if defined?(ActiveRecord) and exception.is_a?(ActiveRecord::RecordNotFound)
119
- raise exception
129
+ @current_user = if session[:user_id]
130
+ user_class.sorcery_adapter.find_by_id(session[:user_id])
131
+ end
120
132
  end
121
133
 
122
134
  def after_login!(user, credentials = [])
@@ -141,66 +153,5 @@ module Sorcery
141
153
 
142
154
  end
143
155
 
144
- module Config
145
- class << self
146
- attr_accessor :submodules,
147
- :user_class, # what class to use as the user class.
148
- :not_authenticated_action, # what controller action to call for non-authenticated users.
149
-
150
- :save_return_to_url, # when a non logged in user tries to enter a page that requires
151
- # login, save the URL he wanted to reach,
152
- # and send him there after login.
153
-
154
- :cookie_domain, # set domain option for cookies
155
-
156
- :login_sources,
157
- :after_login,
158
- :after_failed_login,
159
- :before_logout,
160
- :after_logout
161
-
162
- def init!
163
- @defaults = {
164
- :@user_class => nil,
165
- :@submodules => [],
166
- :@not_authenticated_action => :not_authenticated,
167
- :@login_sources => [],
168
- :@after_login => [],
169
- :@after_failed_login => [],
170
- :@before_logout => [],
171
- :@after_logout => [],
172
- :@save_return_to_url => true,
173
- :@cookie_domain => nil
174
- }
175
- end
176
-
177
- # Resets all configuration options to their default values.
178
- def reset!
179
- @defaults.each do |k,v|
180
- instance_variable_set(k,v)
181
- end
182
- end
183
-
184
- def update!
185
- @defaults.each do |k,v|
186
- instance_variable_set(k,v) if !instance_variable_defined?(k)
187
- end
188
- end
189
-
190
- def user_config(&blk)
191
- block_given? ? @user_config = blk : @user_config
192
- end
193
-
194
- def configure(&blk)
195
- @configure_blk = blk
196
- end
197
-
198
- def configure!
199
- @configure_blk.call(self) if @configure_blk
200
- end
201
- end
202
- init!
203
- reset!
204
- end
205
- end
156
+ end
206
157
  end
@@ -0,0 +1,96 @@
1
+ # Each class which calls 'activate_sorcery!' receives an instance of this class.
2
+ # Every submodule which gets loaded may add accessors to this class so that all
3
+ # options will be configured from a single place.
4
+ module Sorcery
5
+ module Model
6
+ class Config
7
+
8
+ attr_accessor :username_attribute_names, # change default username attribute, for example, to use :email
9
+ # as the login.
10
+
11
+ :password_attribute_name, # change *virtual* password attribute, the one which is used
12
+ # until an encrypted one is generated.
13
+
14
+ :email_attribute_name, # change default email attribute.
15
+
16
+ :downcase_username_before_authenticating, # downcase the username before trying to authenticate, default is false
17
+
18
+ :crypted_password_attribute_name, # change default crypted_password attribute.
19
+ :salt_join_token, # what pattern to use to join the password with the salt
20
+ :salt_attribute_name, # change default salt attribute.
21
+ :stretches, # how many times to apply encryption to the password.
22
+ :encryption_key, # encryption key used to encrypt reversible encryptions such as
23
+ # AES256.
24
+
25
+ :subclasses_inherit_config, # make this configuration inheritable for subclasses. Useful for
26
+ # ActiveRecord's STI.
27
+
28
+ :submodules, # configured in config/application.rb
29
+ :before_authenticate, # an array of method names to call before authentication
30
+ # completes. used internally.
31
+
32
+ :after_config # an array of method names to call after configuration by user.
33
+ # used internally.
34
+
35
+ attr_reader :encryption_provider, # change default encryption_provider.
36
+ :custom_encryption_provider, # use an external encryption class.
37
+ :encryption_algorithm # encryption algorithm name. See 'encryption_algorithm=' below
38
+ # for available options.
39
+
40
+ def initialize
41
+ @defaults = {
42
+ :@submodules => [],
43
+ :@username_attribute_names => [:email],
44
+ :@password_attribute_name => :password,
45
+ :@downcase_username_before_authenticating => false,
46
+ :@email_attribute_name => :email,
47
+ :@crypted_password_attribute_name => :crypted_password,
48
+ :@encryption_algorithm => :bcrypt,
49
+ :@encryption_provider => CryptoProviders::BCrypt,
50
+ :@custom_encryption_provider => nil,
51
+ :@encryption_key => nil,
52
+ :@salt_join_token => "",
53
+ :@salt_attribute_name => :salt,
54
+ :@stretches => nil,
55
+ :@subclasses_inherit_config => false,
56
+ :@before_authenticate => [],
57
+ :@after_config => []
58
+ }
59
+ reset!
60
+ end
61
+
62
+ # Resets all configuration options to their default values.
63
+ def reset!
64
+ @defaults.each do |k,v|
65
+ instance_variable_set(k,v)
66
+ end
67
+ end
68
+
69
+ def username_attribute_names=(fields)
70
+ @username_attribute_names = fields.kind_of?(Array) ? fields : [fields]
71
+ end
72
+
73
+ def custom_encryption_provider=(provider)
74
+ @custom_encryption_provider = @encryption_provider = provider
75
+ end
76
+
77
+ def encryption_algorithm=(algo)
78
+ @encryption_algorithm = algo
79
+ @encryption_provider = case @encryption_algorithm.to_sym
80
+ when :none then nil
81
+ when :md5 then CryptoProviders::MD5
82
+ when :sha1 then CryptoProviders::SHA1
83
+ when :sha256 then CryptoProviders::SHA256
84
+ when :sha512 then CryptoProviders::SHA512
85
+ when :aes256 then CryptoProviders::AES256
86
+ when :bcrypt then CryptoProviders::BCrypt
87
+ when :custom then @custom_encryption_provider
88
+ else raise ArgumentError.new("Encryption algorithm supplied, #{algo}, is invalid")
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+ end
96
+
@@ -3,45 +3,65 @@ module Sorcery
3
3
  module Submodules
4
4
  # This submodule keeps track of events such as login, logout, and last activity time, per user.
5
5
  # It helps in estimating which users are active now in the site.
6
- # This cannot be determined absolutely because a user might be reading a page without clicking anything
6
+ # This cannot be determined absolutely because a user might be reading a page without clicking anything
7
7
  # for a while.
8
8
  # This is the model part of the submodule, which provides configuration options.
9
9
  module ActivityLogging
10
10
  def self.included(base)
11
11
  base.extend(ClassMethods)
12
+ base.send(:include, InstanceMethods)
12
13
 
13
14
  base.sorcery_config.class_eval do
14
15
  attr_accessor :last_login_at_attribute_name, # last login attribute name.
15
16
  :last_logout_at_attribute_name, # last logout attribute name.
16
17
  :last_activity_at_attribute_name, # last activity attribute name.
17
- :activity_timeout # how long since last activity is
18
+ :last_login_from_ip_address_name, # last activity login source
19
+ :activity_timeout # how long since last activity is
18
20
  #the user defined logged out?
19
21
  end
20
-
22
+
21
23
  base.sorcery_config.instance_eval do
22
24
  @defaults.merge!(:@last_login_at_attribute_name => :last_login_at,
23
25
  :@last_logout_at_attribute_name => :last_logout_at,
24
26
  :@last_activity_at_attribute_name => :last_activity_at,
27
+ :@last_login_from_ip_address_name => :last_login_from_ip_address,
25
28
  :@activity_timeout => 10 * 60)
26
29
  reset!
27
30
  end
28
31
 
29
- base.sorcery_config.after_config << :define_activity_logging_mongoid_fields if defined?(Mongoid) and base.ancestors.include?(Mongoid::Document)
32
+ base.sorcery_config.after_config << :define_activity_logging_fields
33
+ end
34
+
35
+ module InstanceMethods
36
+ def set_last_login_at(time)
37
+ sorcery_adapter.update_attribute(sorcery_config.last_login_at_attribute_name, time)
38
+ end
39
+
40
+ def set_last_logout_at(time)
41
+ sorcery_adapter.update_attribute(sorcery_config.last_logout_at_attribute_name, time)
42
+ end
43
+
44
+ def set_last_activity_at(time)
45
+ sorcery_adapter.update_attribute(sorcery_config.last_activity_at_attribute_name, time)
46
+ end
47
+
48
+ def set_last_ip_addess(ip_address)
49
+ sorcery_adapter.update_attribute(sorcery_config.last_login_from_ip_address_name, ip_address)
50
+ end
30
51
  end
31
-
52
+
32
53
  module ClassMethods
33
54
  # get all users with last_activity within timeout
34
55
  def current_users
35
- config = sorcery_config
36
- get_current_users
56
+ sorcery_adapter.get_current_users
37
57
  end
38
58
 
39
59
  protected
40
-
41
- def define_activity_logging_mongoid_fields
42
- field sorcery_config.last_login_at_attribute_name, :type => Time
43
- field sorcery_config.last_logout_at_attribute_name, :type => Time
44
- field sorcery_config.last_activity_at_attribute_name, :type => Time
60
+ def define_activity_logging_fields
61
+ sorcery_adapter.define_field sorcery_config.last_login_at_attribute_name, Time
62
+ sorcery_adapter.define_field sorcery_config.last_logout_at_attribute_name, Time
63
+ sorcery_adapter.define_field sorcery_config.last_activity_at_attribute_name, Time
64
+ sorcery_adapter.define_field sorcery_config.last_login_from_ip_address_name, String
45
65
  end
46
66
  end
47
67
  end
@@ -1,18 +1,18 @@
1
1
  module Sorcery
2
2
  module Model
3
3
  module Submodules
4
- # This module helps protect user accounts by locking them down after too many failed attemps
4
+ # This module helps protect user accounts by locking them down after too many failed attemps
5
5
  # to login were detected.
6
- # This is the model part of the submodule which provides configuration options and methods
6
+ # This is the model part of the submodule which provides configuration options and methods
7
7
  # for locking and unlocking the user.
8
8
  module BruteForceProtection
9
9
  def self.included(base)
10
10
  base.sorcery_config.class_eval do
11
11
  attr_accessor :failed_logins_count_attribute_name, # failed logins attribute name.
12
- :lock_expires_at_attribute_name, # this field indicates whether user
12
+ :lock_expires_at_attribute_name, # this field indicates whether user
13
13
  # is banned and when it will be active again.
14
14
  :consecutive_login_retries_amount_limit, # how many failed logins allowed.
15
- :login_lock_time_period, # how long the user should be banned.
15
+ :login_lock_time_period, # how long the user should be banned.
16
16
  # in seconds. 0 for permanent.
17
17
 
18
18
  :unlock_token_attribute_name, # Unlock token attribute name
@@ -20,7 +20,7 @@ module Sorcery
20
20
  :unlock_token_mailer_disabled, # When true, dont send unlock token via email
21
21
  :unlock_token_mailer # Mailer class
22
22
  end
23
-
23
+
24
24
  base.sorcery_config.instance_eval do
25
25
  @defaults.merge!(:@failed_logins_count_attribute_name => :failed_logins_count,
26
26
  :@lock_expires_at_attribute_name => :lock_expires_at,
@@ -33,82 +33,82 @@ module Sorcery
33
33
  :@unlock_token_mailer => nil)
34
34
  reset!
35
35
  end
36
-
36
+
37
37
  base.sorcery_config.before_authenticate << :prevent_locked_user_login
38
- base.sorcery_config.after_config << :define_brute_force_protection_mongoid_fields if defined?(Mongoid) and base.ancestors.include?(Mongoid::Document)
39
- if defined?(MongoMapper) and base.ancestors.include?(MongoMapper::Document)
40
- base.sorcery_config.after_config << :define_brute_force_protection_mongo_mapper_fields
41
- end
38
+ base.sorcery_config.after_config << :define_brute_force_protection_fields
42
39
  base.extend(ClassMethods)
43
40
  base.send(:include, InstanceMethods)
44
41
  end
45
-
42
+
46
43
  module ClassMethods
47
44
  def load_from_unlock_token(token)
48
45
  return nil if token.blank?
49
- user = find_by_sorcery_token(sorcery_config.unlock_token_attribute_name,token)
46
+ user = sorcery_adapter.find_by_token(sorcery_config.unlock_token_attribute_name,token)
50
47
  user
51
48
  end
52
49
 
53
50
  protected
54
51
 
55
- def define_brute_force_protection_mongoid_fields
56
- field sorcery_config.failed_logins_count_attribute_name, :type => Integer, :default => 0
57
- field sorcery_config.lock_expires_at_attribute_name, :type => Time
58
- field sorcery_config.unlock_token_attribute_name, :type => String
59
- end
60
-
61
- def define_brute_force_protection_mongo_mapper_fields
62
- key sorcery_config.failed_logins_count_attribute_name, Integer, :default => 0
63
- key sorcery_config.lock_expires_at_attribute_name, Time
64
- key sorcery_config.unlock_token_attribute_name, String
52
+ def define_brute_force_protection_fields
53
+ sorcery_adapter.define_field sorcery_config.failed_logins_count_attribute_name, Integer, :default => 0
54
+ sorcery_adapter.define_field sorcery_config.lock_expires_at_attribute_name, Time
55
+ sorcery_adapter.define_field sorcery_config.unlock_token_attribute_name, String
65
56
  end
66
57
  end
67
-
58
+
68
59
  module InstanceMethods
69
60
  # Called by the controller to increment the failed logins counter.
70
61
  # Calls 'lock!' if login retries limit was reached.
71
62
  def register_failed_login!
72
63
  config = sorcery_config
73
64
  return if !unlocked?
74
- self.increment(config.failed_logins_count_attribute_name)
75
- self.update_many_attributes(config.failed_logins_count_attribute_name => self.send(config.failed_logins_count_attribute_name))
76
- self.lock! if self.send(config.failed_logins_count_attribute_name) >= config.consecutive_login_retries_amount_limit
65
+
66
+ sorcery_adapter.increment(config.failed_logins_count_attribute_name)
67
+
68
+ if self.send(config.failed_logins_count_attribute_name) >= config.consecutive_login_retries_amount_limit
69
+ lock!
70
+ end
77
71
  end
78
-
72
+
79
73
  # /!\
80
74
  # Moved out of protected for use like activate! in controller
81
75
  # /!\
82
76
  def unlock!
83
77
  config = sorcery_config
84
78
  attributes = {config.lock_expires_at_attribute_name => nil,
85
- config.failed_logins_count_attribute_name => 0}
86
- attributes[config.unlock_token_attribute_name] = nil unless config.unlock_token_mailer_disabled or config.unlock_token_mailer.nil?
87
- self.update_many_attributes(attributes)
79
+ config.failed_logins_count_attribute_name => 0,
80
+ config.unlock_token_attribute_name => nil}
81
+ sorcery_adapter.update_attributes(attributes)
82
+ end
83
+
84
+ def locked?
85
+ !unlocked?
88
86
  end
89
87
 
90
88
  protected
91
89
 
92
90
  def lock!
93
91
  config = sorcery_config
94
- attributes = {config.lock_expires_at_attribute_name => Time.now.in_time_zone + config.login_lock_time_period}
92
+ attributes = {config.lock_expires_at_attribute_name => Time.now.in_time_zone + config.login_lock_time_period,
93
+ config.unlock_token_attribute_name => TemporaryToken.generate_random_token}
94
+ sorcery_adapter.update_attributes(attributes)
95
95
 
96
96
  unless config.unlock_token_mailer_disabled || config.unlock_token_mailer.nil?
97
- attributes[config.unlock_token_attribute_name] = TemporaryToken.generate_random_token
98
97
  send_unlock_token_email!
99
98
  end
100
- self.update_many_attributes(attributes)
101
99
  end
102
-
100
+
103
101
  def unlocked?
104
102
  config = sorcery_config
105
103
  self.send(config.lock_expires_at_attribute_name).nil?
106
104
  end
107
105
 
108
106
  def send_unlock_token_email!
109
- generic_send_email(:unlock_token_email_method_name, :unlock_token_mailer) unless sorcery_config.unlock_token_email_method_name.nil? or sorcery_config.unlock_token_mailer_disabled == true
107
+ return if sorcery_config.unlock_token_email_method_name.nil?
108
+
109
+ generic_send_email(:unlock_token_email_method_name, :unlock_token_mailer)
110
110
  end
111
-
111
+
112
112
  # Prevents a locked user from logging in, and unlocks users that expired their lock time.
113
113
  # Runs as a hook before authenticate.
114
114
  def prevent_locked_user_login
@@ -8,7 +8,7 @@ module Sorcery
8
8
  # Socery assumes (read: requires) you will create external users in the same table where
9
9
  # you keep your regular users,
10
10
  # but that you will have a separate table for keeping their external authentication data,
11
- # and that that separate table has a few rows for each user, facebook and twitter
11
+ # and that that separate table has a few rows for each user, facebook and twitter
12
12
  # for example (a one-to-many relationship).
13
13
  #
14
14
  # External users will have a null crypted_password field, since we do not hold their password.
@@ -22,7 +22,7 @@ module Sorcery
22
22
  :provider_uid_attribute_name
23
23
 
24
24
  end
25
-
25
+
26
26
  base.sorcery_config.instance_eval do
27
27
  @defaults.merge!(:@authentications_class => nil,
28
28
  :@authentications_user_id_attribute_name => :user_id,
@@ -31,26 +31,70 @@ module Sorcery
31
31
 
32
32
  reset!
33
33
  end
34
-
34
+
35
35
  base.send(:include, InstanceMethods)
36
36
  base.extend(ClassMethods)
37
37
 
38
38
  end
39
-
39
+
40
40
  module ClassMethods
41
41
  # takes a provider and uid and finds a user by them.
42
42
  def load_from_provider(provider,uid)
43
43
  config = sorcery_config
44
- authentication = config.authentications_class.find_by_provider_and_uid(provider, uid)
45
- user = find(authentication.send(config.authentications_user_id_attribute_name)) if authentication
44
+ authentication = config.authentications_class.sorcery_adapter.find_by_oauth_credentials(provider, uid)
45
+ user = sorcery_adapter.find_by_id(authentication.send(config.authentications_user_id_attribute_name)) if authentication
46
+ end
47
+
48
+ def create_and_validate_from_provider(provider, uid, attrs)
49
+ user = new(attrs)
50
+ user.send(sorcery_config.authentications_class.to_s.downcase.pluralize).build(
51
+ sorcery_config.provider_uid_attribute_name => uid,
52
+ sorcery_config.provider_attribute_name => provider
53
+ )
54
+ saved = user.sorcery_adapter.save
55
+ [user, saved]
56
+ end
57
+
58
+ def create_from_provider(provider, uid, attrs)
59
+ user = new
60
+ attrs.each do |k,v|
61
+ user.send(:"#{k}=", v)
62
+ end
63
+
64
+ if block_given?
65
+ return false unless yield user
66
+ end
67
+
68
+ sorcery_adapter.transaction do
69
+ user.sorcery_adapter.save(:validate => false)
70
+ sorcery_config.authentications_class.create!(
71
+ sorcery_config.authentications_user_id_attribute_name => user.id,
72
+ sorcery_config.provider_attribute_name => provider,
73
+ sorcery_config.provider_uid_attribute_name => uid
74
+ )
75
+ end
76
+ user
46
77
  end
47
78
  end
48
-
79
+
49
80
  module InstanceMethods
81
+ def add_provider_to_user(provider, uid)
82
+ authentications = sorcery_config.authentications_class.name.underscore.pluralize
83
+ # first check to see if user has a particular authentication already
84
+ if sorcery_adapter.find_authentication_by_oauth_credentials(authentications, provider, uid).nil?
85
+ user = send(authentications).build(sorcery_config.provider_uid_attribute_name => uid,
86
+ sorcery_config.provider_attribute_name => provider)
87
+ user.sorcery_adapter.save(validate: false)
88
+ else
89
+ user = false
90
+ end
91
+
92
+ user
93
+ end
50
94
 
51
95
  end
52
-
96
+
53
97
  end
54
98
  end
55
99
  end
56
- end
100
+ end