sorcery 0.6.1 → 0.7.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 (185) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +52 -45
  3. data/README.rdoc +26 -54
  4. data/Rakefile +26 -0
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery/USAGE +22 -0
  7. data/lib/generators/sorcery/install_generator.rb +71 -0
  8. data/lib/{sorcery/initializers → generators/sorcery/templates}/initializer.rb +82 -61
  9. data/lib/generators/sorcery/templates/migration/activity_logging.rb +17 -0
  10. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +11 -0
  11. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/core.rb +3 -3
  12. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/external.rb +1 -1
  13. data/lib/generators/sorcery/templates/migration/remember_me.rb +15 -0
  14. data/lib/generators/sorcery/templates/migration/reset_password.rb +17 -0
  15. data/lib/generators/sorcery/templates/migration/user_activation.rb +17 -0
  16. data/lib/sorcery/controller/submodules/activity_logging.rb +23 -9
  17. data/lib/sorcery/controller/submodules/brute_force_protection.rb +2 -1
  18. data/lib/sorcery/controller/submodules/external/protocols/certs/ca-bundle.crt +5182 -0
  19. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +27 -8
  20. data/lib/sorcery/controller/submodules/external/providers/github.rb +80 -0
  21. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +5 -0
  22. data/lib/sorcery/controller/submodules/external.rb +10 -3
  23. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  24. data/lib/sorcery/controller/submodules/remember_me.rb +15 -5
  25. data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
  26. data/lib/sorcery/controller.rb +59 -38
  27. data/lib/sorcery/crypto_providers/aes256.rb +7 -3
  28. data/lib/sorcery/engine.rb +1 -0
  29. data/lib/sorcery/model/adapters/active_record.rb +2 -1
  30. data/lib/sorcery/model/adapters/mongo_mapper.rb +49 -0
  31. data/lib/sorcery/model/adapters/mongoid.rb +7 -2
  32. data/lib/sorcery/model/submodules/brute_force_protection.rb +13 -3
  33. data/lib/sorcery/model/submodules/remember_me.rb +9 -2
  34. data/lib/sorcery/model/submodules/reset_password.rb +11 -2
  35. data/lib/sorcery/model/submodules/user_activation.rb +13 -2
  36. data/lib/sorcery/model/temporary_token.rb +5 -0
  37. data/lib/sorcery/model.rb +34 -15
  38. data/lib/sorcery/test_helpers/internal/rails.rb +1 -1
  39. data/lib/sorcery/test_helpers/rails.rb +2 -2
  40. data/lib/sorcery.rb +6 -7
  41. data/sorcery.gemspec +86 -203
  42. data/spec/Gemfile.lock +23 -12
  43. data/spec/README.md +31 -0
  44. data/spec/rails3/Gemfile +3 -1
  45. data/spec/rails3/Gemfile.lock +45 -28
  46. data/spec/rails3/app/controllers/application_controller.rb +40 -22
  47. data/spec/rails3/app/views/application/index.html.erb +17 -0
  48. data/spec/rails3/spec/controller_activity_logging_spec.rb +23 -0
  49. data/spec/rails3/spec/controller_oauth2_spec.rb +59 -16
  50. data/spec/rails3/spec/controller_remember_me_spec.rb +37 -6
  51. data/spec/rails3/spec/controller_spec.rb +30 -0
  52. data/spec/rails3/spec/integration_spec.rb +23 -0
  53. data/spec/rails3/spec/spec_helper.rb +6 -5
  54. data/spec/rails3_mongo_mapper/.gitignore +4 -0
  55. data/spec/rails3_mongo_mapper/.rspec +1 -0
  56. data/spec/{sinatra_modular → rails3_mongo_mapper}/Gemfile +5 -5
  57. data/spec/rails3_mongo_mapper/Gemfile.lock +159 -0
  58. data/spec/{sinatra → rails3_mongo_mapper}/Rakefile +3 -3
  59. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +108 -0
  60. data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +2 -0
  61. data/spec/rails3_mongo_mapper/app/models/authentication.rb +6 -0
  62. data/spec/rails3_mongo_mapper/app/models/user.rb +5 -0
  63. data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +14 -0
  64. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +17 -0
  65. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +9 -0
  66. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
  67. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
  68. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
  69. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
  70. data/spec/rails3_mongo_mapper/config/application.rb +51 -0
  71. data/spec/rails3_mongo_mapper/config/boot.rb +13 -0
  72. data/spec/rails3_mongo_mapper/config/environment.rb +5 -0
  73. data/spec/rails3_mongo_mapper/config/environments/development.rb +30 -0
  74. data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
  75. data/spec/rails3_mongo_mapper/config/environments/production.rb +49 -0
  76. data/spec/rails3_mongo_mapper/config/environments/test.rb +35 -0
  77. data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +7 -0
  78. data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +10 -0
  79. data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +5 -0
  80. data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +2 -0
  81. data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +7 -0
  82. data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +8 -0
  83. data/spec/rails3_mongo_mapper/config/locales/en.yml +5 -0
  84. data/spec/rails3_mongo_mapper/config/routes.rb +59 -0
  85. data/spec/rails3_mongo_mapper/config.ru +4 -0
  86. data/spec/rails3_mongo_mapper/db/schema.rb +23 -0
  87. data/spec/rails3_mongo_mapper/db/seeds.rb +7 -0
  88. data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
  89. data/spec/rails3_mongo_mapper/public/404.html +26 -0
  90. data/spec/rails3_mongo_mapper/public/422.html +26 -0
  91. data/spec/rails3_mongo_mapper/public/500.html +26 -0
  92. data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
  93. data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
  94. data/spec/rails3_mongo_mapper/public/javascripts/application.js +2 -0
  95. data/spec/rails3_mongo_mapper/public/javascripts/controls.js +965 -0
  96. data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +974 -0
  97. data/spec/rails3_mongo_mapper/public/javascripts/effects.js +1123 -0
  98. data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +6001 -0
  99. data/spec/rails3_mongo_mapper/public/javascripts/rails.js +175 -0
  100. data/spec/rails3_mongo_mapper/public/robots.txt +5 -0
  101. data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
  102. data/spec/rails3_mongo_mapper/script/rails +6 -0
  103. data/spec/{sinatra → rails3_mongo_mapper}/spec/controller_spec.rb +51 -41
  104. data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +27 -0
  105. data/spec/rails3_mongo_mapper/spec/spec_helper.rb +55 -0
  106. data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +9 -0
  107. data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +8 -0
  108. data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +8 -0
  109. data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +8 -0
  110. data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +8 -0
  111. data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +8 -0
  112. data/spec/rails3_mongo_mapper/spec/user_spec.rb +37 -0
  113. data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
  114. data/spec/rails3_mongoid/Gemfile +1 -1
  115. data/spec/rails3_mongoid/Gemfile.lock +41 -34
  116. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +98 -0
  117. data/spec/rails3_mongoid/spec/controller_spec.rb +130 -0
  118. data/spec/rails3_mongoid/spec/user_spec.rb +1 -0
  119. data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -0
  120. data/spec/shared_examples/user_shared_examples.rb +36 -8
  121. metadata +128 -234
  122. data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +0 -24
  123. data/lib/generators/sorcery_migration/templates/activity_logging.rb +0 -17
  124. data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +0 -11
  125. data/lib/generators/sorcery_migration/templates/remember_me.rb +0 -15
  126. data/lib/generators/sorcery_migration/templates/reset_password.rb +0 -13
  127. data/lib/generators/sorcery_migration/templates/user_activation.rb +0 -17
  128. data/lib/sorcery/controller/adapters/sinatra.rb +0 -104
  129. data/lib/sorcery/sinatra.rb +0 -4
  130. data/lib/sorcery/test_helpers/internal/sinatra.rb +0 -74
  131. data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +0 -74
  132. data/lib/sorcery/test_helpers/sinatra.rb +0 -88
  133. data/spec/rails3/Rakefile.unused +0 -7
  134. data/spec/rails3/public/index.html +0 -239
  135. data/spec/sinatra/Gemfile +0 -15
  136. data/spec/sinatra/Gemfile.lock +0 -117
  137. data/spec/sinatra/authentication.rb +0 -3
  138. data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  139. data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  140. data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  141. data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +0 -16
  142. data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  143. data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  144. data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  145. data/spec/sinatra/filters.rb +0 -27
  146. data/spec/sinatra/modular.rb +0 -157
  147. data/spec/sinatra/myapp.rb +0 -133
  148. data/spec/sinatra/spec/controller_activity_logging_spec.rb +0 -85
  149. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +0 -70
  150. data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +0 -53
  151. data/spec/sinatra/spec/controller_oauth2_spec.rb +0 -99
  152. data/spec/sinatra/spec/controller_oauth_spec.rb +0 -100
  153. data/spec/sinatra/spec/controller_remember_me_spec.rb +0 -64
  154. data/spec/sinatra/spec/controller_session_timeout_spec.rb +0 -57
  155. data/spec/sinatra/spec/spec_helper.rb +0 -45
  156. data/spec/sinatra/user.rb +0 -6
  157. data/spec/sinatra/views/test_login.erb +0 -4
  158. data/spec/sinatra_modular/Gemfile.lock +0 -117
  159. data/spec/sinatra_modular/Rakefile +0 -11
  160. data/spec/sinatra_modular/authentication.rb +0 -3
  161. data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  162. data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  163. data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  164. data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +0 -16
  165. data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  166. data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  167. data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  168. data/spec/sinatra_modular/filters.rb +0 -27
  169. data/spec/sinatra_modular/modular.rb +0 -157
  170. data/spec/sinatra_modular/myapp.rb +0 -133
  171. data/spec/sinatra_modular/sorcery_mailer.rb +0 -25
  172. data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +0 -85
  173. data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +0 -70
  174. data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +0 -53
  175. data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +0 -99
  176. data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +0 -100
  177. data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +0 -64
  178. data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +0 -57
  179. data/spec/sinatra_modular/spec_modular/controller_spec.rb +0 -116
  180. data/spec/sinatra_modular/spec_modular/spec.opts +0 -2
  181. data/spec/sinatra_modular/spec_modular/spec_helper.rb +0 -51
  182. data/spec/sinatra_modular/user.rb +0 -6
  183. data/spec/sinatra_modular/views/test_login.erb +0 -4
  184. /data/spec/{sinatra → rails3_mongo_mapper/app/mailers}/sorcery_mailer.rb +0 -0
  185. /data/spec/{sinatra → rails3_mongo_mapper}/spec/spec.opts +0 -0
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source "http://rubygems.org"
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem 'oauth', "~> 0.4.4"
6
6
  gem 'oauth2', "~> 0.4.1"
7
+ gem 'mongo_mapper'
7
8
 
8
9
  # Add dependencies to develop your gem here.
9
10
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -1,41 +1,39 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- actionmailer (3.1.0)
5
- actionpack (= 3.1.0)
4
+ actionmailer (3.1.1)
5
+ actionpack (= 3.1.1)
6
6
  mail (~> 2.3.0)
7
- actionpack (3.1.0)
8
- activemodel (= 3.1.0)
9
- activesupport (= 3.1.0)
7
+ actionpack (3.1.1)
8
+ activemodel (= 3.1.1)
9
+ activesupport (= 3.1.1)
10
10
  builder (~> 3.0.0)
11
11
  erubis (~> 2.7.0)
12
12
  i18n (~> 0.6)
13
13
  rack (~> 1.3.2)
14
- rack-cache (~> 1.0.3)
14
+ rack-cache (~> 1.1)
15
15
  rack-mount (~> 0.8.2)
16
16
  rack-test (~> 0.6.1)
17
- sprockets (~> 2.0.0)
18
- activemodel (3.1.0)
19
- activesupport (= 3.1.0)
20
- bcrypt-ruby (~> 3.0.0)
17
+ sprockets (~> 2.0.2)
18
+ activemodel (3.1.1)
19
+ activesupport (= 3.1.1)
21
20
  builder (~> 3.0.0)
22
21
  i18n (~> 0.6)
23
- activerecord (3.1.0)
24
- activemodel (= 3.1.0)
25
- activesupport (= 3.1.0)
22
+ activerecord (3.1.1)
23
+ activemodel (= 3.1.1)
24
+ activesupport (= 3.1.1)
26
25
  arel (~> 2.2.1)
27
26
  tzinfo (~> 0.3.29)
28
- activeresource (3.1.0)
29
- activemodel (= 3.1.0)
30
- activesupport (= 3.1.0)
31
- activesupport (3.1.0)
27
+ activeresource (3.1.1)
28
+ activemodel (= 3.1.1)
29
+ activesupport (= 3.1.1)
30
+ activesupport (3.1.1)
32
31
  multi_json (~> 1.0)
33
32
  addressable (2.2.6)
34
33
  archive-tar-minitar (0.5.2)
35
34
  arel (2.2.1)
36
- bcrypt-ruby (3.0.0)
37
- bson (1.3.1)
38
- bson_ext (1.3.1)
35
+ bson (1.4.1)
36
+ bson_ext (1.4.1)
39
37
  builder (3.0.0)
40
38
  columnize (0.3.4)
41
39
  diff-lcs (1.1.3)
@@ -43,7 +41,7 @@ GEM
43
41
  faraday (0.6.1)
44
42
  addressable (~> 2.2.4)
45
43
  multipart-post (~> 1.1.0)
46
- rack (< 2, >= 1.1.0)
44
+ rack (>= 1.1.0, < 2)
47
45
  git (1.2.5)
48
46
  hike (1.2.1)
49
47
  i18n (0.6.0)
@@ -51,7 +49,7 @@ GEM
51
49
  bundler (~> 1.0.0)
52
50
  git (>= 1.2.5)
53
51
  rake
54
- json (1.5.4)
52
+ json (1.6.1)
55
53
  linecache19 (0.5.12)
56
54
  ruby_core_source (>= 0.1.4)
57
55
  mail (2.3.0)
@@ -59,11 +57,15 @@ GEM
59
57
  mime-types (~> 1.16)
60
58
  treetop (~> 1.4.8)
61
59
  mime-types (1.16)
62
- mongo (1.3.1)
63
- bson (>= 1.3.1)
64
- mongoid (2.2.0)
60
+ mongo (1.4.1)
61
+ bson (= 1.4.1)
62
+ mongo_mapper (0.9.2)
65
63
  activemodel (~> 3.0)
66
- mongo (~> 1.3)
64
+ activesupport (~> 3.0)
65
+ plucky (~> 0.3.8)
66
+ mongoid (2.3.2)
67
+ activemodel (~> 3.1)
68
+ mongo (~> 1.4)
67
69
  tzinfo (~> 0.3.22)
68
70
  multi_json (1.0.3)
69
71
  multipart-post (1.1.3)
@@ -71,9 +73,11 @@ GEM
71
73
  oauth2 (0.4.1)
72
74
  faraday (~> 0.6.1)
73
75
  multi_json (>= 0.0.5)
76
+ plucky (0.3.8)
77
+ mongo (~> 1.3)
74
78
  polyglot (0.3.2)
75
- rack (1.3.2)
76
- rack-cache (1.0.3)
79
+ rack (1.3.5)
80
+ rack-cache (1.1)
77
81
  rack (>= 0.4)
78
82
  rack-mount (0.8.3)
79
83
  rack (>= 1.0.0)
@@ -81,23 +85,24 @@ GEM
81
85
  rack
82
86
  rack-test (0.6.1)
83
87
  rack (>= 1.0)
84
- rails (3.1.0)
85
- actionmailer (= 3.1.0)
86
- actionpack (= 3.1.0)
87
- activerecord (= 3.1.0)
88
- activeresource (= 3.1.0)
89
- activesupport (= 3.1.0)
88
+ rails (3.1.1)
89
+ actionmailer (= 3.1.1)
90
+ actionpack (= 3.1.1)
91
+ activerecord (= 3.1.1)
92
+ activeresource (= 3.1.1)
93
+ activesupport (= 3.1.1)
90
94
  bundler (~> 1.0)
91
- railties (= 3.1.0)
92
- railties (3.1.0)
93
- actionpack (= 3.1.0)
94
- activesupport (= 3.1.0)
95
+ railties (= 3.1.1)
96
+ railties (3.1.1)
97
+ actionpack (= 3.1.1)
98
+ activesupport (= 3.1.1)
95
99
  rack-ssl (~> 1.3.2)
96
100
  rake (>= 0.8.7)
97
101
  rdoc (~> 3.4)
98
102
  thor (~> 0.14.6)
99
103
  rake (0.9.2)
100
- rdoc (3.9.4)
104
+ rdoc (3.11)
105
+ json (~> 1.4)
101
106
  rspec (2.5.0)
102
107
  rspec-core (~> 2.5.0)
103
108
  rspec-expectations (~> 2.5.0)
@@ -121,13 +126,14 @@ GEM
121
126
  ruby-debug-base19 (>= 0.11.19)
122
127
  ruby_core_source (0.1.5)
123
128
  archive-tar-minitar (>= 0.5.2)
124
- simplecov (0.4.2)
125
- simplecov-html (~> 0.4.4)
126
- simplecov-html (0.4.5)
127
- sprockets (2.0.0)
129
+ simplecov (0.5.4)
130
+ multi_json (~> 1.0.3)
131
+ simplecov-html (~> 0.5.3)
132
+ simplecov-html (0.5.3)
133
+ sprockets (2.0.3)
128
134
  hike (~> 1.2)
129
135
  rack (~> 1.0)
130
- tilt (!= 1.3.0, ~> 1.1)
136
+ tilt (~> 1.1, != 1.3.0)
131
137
  sqlite3 (1.3.4)
132
138
  sqlite3-ruby (1.3.3)
133
139
  sqlite3 (>= 1.3.3)
@@ -137,7 +143,7 @@ GEM
137
143
  treetop (1.4.10)
138
144
  polyglot
139
145
  polyglot (>= 0.3.1)
140
- tzinfo (0.3.29)
146
+ tzinfo (0.3.30)
141
147
  yard (0.6.8)
142
148
 
143
149
  PLATFORMS
@@ -148,6 +154,7 @@ DEPENDENCIES
148
154
  bundler (~> 1.0.0)
149
155
  jeweler (~> 1.5.2)
150
156
  json (>= 1.5.1)
157
+ mongo_mapper
151
158
  mongoid (~> 2.0)
152
159
  oauth (~> 0.4.4)
153
160
  oauth2 (~> 0.4.1)
data/README.rdoc CHANGED
@@ -1,11 +1,11 @@
1
1
  = sorcery
2
- Magical Authentication for Rails 3 and Sinatra.
3
- Supports ActiveRecord and Mongoid.
2
+ Magical Authentication for Rails 3.
3
+ Supports ActiveRecord, Mongoid and MongoMapper.
4
4
 
5
5
  Inspired by restful_authentication, Authlogic and Devise.
6
6
  Crypto code taken almost unchanged from Authlogic.
7
7
  OAuth code inspired by OmniAuth and Ryan Bates's railscasts about it.
8
-
8
+
9
9
 
10
10
  == Philosophy
11
11
 
@@ -24,12 +24,11 @@ Hopefully, I've achieved this. If not, let me know.
24
24
 
25
25
  == Useful Links:
26
26
 
27
+ Railscast: http://railscasts.com/episodes/283-authentication-with-sorcery
27
28
 
28
29
  Example Rails 3 app using sorcery: https://github.com/NoamB/sorcery-example-app
29
30
 
30
- Example Sinatra app using sorcery: https://github.com/NoamB/sorcery-example-app-sinatra
31
-
32
- Documentation: http://rubydoc.info/gems/sorcery/0.6.0/frames
31
+ Documentation: http://rubydoc.info/gems/sorcery/0.7.1/frames
33
32
 
34
33
  Check out the tutorials in the github wiki!
35
34
 
@@ -42,9 +41,10 @@ Below is a summary of the library methods. Most method names are self explaining
42
41
  # core
43
42
  require_login # this is a before filter
44
43
  login(username,password,remember_me = false)
44
+ auto_login(user)# login without credentials
45
45
  logout
46
- logged_in?
47
- current_user
46
+ logged_in? # available to view
47
+ current_user # available to view
48
48
  redirect_back_or_to # used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
49
49
  @user.external? # external users, such as facebook/twitter etc.
50
50
  User.authenticates_with_sorcery!
@@ -61,6 +61,7 @@ Below is a summary of the library methods. Most method names are self explaining
61
61
  create_from(provider) # create the user in the local app db.
62
62
 
63
63
  # remember me
64
+ auto_login(user, should_remember=false) # login without credentials, optional remember_me
64
65
  remember_me!
65
66
  forget_me!
66
67
 
@@ -94,53 +95,26 @@ Otherwise simply
94
95
 
95
96
  == Rails 3 Configuration:
96
97
 
98
+ rails generate sorcery:install
97
99
 
98
- For Rails 3 create an initializer file using:
99
-
100
- rake sorcery:bootstrap
101
-
102
- This will create the file as config/initializers/sorcery.rb .
103
- Inside it the comments will tell you everything you need to know.
104
-
105
- For your convenience, Sorcery includes a migrations generator for Rails, which can be used like so:
106
-
107
- rails g sorcery_migration [list of submodules]
108
-
109
- For example, for only the core functionality use:
110
-
111
- rails g sorcery_migration core
112
-
113
- To generate migrations for both the core AND 'remember_me' submodule:
100
+ This will generate the core migration file, the initializer file and the 'User' model class.
114
101
 
115
- rails g sorcery_migration core remember_me
102
+ rails generate sorcery:install remember_me reset_password
116
103
 
117
- These migrations use the default fields. You can choose to use these migrations or make your own tables and fields. Sorcery tries not to impose a database structure and naming scheme on your application.
104
+ This will generate the migrations files for remember_me and reset_password submodules
105
+ and will create the initializer file (and add submodules to it), and create the 'User' model class.
118
106
 
107
+ rails generate sorcery:install --model Person
119
108
 
120
- == Sinatra Configuration:
109
+ This will generate the core migration file, the initializer and change the model class
110
+ (in the initializer and migration files) to the class 'Person' (and its pluralized version, 'people')
121
111
 
112
+ rails generate sorcery:install http_basic_auth external remember_me --migrations
122
113
 
123
- For Sinatra you'll need to create the initializer manually. You can do it in the main app file or in a separate file you require (see example in example app). The code looks as follows:
124
-
125
- Sorcery::Controller::Config.submodules = [] # specify here the submodules you want to include
126
-
127
- Sorcery::Controller::Config.configure do |config|
128
- config.session_timeout = 10.minutes
129
- ...
130
- ...
114
+ This will generate only the migration files for the specified submodules and will
115
+ add them to the initializer file.
131
116
 
132
- config.user_config do |user|
133
- user.username_attribute_name = :email
134
- ...
135
- ...
136
-
137
- end
138
- end
139
-
140
- Finally, to make all the code above take effect, we'll need to re-include the sorcery controller module:
141
-
142
- include Sorcery::Controller::Adapters::Sinatra
143
- include Sorcery::Controller
117
+ Inside the initializer, the comments will tell you what each setting does.
144
118
 
145
119
 
146
120
  == Full Features List by module:
@@ -150,6 +124,7 @@ Core (see lib/sorcery/model.rb and lib/sorcery/controller.rb):
150
124
  * login/logout, optional return user to requested url on login, configurable redirect for non-logged-in users.
151
125
  * password encryption, algorithms: bcrypt(default), md5, sha1, sha256, sha512, aes256, custom(yours!), none. Configurable stretches and salt.
152
126
  * configurable attribute names for username, password and email.
127
+ * allow multiple fields to serve as username.
153
128
 
154
129
  User Activation (see lib/sorcery/model/submodules/user_activation.rb):
155
130
  * User activation by email with optional success email.
@@ -206,13 +181,6 @@ I've got some thoughts which include (unordered):
206
181
  Have an idea? Let me know, and it might get into the gem!
207
182
 
208
183
 
209
- Other stuff:
210
- * Improve specs speed
211
- * Provide an easy way to run specs after install
212
- * Improve documentation
213
- * Try to reduce the number of library methods, and find better names to some
214
-
215
-
216
184
  == Backward compatibility
217
185
 
218
186
 
@@ -228,11 +196,15 @@ The same cannot be said about upgrading to x.4.0 and above, however.
228
196
 
229
197
  Important notes while upgrading:
230
198
 
199
+ * If upgrading from <= 0.6.1 to >= 0.7.0 you need to change 'username_attribute_name' to 'username_attribute_names' in initializer.
231
200
  * If upgrading from <= v0.5.1 to >= v0.5.2 you need to explicitly set your user_class model in the initializer file.
232
201
 
233
202
  # This line must come after the 'user config' block.
234
203
  config.user_class = User
235
204
 
205
+ * Sinatra support existed until v0.7.0 (including), but was dropped later due to being a maintenance nightmare.
206
+
207
+
236
208
  == Contributing to sorcery
237
209
 
238
210
 
data/Rakefile CHANGED
@@ -54,3 +54,29 @@ task :all_sorcery_specs do
54
54
  CMD
55
55
  end
56
56
  end
57
+
58
+ desc "Bundle all folders"
59
+ task :bundle do
60
+ sh "bundle"
61
+ Dir['spec', 'spec/**'].each do |dir|
62
+ if Dir.exists?(dir) && File.exists?(dir + "/Gemfile")
63
+ sh <<-CMD
64
+ cd #{dir}
65
+ bundle
66
+ CMD
67
+ end
68
+ end
69
+ end
70
+
71
+ desc "Bundle update all folders"
72
+ task :bundle_update do
73
+ sh "bundle update"
74
+ Dir['spec', 'spec/**'].each do |dir|
75
+ if Dir.exists?(dir) && File.exists?(dir + "/Gemfile")
76
+ sh <<-CMD
77
+ cd #{dir}
78
+ bundle update
79
+ CMD
80
+ end
81
+ end
82
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.1
@@ -0,0 +1,22 @@
1
+ Description:
2
+ Generates the necessary files to get you up and running with Sorcery gem
3
+
4
+ Examples:
5
+ rails generate sorcery:install
6
+
7
+ This will generate the core migration file, the initializer file and the 'User' model class.
8
+
9
+ rails generate sorcery:install remember_me reset_password
10
+
11
+ This will generate the migrations files for remember_me and reset_password submodules
12
+ and will create the initializer file (and add submodules to it), and create the 'User' model class.
13
+
14
+ rails generate sorcery:install --model Person
15
+
16
+ This will generate the core migration file, the initializer and change the model class
17
+ (in the initializer and migration files) to the class 'Person' (and it's pluralized version, 'people')
18
+
19
+ rails generate sorcery:install http_basic_auth external remember_me --migrations
20
+
21
+ This will generate only the migration files for the specified submodules and will
22
+ add them to the initializer file.
@@ -0,0 +1,71 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module Sorcery
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ argument :submodules, :optional => true, :type => :array, :banner => "submodules"
11
+
12
+ class_option :model, :optional => true, :type => :string, :banner => "model",
13
+ :desc => "Specify the model class name if you will use anything other than 'User'"
14
+
15
+ class_option :migrations, :optional => true, :type => :boolean, :banner => "migrations",
16
+ :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
+
18
+
19
+ # Copy the initializer file to config/initializers folder.
20
+ def copy_initializer_file
21
+ template "initializer.rb", "config/initializers/sorcery.rb" unless options[:migrations]
22
+ end
23
+
24
+ def configure_initializer_file
25
+ # Add submodules to the initializer file.
26
+ if submodules
27
+ str = submodules.collect{ |submodule| ':' + submodule + ', ' }
28
+ str.last.delete!(", ")
29
+
30
+ gsub_file "config/initializers/sorcery.rb", /submodules = \[\]/, "submodules = [#{str.join()}]"
31
+ end
32
+
33
+ # Generate the model and add 'authenticates_with_sorcery!' unless you passed --migrations
34
+ unless options[:migrations]
35
+ generate "model #{model_class_name} --skip-migration"
36
+ insert_into_file "app/models/#{model_class_name}.rb", " authenticates_with_sorcery!\n", :after => "class #{model_class_name} < ActiveRecord::Base\n"
37
+ end
38
+ end
39
+
40
+ # Copy the migrations files to db/migrate folder
41
+ def copy_migration_files
42
+ if submodules
43
+ submodules.each do |submodule|
44
+ unless submodule == "http_basic_auth" || submodule == "session_timeout"
45
+ migration_template "migration/#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb"
46
+ end
47
+ end
48
+ end
49
+
50
+ # Copy core migration file in all cases except when you pass --migrations.
51
+ migration_template "migration/core.rb", "db/migrate/sorcery_core.rb" unless options[:migrations]
52
+ end
53
+
54
+ # Define the next_migration_number method (necessary for the migration_template method to work)
55
+ def self.next_migration_number(dirname)
56
+ if ActiveRecord::Base.timestamped_migrations
57
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
58
+ else
59
+ "%.3d" % (current_migration_number(dirname) + 1)
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ # Either return the model passed in a capitalized form or return the default "User".
66
+ def model_class_name
67
+ options[:model] ? options[:model].capitalize : "User"
68
+ end
69
+ end
70
+ end
71
+ end