sorcery 0.9.1 → 0.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.github/ISSUE_TEMPLATE.md +24 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +7 -0
- data/.github/workflows/ruby.yml +70 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +55 -0
- data/.rubocop_todo.yml +163 -0
- data/CHANGELOG.md +132 -34
- data/CODE_OF_CONDUCT.md +14 -0
- data/Gemfile +3 -17
- data/{LICENSE.txt → LICENSE.md} +1 -1
- data/MAINTAINING.md +64 -0
- data/README.md +146 -269
- data/Rakefile +4 -2
- data/SECURITY.md +19 -0
- data/gemfiles/rails_52.gemfile +7 -0
- data/gemfiles/rails_60.gemfile +7 -0
- data/gemfiles/rails_61.gemfile +7 -0
- data/gemfiles/rails_70.gemfile +7 -0
- data/lib/generators/sorcery/USAGE +1 -1
- data/lib/generators/sorcery/helpers.rb +8 -4
- data/lib/generators/sorcery/install_generator.rb +41 -35
- data/lib/generators/sorcery/templates/initializer.rb +216 -112
- data/lib/generators/sorcery/templates/migration/activity_logging.rb +7 -7
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +5 -5
- data/lib/generators/sorcery/templates/migration/core.rb +5 -7
- data/lib/generators/sorcery/templates/migration/external.rb +4 -4
- data/lib/generators/sorcery/templates/migration/magic_login.rb +9 -0
- data/lib/generators/sorcery/templates/migration/remember_me.rb +5 -5
- data/lib/generators/sorcery/templates/migration/reset_password.rb +7 -6
- data/lib/generators/sorcery/templates/migration/user_activation.rb +6 -6
- data/lib/sorcery/adapters/active_record_adapter.rb +11 -21
- data/lib/sorcery/adapters/mongoid_adapter.rb +23 -11
- data/lib/sorcery/controller/config.rb +27 -23
- data/lib/sorcery/controller/submodules/activity_logging.rb +16 -18
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
- data/lib/sorcery/controller/submodules/external.rb +69 -44
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +18 -19
- data/lib/sorcery/controller/submodules/remember_me.rb +16 -16
- data/lib/sorcery/controller/submodules/session_timeout.rb +33 -11
- data/lib/sorcery/controller.rb +50 -35
- data/lib/sorcery/crypto_providers/aes256.rb +17 -16
- data/lib/sorcery/crypto_providers/bcrypt.rb +26 -22
- data/lib/sorcery/crypto_providers/common.rb +1 -1
- data/lib/sorcery/crypto_providers/md5.rb +5 -5
- data/lib/sorcery/crypto_providers/sha1.rb +5 -5
- data/lib/sorcery/crypto_providers/sha256.rb +2 -2
- data/lib/sorcery/crypto_providers/sha512.rb +3 -3
- data/lib/sorcery/engine.rb +19 -11
- data/lib/sorcery/model/config.rb +73 -50
- data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
- data/lib/sorcery/model/submodules/brute_force_protection.rb +38 -31
- data/lib/sorcery/model/submodules/external.rb +22 -10
- data/lib/sorcery/model/submodules/magic_login.rb +130 -0
- data/lib/sorcery/model/submodules/remember_me.rb +19 -7
- data/lib/sorcery/model/submodules/reset_password.rb +64 -42
- data/lib/sorcery/model/submodules/user_activation.rb +52 -54
- data/lib/sorcery/model/temporary_token.rb +30 -7
- data/lib/sorcery/model.rb +65 -40
- data/lib/sorcery/protocols/oauth.rb +4 -9
- data/lib/sorcery/protocols/oauth2.rb +0 -2
- data/lib/sorcery/providers/auth0.rb +46 -0
- data/lib/sorcery/providers/base.rb +4 -4
- data/lib/sorcery/providers/battlenet.rb +51 -0
- data/lib/sorcery/providers/discord.rb +52 -0
- data/lib/sorcery/providers/facebook.rb +8 -11
- data/lib/sorcery/providers/github.rb +5 -7
- data/lib/sorcery/providers/google.rb +3 -5
- data/lib/sorcery/providers/heroku.rb +7 -8
- data/lib/sorcery/providers/instagram.rb +73 -0
- data/lib/sorcery/providers/jira.rb +12 -17
- data/lib/sorcery/providers/line.rb +63 -0
- data/lib/sorcery/providers/linkedin.rb +44 -35
- data/lib/sorcery/providers/liveid.rb +4 -7
- data/lib/sorcery/providers/microsoft.rb +59 -0
- data/lib/sorcery/providers/paypal.rb +60 -0
- data/lib/sorcery/providers/salesforce.rb +3 -5
- data/lib/sorcery/providers/slack.rb +45 -0
- data/lib/sorcery/providers/twitter.rb +4 -6
- data/lib/sorcery/providers/vk.rb +8 -9
- data/lib/sorcery/providers/wechat.rb +81 -0
- data/lib/sorcery/providers/xing.rb +7 -10
- data/lib/sorcery/test_helpers/internal/rails.rb +25 -17
- data/lib/sorcery/test_helpers/internal.rb +15 -14
- data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
- data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
- data/lib/sorcery/test_helpers/rails/request.rb +20 -0
- data/lib/sorcery/version.rb +1 -1
- data/lib/sorcery.rb +4 -17
- data/sorcery.gemspec +43 -28
- data/spec/active_record/user_activation_spec.rb +4 -5
- data/spec/active_record/user_activity_logging_spec.rb +4 -6
- data/spec/active_record/user_brute_force_protection_spec.rb +5 -6
- data/spec/active_record/user_magic_login_spec.rb +15 -0
- data/spec/active_record/user_oauth_spec.rb +5 -6
- data/spec/active_record/user_remember_me_spec.rb +5 -6
- data/spec/active_record/user_reset_password_spec.rb +4 -5
- data/spec/active_record/user_spec.rb +7 -17
- data/spec/controllers/controller_activity_logging_spec.rb +13 -24
- data/spec/controllers/controller_brute_force_protection_spec.rb +8 -10
- data/spec/controllers/controller_http_basic_auth_spec.rb +20 -21
- data/spec/controllers/controller_oauth2_spec.rb +297 -158
- data/spec/controllers/controller_oauth_spec.rb +97 -71
- data/spec/controllers/controller_remember_me_spec.rb +49 -36
- data/spec/controllers/controller_session_timeout_spec.rb +106 -20
- data/spec/controllers/controller_spec.rb +87 -111
- data/spec/orm/active_record.rb +3 -3
- data/spec/providers/example_provider_spec.rb +17 -0
- data/spec/providers/example_spec.rb +17 -0
- data/spec/providers/examples_spec.rb +17 -0
- data/spec/providers/vk_spec.rb +42 -0
- data/spec/rails_app/app/active_record/authentication.rb +1 -1
- data/spec/rails_app/app/active_record/user.rb +2 -2
- data/spec/rails_app/app/assets/config/manifest.js +1 -0
- data/spec/rails_app/app/controllers/application_controller.rb +2 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +250 -46
- data/spec/rails_app/app/mailers/sorcery_mailer.rb +23 -17
- data/spec/rails_app/app/views/sorcery_mailer/magic_login_email.html.erb +13 -0
- data/spec/rails_app/app/views/sorcery_mailer/magic_login_email.text.erb +6 -0
- data/spec/rails_app/config/application.rb +14 -9
- data/spec/rails_app/config/boot.rb +2 -2
- data/spec/rails_app/config/environment.rb +1 -1
- data/spec/rails_app/config/environments/test.rb +1 -1
- data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
- data/spec/rails_app/config/initializers/session_store.rb +3 -3
- data/spec/rails_app/config/routes.rb +31 -1
- data/spec/rails_app/config/secrets.yml +4 -0
- data/spec/rails_app/config.ru +1 -1
- data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +4 -4
- data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +10 -10
- data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +5 -5
- data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +5 -5
- data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +3 -3
- data/spec/rails_app/db/migrate/invalidate_active_sessions/20180221093235_add_invalidate_active_sessions_before_to_users.rb +9 -0
- data/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb +17 -0
- data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +6 -6
- data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +7 -5
- data/spec/rails_app/db/schema.rb +7 -9
- data/spec/shared_examples/user_activation_shared_examples.rb +177 -58
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +47 -41
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +19 -24
- data/spec/shared_examples/user_magic_login_shared_examples.rb +150 -0
- data/spec/shared_examples/user_oauth_shared_examples.rb +7 -10
- data/spec/shared_examples/user_remember_me_shared_examples.rb +91 -22
- data/spec/shared_examples/user_reset_password_shared_examples.rb +153 -58
- data/spec/shared_examples/user_shared_examples.rb +328 -145
- data/spec/sorcery_crypto_providers_spec.rb +122 -75
- data/spec/sorcery_temporary_token_spec.rb +27 -0
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +19 -14
- data/spec/support/migration_helper.rb +29 -0
- data/spec/support/providers/example.rb +11 -0
- data/spec/support/providers/example_provider.rb +11 -0
- data/spec/support/providers/examples.rb +11 -0
- metadata +119 -89
- data/.travis.yml +0 -132
- data/gemfiles/active_record-rails40.gemfile +0 -7
- data/gemfiles/active_record-rails41.gemfile +0 -7
- data/gemfiles/mongo_mapper-rails40.gemfile +0 -9
- data/gemfiles/mongo_mapper-rails41.gemfile +0 -9
- data/gemfiles/mongoid-rails40.gemfile +0 -9
- data/gemfiles/mongoid-rails41.gemfile +0 -9
- data/gemfiles/mongoid3-rails32.gemfile +0 -9
- data/lib/sorcery/adapters/data_mapper_adapter.rb +0 -176
- data/lib/sorcery/adapters/mongo_mapper_adapter.rb +0 -110
- data/lib/sorcery/railties/tasks.rake +0 -6
- data/spec/data_mapper/user_activation_spec.rb +0 -10
- data/spec/data_mapper/user_activity_logging_spec.rb +0 -14
- data/spec/data_mapper/user_brute_force_protection_spec.rb +0 -9
- data/spec/data_mapper/user_oauth_spec.rb +0 -9
- data/spec/data_mapper/user_remember_me_spec.rb +0 -8
- data/spec/data_mapper/user_reset_password_spec.rb +0 -8
- data/spec/data_mapper/user_spec.rb +0 -27
- data/spec/mongo_mapper/user_activation_spec.rb +0 -9
- data/spec/mongo_mapper/user_activity_logging_spec.rb +0 -8
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +0 -8
- data/spec/mongo_mapper/user_oauth_spec.rb +0 -8
- data/spec/mongo_mapper/user_remember_me_spec.rb +0 -8
- data/spec/mongo_mapper/user_reset_password_spec.rb +0 -8
- data/spec/mongo_mapper/user_spec.rb +0 -37
- data/spec/mongoid/user_activation_spec.rb +0 -9
- data/spec/mongoid/user_activity_logging_spec.rb +0 -8
- data/spec/mongoid/user_brute_force_protection_spec.rb +0 -8
- data/spec/mongoid/user_oauth_spec.rb +0 -8
- data/spec/mongoid/user_remember_me_spec.rb +0 -8
- data/spec/mongoid/user_reset_password_spec.rb +0 -8
- data/spec/mongoid/user_spec.rb +0 -51
- data/spec/orm/data_mapper.rb +0 -48
- data/spec/orm/mongo_mapper.rb +0 -10
- data/spec/orm/mongoid.rb +0 -22
- data/spec/rails_app/app/data_mapper/authentication.rb +0 -8
- data/spec/rails_app/app/data_mapper/user.rb +0 -7
- data/spec/rails_app/app/mongo_mapper/authentication.rb +0 -6
- data/spec/rails_app/app/mongo_mapper/user.rb +0 -7
- data/spec/rails_app/app/mongoid/authentication.rb +0 -7
- data/spec/rails_app/app/mongoid/user.rb +0 -7
- data/spec/rails_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails_app/log/development.log +0 -1791
@@ -1,33 +1,38 @@
|
|
1
1
|
require 'oauth'
|
2
2
|
|
3
|
-
class SorceryController <
|
3
|
+
class SorceryController < ApplicationController
|
4
4
|
protect_from_forgery
|
5
5
|
|
6
|
-
|
7
|
-
|
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
|
-
|
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
|
-
|
23
|
+
head :ok
|
19
24
|
end
|
20
25
|
|
21
26
|
def test_login
|
22
27
|
@user = login(params[:email], params[:password])
|
23
|
-
|
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
|
-
|
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
|
-
|
45
|
+
head :ok
|
41
46
|
end
|
42
47
|
|
43
48
|
def test_logout_with_remember
|
44
49
|
remember_me!
|
45
50
|
logout
|
46
|
-
|
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
|
-
|
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
|
-
|
83
|
+
head :ok
|
60
84
|
end
|
61
85
|
|
62
86
|
def test_login_from_cookie
|
63
87
|
@user = current_user
|
64
|
-
|
88
|
+
head :ok
|
65
89
|
end
|
66
90
|
|
67
91
|
def test_not_authenticated_action
|
68
|
-
|
92
|
+
head :ok
|
69
93
|
end
|
70
94
|
|
71
95
|
def test_should_be_logged_in
|
72
|
-
|
96
|
+
head :ok
|
73
97
|
end
|
74
98
|
|
75
99
|
def test_http_basic_auth
|
76
|
-
|
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
|
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,
|
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
|
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
|
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
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
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 |
|
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
|
-
|
4
|
-
|
2
|
+
default from: 'notifications@example.com'
|
3
|
+
|
5
4
|
def activation_needed_email(user)
|
6
5
|
@user = user
|
7
|
-
@url =
|
8
|
-
mail(:
|
9
|
-
:
|
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 =
|
15
|
-
mail(:
|
16
|
-
:
|
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 =
|
22
|
-
mail(:
|
23
|
-
:
|
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(:
|
30
|
-
:
|
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>
|
@@ -1,22 +1,25 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('boot', __dir__)
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
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
|
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
|
19
|
-
config.autoload_paths += [
|
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 =
|
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('
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
|
3
3
|
|
4
|
-
require 'bundler/setup' if File.
|
4
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
@@ -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
|
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
|
@@ -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, :
|
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 =
|
12
|
-
end
|
11
|
+
AppRoot::Application.config.secret_key_base = 'foobar'
|
12
|
+
end
|