sorcery 0.9.1 → 0.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/ISSUE_TEMPLATE.md +24 -0
  4. data/.github/PULL_REQUEST_TEMPLATE.md +7 -0
  5. data/.github/workflows/ruby.yml +70 -0
  6. data/.gitignore +3 -0
  7. data/.rubocop.yml +55 -0
  8. data/.rubocop_todo.yml +163 -0
  9. data/CHANGELOG.md +132 -34
  10. data/CODE_OF_CONDUCT.md +14 -0
  11. data/Gemfile +3 -17
  12. data/{LICENSE.txt → LICENSE.md} +1 -1
  13. data/MAINTAINING.md +64 -0
  14. data/README.md +146 -269
  15. data/Rakefile +4 -2
  16. data/SECURITY.md +19 -0
  17. data/gemfiles/rails_52.gemfile +7 -0
  18. data/gemfiles/rails_60.gemfile +7 -0
  19. data/gemfiles/rails_61.gemfile +7 -0
  20. data/gemfiles/rails_70.gemfile +7 -0
  21. data/lib/generators/sorcery/USAGE +1 -1
  22. data/lib/generators/sorcery/helpers.rb +8 -4
  23. data/lib/generators/sorcery/install_generator.rb +41 -35
  24. data/lib/generators/sorcery/templates/initializer.rb +216 -112
  25. data/lib/generators/sorcery/templates/migration/activity_logging.rb +7 -7
  26. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +5 -5
  27. data/lib/generators/sorcery/templates/migration/core.rb +5 -7
  28. data/lib/generators/sorcery/templates/migration/external.rb +4 -4
  29. data/lib/generators/sorcery/templates/migration/magic_login.rb +9 -0
  30. data/lib/generators/sorcery/templates/migration/remember_me.rb +5 -5
  31. data/lib/generators/sorcery/templates/migration/reset_password.rb +7 -6
  32. data/lib/generators/sorcery/templates/migration/user_activation.rb +6 -6
  33. data/lib/sorcery/adapters/active_record_adapter.rb +11 -21
  34. data/lib/sorcery/adapters/mongoid_adapter.rb +23 -11
  35. data/lib/sorcery/controller/config.rb +27 -23
  36. data/lib/sorcery/controller/submodules/activity_logging.rb +16 -18
  37. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  38. data/lib/sorcery/controller/submodules/external.rb +69 -44
  39. data/lib/sorcery/controller/submodules/http_basic_auth.rb +18 -19
  40. data/lib/sorcery/controller/submodules/remember_me.rb +16 -16
  41. data/lib/sorcery/controller/submodules/session_timeout.rb +33 -11
  42. data/lib/sorcery/controller.rb +50 -35
  43. data/lib/sorcery/crypto_providers/aes256.rb +17 -16
  44. data/lib/sorcery/crypto_providers/bcrypt.rb +26 -22
  45. data/lib/sorcery/crypto_providers/common.rb +1 -1
  46. data/lib/sorcery/crypto_providers/md5.rb +5 -5
  47. data/lib/sorcery/crypto_providers/sha1.rb +5 -5
  48. data/lib/sorcery/crypto_providers/sha256.rb +2 -2
  49. data/lib/sorcery/crypto_providers/sha512.rb +3 -3
  50. data/lib/sorcery/engine.rb +19 -11
  51. data/lib/sorcery/model/config.rb +73 -50
  52. data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
  53. data/lib/sorcery/model/submodules/brute_force_protection.rb +38 -31
  54. data/lib/sorcery/model/submodules/external.rb +22 -10
  55. data/lib/sorcery/model/submodules/magic_login.rb +130 -0
  56. data/lib/sorcery/model/submodules/remember_me.rb +19 -7
  57. data/lib/sorcery/model/submodules/reset_password.rb +64 -42
  58. data/lib/sorcery/model/submodules/user_activation.rb +52 -54
  59. data/lib/sorcery/model/temporary_token.rb +30 -7
  60. data/lib/sorcery/model.rb +65 -40
  61. data/lib/sorcery/protocols/oauth.rb +4 -9
  62. data/lib/sorcery/protocols/oauth2.rb +0 -2
  63. data/lib/sorcery/providers/auth0.rb +46 -0
  64. data/lib/sorcery/providers/base.rb +4 -4
  65. data/lib/sorcery/providers/battlenet.rb +51 -0
  66. data/lib/sorcery/providers/discord.rb +52 -0
  67. data/lib/sorcery/providers/facebook.rb +8 -11
  68. data/lib/sorcery/providers/github.rb +5 -7
  69. data/lib/sorcery/providers/google.rb +3 -5
  70. data/lib/sorcery/providers/heroku.rb +7 -8
  71. data/lib/sorcery/providers/instagram.rb +73 -0
  72. data/lib/sorcery/providers/jira.rb +12 -17
  73. data/lib/sorcery/providers/line.rb +63 -0
  74. data/lib/sorcery/providers/linkedin.rb +44 -35
  75. data/lib/sorcery/providers/liveid.rb +4 -7
  76. data/lib/sorcery/providers/microsoft.rb +59 -0
  77. data/lib/sorcery/providers/paypal.rb +60 -0
  78. data/lib/sorcery/providers/salesforce.rb +3 -5
  79. data/lib/sorcery/providers/slack.rb +45 -0
  80. data/lib/sorcery/providers/twitter.rb +4 -6
  81. data/lib/sorcery/providers/vk.rb +8 -9
  82. data/lib/sorcery/providers/wechat.rb +81 -0
  83. data/lib/sorcery/providers/xing.rb +7 -10
  84. data/lib/sorcery/test_helpers/internal/rails.rb +25 -17
  85. data/lib/sorcery/test_helpers/internal.rb +15 -14
  86. data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
  87. data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
  88. data/lib/sorcery/test_helpers/rails/request.rb +20 -0
  89. data/lib/sorcery/version.rb +1 -1
  90. data/lib/sorcery.rb +4 -17
  91. data/sorcery.gemspec +43 -28
  92. data/spec/active_record/user_activation_spec.rb +4 -5
  93. data/spec/active_record/user_activity_logging_spec.rb +4 -6
  94. data/spec/active_record/user_brute_force_protection_spec.rb +5 -6
  95. data/spec/active_record/user_magic_login_spec.rb +15 -0
  96. data/spec/active_record/user_oauth_spec.rb +5 -6
  97. data/spec/active_record/user_remember_me_spec.rb +5 -6
  98. data/spec/active_record/user_reset_password_spec.rb +4 -5
  99. data/spec/active_record/user_spec.rb +7 -17
  100. data/spec/controllers/controller_activity_logging_spec.rb +13 -24
  101. data/spec/controllers/controller_brute_force_protection_spec.rb +8 -10
  102. data/spec/controllers/controller_http_basic_auth_spec.rb +20 -21
  103. data/spec/controllers/controller_oauth2_spec.rb +297 -158
  104. data/spec/controllers/controller_oauth_spec.rb +97 -71
  105. data/spec/controllers/controller_remember_me_spec.rb +49 -36
  106. data/spec/controllers/controller_session_timeout_spec.rb +106 -20
  107. data/spec/controllers/controller_spec.rb +87 -111
  108. data/spec/orm/active_record.rb +3 -3
  109. data/spec/providers/example_provider_spec.rb +17 -0
  110. data/spec/providers/example_spec.rb +17 -0
  111. data/spec/providers/examples_spec.rb +17 -0
  112. data/spec/providers/vk_spec.rb +42 -0
  113. data/spec/rails_app/app/active_record/authentication.rb +1 -1
  114. data/spec/rails_app/app/active_record/user.rb +2 -2
  115. data/spec/rails_app/app/assets/config/manifest.js +1 -0
  116. data/spec/rails_app/app/controllers/application_controller.rb +2 -0
  117. data/spec/rails_app/app/controllers/sorcery_controller.rb +250 -46
  118. data/spec/rails_app/app/mailers/sorcery_mailer.rb +23 -17
  119. data/spec/rails_app/app/views/sorcery_mailer/magic_login_email.html.erb +13 -0
  120. data/spec/rails_app/app/views/sorcery_mailer/magic_login_email.text.erb +6 -0
  121. data/spec/rails_app/config/application.rb +14 -9
  122. data/spec/rails_app/config/boot.rb +2 -2
  123. data/spec/rails_app/config/environment.rb +1 -1
  124. data/spec/rails_app/config/environments/test.rb +1 -1
  125. data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
  126. data/spec/rails_app/config/initializers/session_store.rb +3 -3
  127. data/spec/rails_app/config/routes.rb +31 -1
  128. data/spec/rails_app/config/secrets.yml +4 -0
  129. data/spec/rails_app/config.ru +1 -1
  130. data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +4 -4
  131. data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +10 -10
  132. data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +5 -5
  133. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +5 -5
  134. data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +3 -3
  135. data/spec/rails_app/db/migrate/invalidate_active_sessions/20180221093235_add_invalidate_active_sessions_before_to_users.rb +9 -0
  136. data/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb +17 -0
  137. data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +6 -6
  138. data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +7 -5
  139. data/spec/rails_app/db/schema.rb +7 -9
  140. data/spec/shared_examples/user_activation_shared_examples.rb +177 -58
  141. data/spec/shared_examples/user_activity_logging_shared_examples.rb +47 -41
  142. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +19 -24
  143. data/spec/shared_examples/user_magic_login_shared_examples.rb +150 -0
  144. data/spec/shared_examples/user_oauth_shared_examples.rb +7 -10
  145. data/spec/shared_examples/user_remember_me_shared_examples.rb +91 -22
  146. data/spec/shared_examples/user_reset_password_shared_examples.rb +153 -58
  147. data/spec/shared_examples/user_shared_examples.rb +328 -145
  148. data/spec/sorcery_crypto_providers_spec.rb +122 -75
  149. data/spec/sorcery_temporary_token_spec.rb +27 -0
  150. data/spec/spec.opts +1 -1
  151. data/spec/spec_helper.rb +19 -14
  152. data/spec/support/migration_helper.rb +29 -0
  153. data/spec/support/providers/example.rb +11 -0
  154. data/spec/support/providers/example_provider.rb +11 -0
  155. data/spec/support/providers/examples.rb +11 -0
  156. metadata +119 -89
  157. data/.travis.yml +0 -132
  158. data/gemfiles/active_record-rails40.gemfile +0 -7
  159. data/gemfiles/active_record-rails41.gemfile +0 -7
  160. data/gemfiles/mongo_mapper-rails40.gemfile +0 -9
  161. data/gemfiles/mongo_mapper-rails41.gemfile +0 -9
  162. data/gemfiles/mongoid-rails40.gemfile +0 -9
  163. data/gemfiles/mongoid-rails41.gemfile +0 -9
  164. data/gemfiles/mongoid3-rails32.gemfile +0 -9
  165. data/lib/sorcery/adapters/data_mapper_adapter.rb +0 -176
  166. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +0 -110
  167. data/lib/sorcery/railties/tasks.rake +0 -6
  168. data/spec/data_mapper/user_activation_spec.rb +0 -10
  169. data/spec/data_mapper/user_activity_logging_spec.rb +0 -14
  170. data/spec/data_mapper/user_brute_force_protection_spec.rb +0 -9
  171. data/spec/data_mapper/user_oauth_spec.rb +0 -9
  172. data/spec/data_mapper/user_remember_me_spec.rb +0 -8
  173. data/spec/data_mapper/user_reset_password_spec.rb +0 -8
  174. data/spec/data_mapper/user_spec.rb +0 -27
  175. data/spec/mongo_mapper/user_activation_spec.rb +0 -9
  176. data/spec/mongo_mapper/user_activity_logging_spec.rb +0 -8
  177. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +0 -8
  178. data/spec/mongo_mapper/user_oauth_spec.rb +0 -8
  179. data/spec/mongo_mapper/user_remember_me_spec.rb +0 -8
  180. data/spec/mongo_mapper/user_reset_password_spec.rb +0 -8
  181. data/spec/mongo_mapper/user_spec.rb +0 -37
  182. data/spec/mongoid/user_activation_spec.rb +0 -9
  183. data/spec/mongoid/user_activity_logging_spec.rb +0 -8
  184. data/spec/mongoid/user_brute_force_protection_spec.rb +0 -8
  185. data/spec/mongoid/user_oauth_spec.rb +0 -8
  186. data/spec/mongoid/user_remember_me_spec.rb +0 -8
  187. data/spec/mongoid/user_reset_password_spec.rb +0 -8
  188. data/spec/mongoid/user_spec.rb +0 -51
  189. data/spec/orm/data_mapper.rb +0 -48
  190. data/spec/orm/mongo_mapper.rb +0 -10
  191. data/spec/orm/mongoid.rb +0 -22
  192. data/spec/rails_app/app/data_mapper/authentication.rb +0 -8
  193. data/spec/rails_app/app/data_mapper/user.rb +0 -7
  194. data/spec/rails_app/app/mongo_mapper/authentication.rb +0 -6
  195. data/spec/rails_app/app/mongo_mapper/user.rb +0 -7
  196. data/spec/rails_app/app/mongoid/authentication.rb +0 -7
  197. data/spec/rails_app/app/mongoid/user.rb +0 -7
  198. data/spec/rails_app/config/initializers/secret_token.rb +0 -7
  199. data/spec/rails_app/log/development.log +0 -1791
@@ -1,33 +1,38 @@
1
1
  require 'oauth'
2
2
 
3
- class SorceryController < ActionController::Base
3
+ class SorceryController < ApplicationController
4
4
  protect_from_forgery
5
5
 
6
- before_filter :require_login_from_http_basic, only: [:test_http_basic_auth]
7
- before_filter :require_login, only: [:test_logout, :test_should_be_logged_in, :some_action]
6
+ before_action :require_login_from_http_basic, only: [:test_http_basic_auth]
7
+ before_action :require_login, only: %i[
8
+ test_logout
9
+ test_logout_with_forget_me
10
+ test_logout_with_force_forget_me
11
+ test_should_be_logged_in
12
+ some_action
13
+ ]
8
14
 
9
- def index
10
- end
15
+ def index; end
11
16
 
12
17
  def some_action
13
- render nothing: true
18
+ head :ok
14
19
  end
15
20
 
16
21
  def some_action_making_a_non_persisted_change_to_the_user
17
22
  current_user.email = 'to_be_ignored'
18
- render nothing: true
23
+ head :ok
19
24
  end
20
25
 
21
26
  def test_login
22
27
  @user = login(params[:email], params[:password])
23
- render nothing: true
28
+ head :ok
24
29
  end
25
30
 
26
31
  def test_auto_login
27
32
  @user = User.first
28
33
  auto_login(@user)
29
34
  @result = current_user
30
- render nothing: true
35
+ head :ok
31
36
  end
32
37
 
33
38
  def test_return_to
@@ -37,50 +42,69 @@ class SorceryController < ActionController::Base
37
42
 
38
43
  def test_logout
39
44
  logout
40
- render nothing: true
45
+ head :ok
41
46
  end
42
47
 
43
48
  def test_logout_with_remember
44
49
  remember_me!
45
50
  logout
46
- render nothing: true
51
+ head :ok
52
+ end
53
+
54
+ def test_logout_with_forget_me
55
+ remember_me!
56
+ forget_me!
57
+ logout
58
+ head :ok
59
+ end
60
+
61
+ def test_logout_with_force_forget_me
62
+ remember_me!
63
+ force_forget_me!
64
+ logout
65
+ head :ok
66
+ end
67
+
68
+ def test_invalidate_active_session
69
+ invalidate_active_sessions!
70
+ head :ok
47
71
  end
48
72
 
49
73
  def test_login_with_remember
50
74
  @user = login(params[:email], params[:password])
51
75
  remember_me!
52
76
 
53
- render nothing: true
77
+ head :ok
54
78
  end
55
79
 
56
80
  def test_login_with_remember_in_login
57
81
  @user = login(params[:email], params[:password], params[:remember])
58
82
 
59
- render nothing: true
83
+ head :ok
60
84
  end
61
85
 
62
86
  def test_login_from_cookie
63
87
  @user = current_user
64
- render nothing: true
88
+ head :ok
65
89
  end
66
90
 
67
91
  def test_not_authenticated_action
68
- render text: 'test_not_authenticated_action'
92
+ head :ok
69
93
  end
70
94
 
71
95
  def test_should_be_logged_in
72
- render nothing: true
96
+ head :ok
73
97
  end
74
98
 
75
99
  def test_http_basic_auth
76
- render text: 'HTTP Basic Auth'
100
+ head :ok
77
101
  end
78
102
 
79
103
  def login_at_test_twitter
80
104
  login_at(:twitter)
81
105
  end
82
106
 
83
- alias :login_at_test :login_at_test_twitter
107
+ alias login_at_test login_at_test_twitter
84
108
 
85
109
  def login_at_test_facebook
86
110
  login_at(:facebook)
@@ -90,6 +114,18 @@ class SorceryController < ActionController::Base
90
114
  login_at(:github)
91
115
  end
92
116
 
117
+ def login_at_test_paypal
118
+ login_at(:paypal)
119
+ end
120
+
121
+ def login_at_test_wechat
122
+ login_at(:wechat)
123
+ end
124
+
125
+ def login_at_test_microsoft
126
+ login_at(:microsoft)
127
+ end
128
+
93
129
  def login_at_test_google
94
130
  login_at(:google)
95
131
  end
@@ -110,22 +146,46 @@ class SorceryController < ActionController::Base
110
146
  login_at(:salesforce)
111
147
  end
112
148
 
149
+ def login_at_test_slack
150
+ login_at(:slack)
151
+ end
152
+
153
+ def login_at_test_line
154
+ login_at(:line)
155
+ end
156
+
113
157
  def login_at_test_with_state
114
- login_at(:facebook, {state: 'bla'})
158
+ login_at(:facebook, state: 'bla')
159
+ end
160
+
161
+ def login_at_test_instagram
162
+ login_at(:instagram)
163
+ end
164
+
165
+ def login_at_test_auth0
166
+ login_at(:auth0)
167
+ end
168
+
169
+ def login_at_test_discord
170
+ login_at(:discord)
171
+ end
172
+
173
+ def login_at_test_battlenet
174
+ login_at(:battlenet)
115
175
  end
116
176
 
117
177
  def test_login_from_twitter
118
- if @user = login_from(:twitter)
178
+ if (@user = login_from(:twitter))
119
179
  redirect_to 'bla', notice: 'Success!'
120
180
  else
121
181
  redirect_to 'blu', alert: 'Failed!'
122
182
  end
123
183
  end
124
184
 
125
- alias :test_login_from :test_login_from_twitter
185
+ alias test_login_from test_login_from_twitter
126
186
 
127
187
  def test_login_from_facebook
128
- if @user = login_from(:facebook)
188
+ if (@user = login_from(:facebook))
129
189
  redirect_to 'bla', notice: 'Success!'
130
190
  else
131
191
  redirect_to 'blu', alert: 'Failed!'
@@ -133,7 +193,31 @@ class SorceryController < ActionController::Base
133
193
  end
134
194
 
135
195
  def test_login_from_github
136
- if @user = login_from(:github)
196
+ if (@user = login_from(:github))
197
+ redirect_to 'bla', notice: 'Success!'
198
+ else
199
+ redirect_to 'blu', alert: 'Failed!'
200
+ end
201
+ end
202
+
203
+ def test_login_from_paypal
204
+ if (@user = login_from(:paypal))
205
+ redirect_to 'bla', notice: 'Success!'
206
+ else
207
+ redirect_to 'blu', alert: 'Failed!'
208
+ end
209
+ end
210
+
211
+ def test_login_from_wechat
212
+ if (@user = login_from(:wechat))
213
+ redirect_to 'bla', notice: 'Success!'
214
+ else
215
+ redirect_to 'blu', alert: 'Failed!'
216
+ end
217
+ end
218
+
219
+ def test_login_from_microsoft
220
+ if (@user = login_from(:microsoft))
137
221
  redirect_to 'bla', notice: 'Success!'
138
222
  else
139
223
  redirect_to 'blu', alert: 'Failed!'
@@ -141,7 +225,7 @@ class SorceryController < ActionController::Base
141
225
  end
142
226
 
143
227
  def test_login_from_google
144
- if @user = login_from(:google)
228
+ if (@user = login_from(:google))
145
229
  redirect_to 'bla', notice: 'Success!'
146
230
  else
147
231
  redirect_to 'blu', alert: 'Failed!'
@@ -149,7 +233,7 @@ class SorceryController < ActionController::Base
149
233
  end
150
234
 
151
235
  def test_login_from_liveid
152
- if @user = login_from(:liveid)
236
+ if (@user = login_from(:liveid))
153
237
  redirect_to 'bla', notice: 'Success!'
154
238
  else
155
239
  redirect_to 'blu', alert: 'Failed!'
@@ -157,7 +241,7 @@ class SorceryController < ActionController::Base
157
241
  end
158
242
 
159
243
  def test_login_from_vk
160
- if @user = login_from(:vk)
244
+ if (@user = login_from(:vk))
161
245
  redirect_to 'bla', notice: 'Success!'
162
246
  else
163
247
  redirect_to 'blu', alert: 'Failed!'
@@ -165,7 +249,7 @@ class SorceryController < ActionController::Base
165
249
  end
166
250
 
167
251
  def test_login_from_jira
168
- if @user = login_from(:jira)
252
+ if (@user = login_from(:jira))
169
253
  redirect_to 'bla', notice: 'Success!'
170
254
  else
171
255
  redirect_to 'blu', alert: 'Failed!'
@@ -173,7 +257,55 @@ class SorceryController < ActionController::Base
173
257
  end
174
258
 
175
259
  def test_login_from_salesforce
176
- if @user = login_from(:salesforce)
260
+ if (@user = login_from(:salesforce))
261
+ redirect_to 'bla', notice: 'Success!'
262
+ else
263
+ redirect_to 'blu', alert: 'Failed!'
264
+ end
265
+ end
266
+
267
+ def test_login_from_slack
268
+ if (@user = login_from(:slack))
269
+ redirect_to 'bla', notice: 'Success!'
270
+ else
271
+ redirect_to 'blu', alert: 'Failed!'
272
+ end
273
+ end
274
+
275
+ def test_login_from_instagram
276
+ if (@user = login_from(:instagram))
277
+ redirect_to 'bla', notice: 'Success!'
278
+ else
279
+ redirect_to 'blu', alert: 'Failed!'
280
+ end
281
+ end
282
+
283
+ def test_login_from_auth0
284
+ if (@user = login_from(:auth0))
285
+ redirect_to 'bla', notice: 'Success!'
286
+ else
287
+ redirect_to 'blu', alert: 'Failed!'
288
+ end
289
+ end
290
+
291
+ def test_login_from_line
292
+ if @user = login_from(:line)
293
+ redirect_to 'bla', notice: 'Success!'
294
+ else
295
+ redirect_to 'blu', alert: 'Failed!'
296
+ end
297
+ end
298
+
299
+ def test_login_from_discord
300
+ if (@user = login_from(:discord))
301
+ redirect_to 'bla', notice: 'Success!'
302
+ else
303
+ redirect_to 'blu', alert: 'Failed!'
304
+ end
305
+ end
306
+
307
+ def test_login_from_battlenet
308
+ if (@user = login_from(:battlenet))
177
309
  redirect_to 'bla', notice: 'Success!'
178
310
  else
179
311
  redirect_to 'blu', alert: 'Failed!'
@@ -181,7 +313,7 @@ class SorceryController < ActionController::Base
181
313
  end
182
314
 
183
315
  def test_return_to_with_external_twitter
184
- if @user = login_from(:twitter)
316
+ if (@user = login_from(:twitter))
185
317
  redirect_back_or_to 'bla', notice: 'Success!'
186
318
  else
187
319
  redirect_to 'blu', alert: 'Failed!'
@@ -189,17 +321,17 @@ class SorceryController < ActionController::Base
189
321
  end
190
322
 
191
323
  def test_return_to_with_external_jira
192
- if @user = login_from(:jira)
324
+ if (@user = login_from(:jira))
193
325
  redirect_back_or_to 'bla', notice: 'Success!'
194
326
  else
195
327
  redirect_to 'blu', alert: 'Failed!'
196
328
  end
197
329
  end
198
330
 
199
- alias :test_return_to_with_external :test_return_to_with_external_twitter
331
+ alias test_return_to_with_external test_return_to_with_external_twitter
200
332
 
201
333
  def test_return_to_with_external_facebook
202
- if @user = login_from(:facebook)
334
+ if (@user = login_from(:facebook))
203
335
  redirect_back_or_to 'bla', notice: 'Success!'
204
336
  else
205
337
  redirect_to 'blu', alert: 'Failed!'
@@ -207,7 +339,31 @@ class SorceryController < ActionController::Base
207
339
  end
208
340
 
209
341
  def test_return_to_with_external_github
210
- if @user = login_from(:github)
342
+ if (@user = login_from(:github))
343
+ redirect_back_or_to 'bla', notice: 'Success!'
344
+ else
345
+ redirect_to 'blu', alert: 'Failed!'
346
+ end
347
+ end
348
+
349
+ def test_return_to_with_external_paypal
350
+ if (@user = login_from(:paypal))
351
+ redirect_back_or_to 'bla', notice: 'Success!'
352
+ else
353
+ redirect_to 'blu', alert: 'Failed!'
354
+ end
355
+ end
356
+
357
+ def test_return_to_with_external_wechat
358
+ if (@user = login_from(:wechat))
359
+ redirect_back_or_to 'bla', notice: 'Success!'
360
+ else
361
+ redirect_to 'blu', alert: 'Failed!'
362
+ end
363
+ end
364
+
365
+ def test_return_to_with_external_microsoft
366
+ if (@user = login_from(:microsoft))
211
367
  redirect_back_or_to 'bla', notice: 'Success!'
212
368
  else
213
369
  redirect_to 'blu', alert: 'Failed!'
@@ -215,7 +371,7 @@ class SorceryController < ActionController::Base
215
371
  end
216
372
 
217
373
  def test_return_to_with_external_google
218
- if @user = login_from(:google)
374
+ if (@user = login_from(:google))
219
375
  redirect_back_or_to 'bla', notice: 'Success!'
220
376
  else
221
377
  redirect_to 'blu', alert: 'Failed!'
@@ -223,7 +379,7 @@ class SorceryController < ActionController::Base
223
379
  end
224
380
 
225
381
  def test_return_to_with_external_liveid
226
- if @user = login_from(:liveid)
382
+ if (@user = login_from(:liveid))
227
383
  redirect_back_or_to 'bla', notice: 'Success!'
228
384
  else
229
385
  redirect_to 'blu', alert: 'Failed!'
@@ -231,7 +387,7 @@ class SorceryController < ActionController::Base
231
387
  end
232
388
 
233
389
  def test_return_to_with_external_vk
234
- if @user = login_from(:vk)
390
+ if (@user = login_from(:vk))
235
391
  redirect_back_or_to 'bla', notice: 'Success!'
236
392
  else
237
393
  redirect_to 'blu', alert: 'Failed!'
@@ -239,7 +395,55 @@ class SorceryController < ActionController::Base
239
395
  end
240
396
 
241
397
  def test_return_to_with_external_salesforce
242
- if @user = login_from(:salesforce)
398
+ if (@user = login_from(:salesforce))
399
+ redirect_back_or_to 'bla', notice: 'Success!'
400
+ else
401
+ redirect_to 'blu', alert: 'Failed!'
402
+ end
403
+ end
404
+
405
+ def test_return_to_with_external_slack
406
+ if (@user = login_from(:slack))
407
+ redirect_back_or_to 'bla', notice: 'Success!'
408
+ else
409
+ redirect_to 'blu', alert: 'Failed!'
410
+ end
411
+ end
412
+
413
+ def test_return_to_with_external_instagram
414
+ if (@user = login_from(:instagram))
415
+ redirect_back_or_to 'bla', notice: 'Success!'
416
+ else
417
+ redirect_to 'blu', alert: 'Failed!'
418
+ end
419
+ end
420
+
421
+ def test_return_to_with_external_auth0
422
+ if (@user = login_from(:auth0))
423
+ redirect_back_or_to 'bla', notice: 'Success!'
424
+ else
425
+ redirect_to 'blu', alert: 'Failed!'
426
+ end
427
+ end
428
+
429
+ def test_return_to_with_external_line
430
+ if @user = login_from(:line)
431
+ redirect_back_or_to 'bla', notice: 'Success!'
432
+ else
433
+ redirect_to 'blu', alert: 'Failed!'
434
+ end
435
+ end
436
+
437
+ def test_return_to_with_external_discord
438
+ if (@user = login_from(:discord))
439
+ redirect_back_or_to 'bla', notice: 'Success!'
440
+ else
441
+ redirect_to 'blu', alert: 'Failed!'
442
+ end
443
+ end
444
+
445
+ def test_return_to_with_external_battlenet
446
+ if (@user = login_from(:battlenet))
243
447
  redirect_back_or_to 'bla', notice: 'Success!'
244
448
  else
245
449
  redirect_to 'blu', alert: 'Failed!'
@@ -249,7 +453,7 @@ class SorceryController < ActionController::Base
249
453
  def test_create_from_provider
250
454
  provider = params[:provider]
251
455
  login_from(provider)
252
- if @user = create_from(provider)
456
+ if (@user = create_from(provider))
253
457
  redirect_to 'bla', notice: 'Success!'
254
458
  else
255
459
  redirect_to 'blu', alert: 'Failed!'
@@ -258,19 +462,20 @@ class SorceryController < ActionController::Base
258
462
 
259
463
  def test_add_second_provider
260
464
  provider = params[:provider]
261
- if logged_in?
262
- if @user = add_provider_to_user(provider)
263
- redirect_to "bla", :notice => "Success!"
264
- else
265
- redirect_to "blu", :alert => "Failed!"
266
- end
465
+
466
+ return unless logged_in?
467
+
468
+ if (@user = add_provider_to_user(provider))
469
+ redirect_to 'bla', notice: 'Success!'
470
+ else
471
+ redirect_to 'blu', alert: 'Failed!'
267
472
  end
268
473
  end
269
474
 
270
475
  def test_create_from_provider_with_block
271
476
  provider = params[:provider]
272
477
  login_from(provider)
273
- @user = create_from(provider) do |user|
478
+ @user = create_from(provider) do |_user|
274
479
  # check uniqueness of email
275
480
  # User.where(email: user.email).empty?
276
481
  false
@@ -281,5 +486,4 @@ class SorceryController < ActionController::Base
281
486
  redirect_to 'blu', alert: 'Failed!'
282
487
  end
283
488
  end
284
-
285
489
  end
@@ -1,32 +1,38 @@
1
1
  class SorceryMailer < ActionMailer::Base
2
-
3
- default :from => "notifications@example.com"
4
-
2
+ default from: 'notifications@example.com'
3
+
5
4
  def activation_needed_email(user)
6
5
  @user = user
7
- @url = "http://example.com/login"
8
- mail(:to => user.email,
9
- :subject => "Welcome to My Awesome Site")
6
+ @url = 'http://example.com/login'
7
+ mail(to: user.email,
8
+ subject: 'Welcome to My Awesome Site')
10
9
  end
11
-
10
+
12
11
  def activation_success_email(user)
13
12
  @user = user
14
- @url = "http://example.com/login"
15
- mail(:to => user.email,
16
- :subject => "Your account is now activated")
13
+ @url = 'http://example.com/login'
14
+ mail(to: user.email,
15
+ subject: 'Your account is now activated')
17
16
  end
18
-
17
+
19
18
  def reset_password_email(user)
20
19
  @user = user
21
- @url = "http://example.com/login"
22
- mail(:to => user.email,
23
- :subject => "Your password has been reset")
20
+ @url = 'http://example.com/login'
21
+ mail(to: user.email,
22
+ subject: 'Your password has been reset')
24
23
  end
25
24
 
26
25
  def send_unlock_token_email(user)
27
26
  @user = user
28
27
  @url = "http://example.com/unlock/#{user.unlock_token}"
29
- mail(:to => user.email,
30
- :subject => "Your account has been locked due to many wrong logins")
28
+ mail(to: user.email,
29
+ subject: 'Your account has been locked due to many wrong logins')
30
+ end
31
+
32
+ def magic_login_email(user)
33
+ @user = user
34
+ @url = 'http://example.com/login'
35
+ mail(to: user.email,
36
+ subject: 'Magic Login')
31
37
  end
32
- end
38
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5
+ </head>
6
+ <body>
7
+ <h1>Hello, <%= @user.username %></h1>
8
+ <p>
9
+ To login without a password, just follow this link: <%= @url %>.
10
+ </p>
11
+ <p>Have a great day!</p>
12
+ </body>
13
+ </html>
@@ -0,0 +1,6 @@
1
+ Hello, <%= @user.username %>
2
+ ===============================================
3
+
4
+ To login without a password, just follow this link: <%= @url %>.
5
+
6
+ Have a great day!
@@ -1,22 +1,25 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
- require "action_controller/railtie"
4
- require "action_mailer/railtie"
5
- require "rails/test_unit/railtie"
3
+ require 'action_controller/railtie'
4
+ require 'action_mailer/railtie'
5
+ require 'rails/test_unit/railtie'
6
6
 
7
7
  Bundler.require :default, SORCERY_ORM
8
8
 
9
+ # rubocop:disable Lint/HandleExceptions
9
10
  begin
10
11
  require "#{SORCERY_ORM}/railtie"
11
12
  rescue LoadError
13
+ # TODO: Log this issue or change require scheme.
12
14
  end
15
+ # rubocop:enable Lint/HandleExceptions
13
16
 
14
- require "sorcery"
17
+ require 'sorcery'
15
18
 
16
19
  module AppRoot
17
20
  class Application < Rails::Application
18
- config.autoload_paths.reject!{ |p| p =~ /\/app\/(\w+)$/ && !%w(controllers helpers mailers views).include?($1) }
19
- config.autoload_paths += [ "#{config.root}/app/#{SORCERY_ORM}" ]
21
+ config.autoload_paths.reject! { |p| p =~ %r{/\/app\/(\w+)$/} && !%w[controllers helpers mailers views].include?(Regexp.last_match(1)) }
22
+ config.autoload_paths += ["#{config.root}/app/#{SORCERY_ORM}"]
20
23
 
21
24
  # Settings in config/environments/* take precedence over those specified here.
22
25
  # Application configuration should go into files in config/initializers
@@ -44,13 +47,15 @@ module AppRoot
44
47
  # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
45
48
 
46
49
  # Configure the default encoding used in templates for Ruby 1.9.
47
- config.encoding = "utf-8"
50
+ config.encoding = 'utf-8'
48
51
 
49
52
  # Configure sensitive parameters which will be filtered from the log file.
50
53
  config.filter_parameters += [:password]
51
54
 
52
55
  config.action_mailer.delivery_method = :test
53
-
54
56
  config.active_support.deprecation = :stderr
57
+ if Rails.version >= '5.1.0' && config.active_record.sqlite3.present?
58
+ config.active_record.sqlite3.represent_boolean_as_integer = true
59
+ end
55
60
  end
56
61
  end
@@ -1,4 +1,4 @@
1
1
  # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
3
 
4
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -1,5 +1,5 @@
1
1
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
2
+ require File.expand_path('application', __dir__)
3
3
 
4
4
  # Initialize the rails application
5
5
  AppRoot::Application.initialize!
@@ -18,7 +18,7 @@ AppRoot::Application.configure do
18
18
  config.action_dispatch.show_exceptions = false
19
19
 
20
20
  # Disable request forgery protection in test environment
21
- config.action_controller.allow_forgery_protection = false
21
+ config.action_controller.allow_forgery_protection = false
22
22
 
23
23
  # Tell Action Mailer not to deliver emails to the real world.
24
24
  # The :test delivery method accumulates sent emails in the
@@ -0,0 +1,11 @@
1
+ module ActiveRecord
2
+ module CompatibleLegacyMigration
3
+ def self.migration_class
4
+ if Rails::VERSION::MAJOR >= 5
5
+ ActiveRecord::Migration::Current
6
+ else
7
+ ActiveRecord::Migration
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- AppRoot::Application.config.session_store :cookie_store, :key => '_app_root_session'
3
+ AppRoot::Application.config.session_store :cookie_store, key: '_app_root_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -8,5 +8,5 @@ AppRoot::Application.config.session_store :cookie_store, :key => '_app_root_sess
8
8
  # AppRoot::Application.config.session_store :active_record_store
9
9
 
10
10
  if AppRoot::Application.config.respond_to?(:secret_key_base=)
11
- AppRoot::Application.config.secret_key_base = "foobar"
12
- end
11
+ AppRoot::Application.config.secret_key_base = 'foobar'
12
+ end