sorcery 0.7.0 → 0.7.4

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 (176) hide show
  1. data/Gemfile +1 -3
  2. data/Gemfile.lock +47 -57
  3. data/README.rdoc +19 -57
  4. data/Rakefile +27 -1
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery/USAGE +22 -0
  7. data/lib/generators/sorcery/install_generator.rb +72 -0
  8. data/lib/{sorcery/initializers → generators/sorcery/templates}/initializer.rb +4 -4
  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 +2 -2
  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 +8 -11
  17. data/lib/sorcery/controller/submodules/brute_force_protection.rb +2 -2
  18. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +23 -8
  19. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +1 -1
  20. data/lib/sorcery/controller/submodules/remember_me.rb +16 -14
  21. data/lib/sorcery/controller/submodules/session_timeout.rb +3 -3
  22. data/lib/sorcery/controller.rb +40 -39
  23. data/lib/sorcery/model/adapters/mongo_mapper.rb +49 -0
  24. data/lib/sorcery/model/adapters/mongoid.rb +3 -1
  25. data/lib/sorcery/model/submodules/brute_force_protection.rb +14 -6
  26. data/lib/sorcery/model/submodules/remember_me.rb +9 -2
  27. data/lib/sorcery/model/submodules/reset_password.rb +12 -2
  28. data/lib/sorcery/model/submodules/user_activation.rb +13 -1
  29. data/lib/sorcery/model/temporary_token.rb +4 -2
  30. data/lib/sorcery/model.rb +21 -4
  31. data/lib/sorcery.rb +5 -7
  32. data/sorcery.gemspec +83 -216
  33. data/spec/Gemfile +1 -1
  34. data/spec/Gemfile.lock +20 -17
  35. data/spec/README.md +6 -1
  36. data/spec/rails3/Gemfile +2 -2
  37. data/spec/rails3/Gemfile.lock +36 -51
  38. data/spec/rails3/spec/controller_activity_logging_spec.rb +6 -6
  39. data/spec/rails3/spec/controller_brute_force_protection_spec.rb +2 -2
  40. data/spec/rails3/spec/controller_oauth2_spec.rb +5 -3
  41. data/spec/rails3/spec/controller_session_timeout_spec.rb +4 -4
  42. data/spec/rails3/spec/spec_helper.rb +1 -3
  43. data/spec/rails3_mongo_mapper/.gitignore +4 -0
  44. data/spec/rails3_mongo_mapper/.rspec +1 -0
  45. data/spec/{sinatra_modular → rails3_mongo_mapper}/Gemfile +5 -5
  46. data/spec/rails3_mongo_mapper/Gemfile.lock +158 -0
  47. data/spec/{sinatra → rails3_mongo_mapper}/Rakefile +3 -3
  48. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +108 -0
  49. data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +2 -0
  50. data/spec/rails3_mongo_mapper/app/models/authentication.rb +6 -0
  51. data/spec/rails3_mongo_mapper/app/models/user.rb +5 -0
  52. data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +14 -0
  53. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +17 -0
  54. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +9 -0
  55. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
  56. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
  57. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
  58. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
  59. data/spec/rails3_mongo_mapper/config/application.rb +51 -0
  60. data/spec/rails3_mongo_mapper/config/boot.rb +13 -0
  61. data/spec/rails3_mongo_mapper/config/environment.rb +5 -0
  62. data/spec/rails3_mongo_mapper/config/environments/development.rb +30 -0
  63. data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
  64. data/spec/rails3_mongo_mapper/config/environments/production.rb +49 -0
  65. data/spec/rails3_mongo_mapper/config/environments/test.rb +35 -0
  66. data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +7 -0
  67. data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +10 -0
  68. data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +5 -0
  69. data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +2 -0
  70. data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +7 -0
  71. data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +8 -0
  72. data/spec/rails3_mongo_mapper/config/locales/en.yml +5 -0
  73. data/spec/rails3_mongo_mapper/config/routes.rb +59 -0
  74. data/spec/rails3_mongo_mapper/config.ru +4 -0
  75. data/spec/rails3_mongo_mapper/db/schema.rb +23 -0
  76. data/spec/rails3_mongo_mapper/db/seeds.rb +7 -0
  77. data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
  78. data/spec/rails3_mongo_mapper/public/404.html +26 -0
  79. data/spec/rails3_mongo_mapper/public/422.html +26 -0
  80. data/spec/rails3_mongo_mapper/public/500.html +26 -0
  81. data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
  82. data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
  83. data/spec/rails3_mongo_mapper/public/javascripts/application.js +2 -0
  84. data/spec/rails3_mongo_mapper/public/javascripts/controls.js +965 -0
  85. data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +974 -0
  86. data/spec/rails3_mongo_mapper/public/javascripts/effects.js +1123 -0
  87. data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +6001 -0
  88. data/spec/rails3_mongo_mapper/public/javascripts/rails.js +175 -0
  89. data/spec/rails3_mongo_mapper/public/robots.txt +5 -0
  90. data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
  91. data/spec/rails3_mongo_mapper/script/rails +6 -0
  92. data/spec/{sinatra → rails3_mongo_mapper}/spec/controller_spec.rb +45 -42
  93. data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +27 -0
  94. data/spec/rails3_mongo_mapper/spec/spec_helper.rb +55 -0
  95. data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +9 -0
  96. data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +8 -0
  97. data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +8 -0
  98. data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +8 -0
  99. data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +8 -0
  100. data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +8 -0
  101. data/spec/rails3_mongo_mapper/spec/user_spec.rb +37 -0
  102. data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
  103. data/spec/rails3_mongoid/Gemfile +1 -1
  104. data/spec/rails3_mongoid/Gemfile.lock +38 -36
  105. data/spec/rails3_mongoid/script/rails +0 -0
  106. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +98 -0
  107. data/spec/rails3_mongoid/spec/controller_spec.rb +11 -0
  108. data/spec/rails3_mongoid/spec/user_spec.rb +1 -0
  109. data/spec/shared_examples/user_activation_shared_examples.rb +1 -1
  110. data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -1
  111. data/spec/shared_examples/user_reset_password_shared_examples.rb +2 -2
  112. data/spec/shared_examples/user_shared_examples.rb +29 -1
  113. metadata +105 -251
  114. data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +0 -24
  115. data/lib/generators/sorcery_migration/templates/activity_logging.rb +0 -17
  116. data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +0 -11
  117. data/lib/generators/sorcery_migration/templates/remember_me.rb +0 -15
  118. data/lib/generators/sorcery_migration/templates/reset_password.rb +0 -17
  119. data/lib/generators/sorcery_migration/templates/user_activation.rb +0 -17
  120. data/lib/sorcery/controller/adapters/sinatra.rb +0 -115
  121. data/lib/sorcery/sinatra.rb +0 -4
  122. data/lib/sorcery/test_helpers/internal/sinatra.rb +0 -74
  123. data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +0 -74
  124. data/lib/sorcery/test_helpers/sinatra.rb +0 -88
  125. data/spec/rails3/Rakefile.unused +0 -7
  126. data/spec/sinatra/Gemfile +0 -15
  127. data/spec/sinatra/Gemfile.lock +0 -115
  128. data/spec/sinatra/authentication.rb +0 -3
  129. data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  130. data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  131. data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  132. data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +0 -16
  133. data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  134. data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  135. data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  136. data/spec/sinatra/filters.rb +0 -27
  137. data/spec/sinatra/modular.rb +0 -157
  138. data/spec/sinatra/myapp.rb +0 -133
  139. data/spec/sinatra/spec/controller_activity_logging_spec.rb +0 -85
  140. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +0 -70
  141. data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +0 -53
  142. data/spec/sinatra/spec/controller_oauth2_spec.rb +0 -96
  143. data/spec/sinatra/spec/controller_oauth_spec.rb +0 -100
  144. data/spec/sinatra/spec/controller_remember_me_spec.rb +0 -64
  145. data/spec/sinatra/spec/controller_session_timeout_spec.rb +0 -57
  146. data/spec/sinatra/spec/spec_helper.rb +0 -45
  147. data/spec/sinatra/user.rb +0 -6
  148. data/spec/sinatra/views/test_login.erb +0 -4
  149. data/spec/sinatra_modular/Gemfile.lock +0 -115
  150. data/spec/sinatra_modular/Rakefile +0 -11
  151. data/spec/sinatra_modular/authentication.rb +0 -3
  152. data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  153. data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  154. data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  155. data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +0 -16
  156. data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  157. data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  158. data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  159. data/spec/sinatra_modular/filters.rb +0 -27
  160. data/spec/sinatra_modular/modular.rb +0 -157
  161. data/spec/sinatra_modular/myapp.rb +0 -133
  162. data/spec/sinatra_modular/sorcery_mailer.rb +0 -25
  163. data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +0 -85
  164. data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +0 -70
  165. data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +0 -53
  166. data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +0 -96
  167. data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +0 -100
  168. data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +0 -64
  169. data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +0 -57
  170. data/spec/sinatra_modular/spec_modular/controller_spec.rb +0 -116
  171. data/spec/sinatra_modular/spec_modular/spec.opts +0 -2
  172. data/spec/sinatra_modular/spec_modular/spec_helper.rb +0 -51
  173. data/spec/sinatra_modular/user.rb +0 -6
  174. data/spec/sinatra_modular/views/test_login.erb +0 -4
  175. /data/spec/{sinatra → rails3_mongo_mapper/app/mailers}/sorcery_mailer.rb +0 -0
  176. /data/spec/{sinatra → rails3_mongo_mapper}/spec/spec.opts +0 -0
data/Gemfile CHANGED
@@ -3,15 +3,13 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem 'oauth', "~> 0.4.4"
6
- gem 'oauth2', "~> 0.5.1"
6
+ gem 'oauth2', "~> 0.4.1"
7
7
 
8
8
  # Add dependencies to develop your gem here.
9
9
  # Include everything needed to run rake, tests, features, etc.
10
10
  group :development do
11
11
  gem "rails", ">= 3.0.0"
12
12
  gem 'json', ">= 1.5.1"
13
- gem "mongoid", "~> 2.0"
14
- gem "bson_ext", "~> 1.3"
15
13
  gem "rspec", "~> 2.5.0"
16
14
  gem 'rspec-rails', "~> 2.5.0"
17
15
  gem 'ruby-debug19'
data/Gemfile.lock CHANGED
@@ -1,49 +1,45 @@
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)
39
35
  builder (3.0.0)
40
36
  columnize (0.3.4)
41
37
  diff-lcs (1.1.3)
42
38
  erubis (2.7.0)
43
- faraday (0.7.4)
44
- addressable (~> 2.2.6)
39
+ faraday (0.6.1)
40
+ addressable (~> 2.2.4)
45
41
  multipart-post (~> 1.1.0)
46
- rack (< 2, >= 1.1.0)
42
+ rack (>= 1.1.0, < 2)
47
43
  git (1.2.5)
48
44
  hike (1.2.1)
49
45
  i18n (0.6.0)
@@ -51,29 +47,23 @@ GEM
51
47
  bundler (~> 1.0.0)
52
48
  git (>= 1.2.5)
53
49
  rake
54
- json (1.5.4)
50
+ json (1.6.1)
55
51
  linecache19 (0.5.12)
56
52
  ruby_core_source (>= 0.1.4)
57
53
  mail (2.3.0)
58
54
  i18n (>= 0.4.0)
59
55
  mime-types (~> 1.16)
60
56
  treetop (~> 1.4.8)
61
- mime-types (1.16)
62
- mongo (1.3.1)
63
- bson (>= 1.3.1)
64
- mongoid (2.2.0)
65
- activemodel (~> 3.0)
66
- mongo (~> 1.3)
67
- tzinfo (~> 0.3.22)
57
+ mime-types (1.17.2)
68
58
  multi_json (1.0.3)
69
59
  multipart-post (1.1.3)
70
60
  oauth (0.4.5)
71
- oauth2 (0.5.1)
72
- faraday (~> 0.7.4)
73
- multi_json (~> 1.0.3)
61
+ oauth2 (0.4.1)
62
+ faraday (~> 0.6.1)
63
+ multi_json (>= 0.0.5)
74
64
  polyglot (0.3.2)
75
- rack (1.3.3)
76
- rack-cache (1.0.3)
65
+ rack (1.3.5)
66
+ rack-cache (1.1)
77
67
  rack (>= 0.4)
78
68
  rack-mount (0.8.3)
79
69
  rack (>= 1.0.0)
@@ -81,23 +71,24 @@ GEM
81
71
  rack
82
72
  rack-test (0.6.1)
83
73
  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)
74
+ rails (3.1.1)
75
+ actionmailer (= 3.1.1)
76
+ actionpack (= 3.1.1)
77
+ activerecord (= 3.1.1)
78
+ activeresource (= 3.1.1)
79
+ activesupport (= 3.1.1)
90
80
  bundler (~> 1.0)
91
- railties (= 3.1.0)
92
- railties (3.1.0)
93
- actionpack (= 3.1.0)
94
- activesupport (= 3.1.0)
81
+ railties (= 3.1.1)
82
+ railties (3.1.1)
83
+ actionpack (= 3.1.1)
84
+ activesupport (= 3.1.1)
95
85
  rack-ssl (~> 1.3.2)
96
86
  rake (>= 0.8.7)
97
87
  rdoc (~> 3.4)
98
88
  thor (~> 0.14.6)
99
- rake (0.9.2)
100
- rdoc (3.9.4)
89
+ rake (0.9.2.2)
90
+ rdoc (3.11)
91
+ json (~> 1.4)
101
92
  rspec (2.5.0)
102
93
  rspec-core (~> 2.5.0)
103
94
  rspec-expectations (~> 2.5.0)
@@ -121,13 +112,14 @@ GEM
121
112
  ruby-debug-base19 (>= 0.11.19)
122
113
  ruby_core_source (0.1.5)
123
114
  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)
115
+ simplecov (0.5.4)
116
+ multi_json (~> 1.0.3)
117
+ simplecov-html (~> 0.5.3)
118
+ simplecov-html (0.5.3)
119
+ sprockets (2.0.3)
128
120
  hike (~> 1.2)
129
121
  rack (~> 1.0)
130
- tilt (!= 1.3.0, ~> 1.1)
122
+ tilt (~> 1.1, != 1.3.0)
131
123
  sqlite3 (1.3.4)
132
124
  sqlite3-ruby (1.3.3)
133
125
  sqlite3 (>= 1.3.3)
@@ -137,20 +129,18 @@ GEM
137
129
  treetop (1.4.10)
138
130
  polyglot
139
131
  polyglot (>= 0.3.1)
140
- tzinfo (0.3.29)
132
+ tzinfo (0.3.30)
141
133
  yard (0.6.8)
142
134
 
143
135
  PLATFORMS
144
136
  ruby
145
137
 
146
138
  DEPENDENCIES
147
- bson_ext (~> 1.3)
148
139
  bundler (~> 1.0.0)
149
140
  jeweler (~> 1.5.2)
150
141
  json (>= 1.5.1)
151
- mongoid (~> 2.0)
152
142
  oauth (~> 0.4.4)
153
- oauth2 (~> 0.5.1)
143
+ oauth2 (~> 0.4.1)
154
144
  rails (>= 3.0.0)
155
145
  rspec (~> 2.5.0)
156
146
  rspec-rails (~> 2.5.0)
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
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.
@@ -28,9 +28,7 @@ Railscast: http://railscasts.com/episodes/283-authentication-with-sorcery
28
28
 
29
29
  Example Rails 3 app using sorcery: https://github.com/NoamB/sorcery-example-app
30
30
 
31
- Example Sinatra app using sorcery: https://github.com/NoamB/sorcery-example-app-sinatra
32
-
33
- Documentation: http://rubydoc.info/gems/sorcery/0.7.0/frames
31
+ Documentation: http://rubydoc.info/gems/sorcery/0.7.4/frames
34
32
 
35
33
  Check out the tutorials in the github wiki!
36
34
 
@@ -97,59 +95,26 @@ Otherwise simply
97
95
 
98
96
  == Rails 3 Configuration:
99
97
 
98
+ rails generate sorcery:install
100
99
 
101
- For Rails 3 create an initializer file using:
102
-
103
- rake sorcery:bootstrap
104
-
105
- This will create the file as config/initializers/sorcery.rb .
106
- Inside it the comments will tell you everything you need to know.
107
-
108
- For your convenience, Sorcery includes a migrations generator for Rails, which can be used like so:
109
-
110
- rails g sorcery_migration [list of submodules]
100
+ This will generate the core migration file, the initializer file and the 'User' model class.
111
101
 
112
- Note: There is no migration for the session_timeout module.
113
- For example, for only the core functionality use:
102
+ rails generate sorcery:install remember_me reset_password
114
103
 
115
- rails g sorcery_migration core
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.
116
106
 
117
- To generate migrations for both the core AND 'remember_me' submodule:
107
+ rails generate sorcery:install --model Person
118
108
 
119
- rails g sorcery_migration core remember_me
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')
120
111
 
121
- 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.
112
+ rails generate sorcery:install http_basic_auth external remember_me --migrations
122
113
 
123
- Finally, add sorcery to the the model that you will use for authentication:
124
-
125
- class User < ActiveRecord::Base
126
- authenticates_with_sorcery!
127
- end
114
+ This will generate only the migration files for the specified submodules and will
115
+ add them to the initializer file.
128
116
 
129
- == Sinatra Configuration:
130
-
131
-
132
- 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:
133
-
134
- Sorcery::Controller::Config.submodules = [] # specify here the submodules you want to include
135
-
136
- Sorcery::Controller::Config.configure do |config|
137
- config.session_timeout = 10.minutes
138
- ...
139
- ...
140
-
141
- config.user_config do |user|
142
- user.username_attribute_name = :email
143
- ...
144
- ...
145
-
146
- end
147
- end
148
-
149
- Finally, to make all the code above take effect, we'll need to re-include the sorcery controller module:
150
-
151
- include Sorcery::Controller::Adapters::Sinatra
152
- include Sorcery::Controller
117
+ Inside the initializer, the comments will tell you what each setting does.
153
118
 
154
119
 
155
120
  == Full Features List by module:
@@ -216,13 +181,6 @@ I've got some thoughts which include (unordered):
216
181
  Have an idea? Let me know, and it might get into the gem!
217
182
 
218
183
 
219
- Other stuff:
220
- * Improve specs speed
221
- * Provide an easy way to run specs after install
222
- * Improve documentation
223
- * Try to reduce the number of library methods, and find better names to some
224
-
225
-
226
184
  == Backward compatibility
227
185
 
228
186
 
@@ -238,11 +196,15 @@ The same cannot be said about upgrading to x.4.0 and above, however.
238
196
 
239
197
  Important notes while upgrading:
240
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.
241
200
  * If upgrading from <= v0.5.1 to >= v0.5.2 you need to explicitly set your user_class model in the initializer file.
242
201
 
243
202
  # This line must come after the 'user config' block.
244
203
  config.user_class = User
245
204
 
205
+ * Sinatra support existed until v0.7.0 (including), but was dropped later due to being a maintenance nightmare.
206
+
207
+
246
208
  == Contributing to sorcery
247
209
 
248
210
 
data/Rakefile CHANGED
@@ -27,7 +27,7 @@ Jeweler::Tasks.new do |gem|
27
27
  # gem.add_development_dependency 'rspec', '> 1.2.3'
28
28
  gem.add_runtime_dependency 'bcrypt-ruby', '~> 3.0.0'
29
29
  gem.add_runtime_dependency 'oauth', '~> 0.4.4'
30
- gem.add_runtime_dependency 'oauth2', '~> 0.5.1'
30
+ gem.add_runtime_dependency 'oauth2', '~> 0.4.1'
31
31
  end
32
32
  Jeweler::RubygemsDotOrgTasks.new
33
33
 
@@ -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.7.0
1
+ 0.7.4
@@ -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,72 @@
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.downcase}.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
+ sleep 1 # make sure each time we get a different timestamp
58
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
59
+ else
60
+ "%.3d" % (current_migration_number(dirname) + 1)
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ # Either return the model passed in a capitalized form or return the default "User".
67
+ def model_class_name
68
+ options[:model] ? options[:model].capitalize : "User"
69
+ end
70
+ end
71
+ end
72
+ end
@@ -18,6 +18,9 @@ Rails.application.config.sorcery.configure do |config|
18
18
  # and send him there after login, using
19
19
  # 'redirect_back_or_to'.
20
20
 
21
+ # config.cookie_domain = nil # set domain option for cookies
22
+ # Useful for remember_me submodule
23
+
21
24
  # -- session timeout --
22
25
  # config.session_timeout = 3600 # how long in seconds to keep the session alive.
23
26
  # config.session_timeout_from_last_action = false # use the last action as the beginning of
@@ -54,9 +57,6 @@ Rails.application.config.sorcery.configure do |config|
54
57
  # config.github.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=github"
55
58
  # config.github.user_info_mapping = {:email => "name"}
56
59
 
57
- # config.sinatra_cookie_secret = 'ch4ng3M3plz' # key used to sign cookies in Sinatra
58
- # changing it will invalidate all signed cookies!
59
-
60
60
  # --- user config ---
61
61
  config.user_config do |user|
62
62
  # -- core --
@@ -194,6 +194,6 @@ Rails.application.config.sorcery.configure do |config|
194
194
  end
195
195
 
196
196
  # This line must come after the 'user config' block.
197
- config.user_class = "User" # define which model authenticates
197
+ config.user_class = "<%= model_class_name %>" # define which model authenticates
198
198
  # with sorcery.
199
199
  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,11 @@
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
+ end
6
+
7
+ def self.down
8
+ remove_column :<%= model_class_name.tableize %>, :lock_expires_at
9
+ remove_column :<%= model_class_name.tableize %>, :failed_logins_count
10
+ end
11
+ 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 :users, :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_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_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_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
@@ -30,10 +30,10 @@ module Sorcery
30
30
  # Runs as a hook after a successful login.
31
31
  def reset_failed_logins_count!(user, credentials)
32
32
  user.send(:"#{user_class.sorcery_config.failed_logins_count_attribute_name}=", 0)
33
- user.save!
33
+ user.save!(:validate => false)
34
34
  end
35
35
  end
36
36
  end
37
37
  end
38
38
  end
39
- end
39
+ end