quo_vadis 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +22 -3
- data/app/controllers/quo_vadis/confirmations_controller.rb +47 -1
- data/app/controllers/quo_vadis/sessions_controller.rb +1 -1
- data/config/routes.rb +7 -1
- data/lib/quo_vadis.rb +5 -1
- data/lib/quo_vadis/controller.rb +1 -0
- data/lib/quo_vadis/version.rb +1 -1
- data/test/dummy/app/controllers/sign_ups_controller.rb +1 -1
- data/test/dummy/app/views/quo_vadis/confirmations/edit_email.html.erb +14 -0
- data/test/dummy/app/views/quo_vadis/confirmations/index.html.erb +11 -2
- data/test/integration/account_confirmation_test.rb +35 -2
- data/test/integration/logging_test.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aca902d10c618abd2c9c0461aac204236b4ef7565911aafb5bb12dfe1e3b25e1
|
4
|
+
data.tar.gz: 3417365d9ca59d5e17a1b28118d3c9ec439b77fb228da9968512786dd3797a12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ffdeced9bd86b0a64fe21f3491f3ad03cb2098f0687b663ab794c37e278383ad235df856d8a18bf8e73108d602661990992dd033cbc1358849b8824ac25aff6
|
7
|
+
data.tar.gz: 59c52478f7a5bc8ee0befe682ee520feec894c6fefe875cc84395e827ae62f9cbf5eb588862cf8eb3888b5b0ba102700b61f5d401156dc9eff893e05307d1787
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
3
|
|
4
|
+
## HEAD
|
5
|
+
|
6
|
+
|
7
|
+
## 2.0.2 (24 May 2021)
|
8
|
+
|
9
|
+
* Account confirmation: enable updating of email address.
|
10
|
+
* Account confirmation: enable direct resending of email.
|
11
|
+
* Log unknown identifier in metadata.
|
12
|
+
|
13
|
+
|
4
14
|
## 2.0.1 (18 May 2021)
|
5
15
|
|
6
16
|
* Remove Gemfile.lock from repo.
|
data/README.md
CHANGED
@@ -232,7 +232,7 @@ class UsersController < ApplicationController
|
|
232
232
|
@user = User.new user_params
|
233
233
|
if @user.save
|
234
234
|
request_confirmation @user
|
235
|
-
redirect_to
|
235
|
+
redirect_to quo_vadis.confirmations_path # a page where you advise the user to check their email
|
236
236
|
else
|
237
237
|
# ...
|
238
238
|
end
|
@@ -252,7 +252,7 @@ See the Configuration section below for how to set QuoVadis's emails' from addre
|
|
252
252
|
|
253
253
|
Now write the page to where the user is redirected while they wait for the email ([example](https://github.com/airblade/quo_vadis/blob/master/test/dummy/app/views/quo_vadis/confirmations/index.html.erb)). It must be in `app/views/quo_vadis/confirmations/index.html.:format`.
|
254
254
|
|
255
|
-
|
255
|
+
On that page you can show the user the address the email was sent to, enable them to update their email address if they make a mistake on the sign-up form, and provide a button to resend another email directly. If the sign-up occurred in a different browser session, you can instead link to `new_confirmation_path` where the user can request another email if need be.
|
256
256
|
|
257
257
|
Next, write the page to which the link in the email points ([example](https://github.com/airblade/quo_vadis/blob/master/test/dummy/app/views/quo_vadis/confirmations/edit.html.erb)). It must be in `app/views/quo_vadis/confirmations/edit.html.:format`.
|
258
258
|
|
@@ -488,13 +488,32 @@ For example, the default login path is at `/login`. If you set `mount_point` to
|
|
488
488
|
|
489
489
|
#### Rails configuration
|
490
490
|
|
491
|
+
__Mailer URLs__
|
492
|
+
|
491
493
|
You must also configure the mailer host so URLs are generated correctly in emails:
|
492
494
|
|
493
495
|
```ruby
|
494
496
|
config.action_mailer.default_url_options: { host: 'example.com' }
|
495
497
|
```
|
496
498
|
|
497
|
-
|
499
|
+
__Layouts__
|
500
|
+
|
501
|
+
You can specify QuoVadis's controllers' layouts in a `#to_prepare` block in your application configuration. For example:
|
502
|
+
|
503
|
+
```ruby
|
504
|
+
# config/application.rb
|
505
|
+
module YourApp
|
506
|
+
class Application < Rails::Application
|
507
|
+
config.to_prepare do
|
508
|
+
QuoVadis::ConfirmationsController.layout 'your_layout'
|
509
|
+
end
|
510
|
+
end
|
511
|
+
end
|
512
|
+
```
|
513
|
+
|
514
|
+
__Routes__
|
515
|
+
|
516
|
+
You can set up your post-authentication and post-password-change routes. If you don't, you must have a root route. For example:
|
498
517
|
|
499
518
|
```ruby
|
500
519
|
# config/routes.rb
|
@@ -5,6 +5,7 @@ module QuoVadis
|
|
5
5
|
|
6
6
|
# holding page
|
7
7
|
def index
|
8
|
+
@account = find_pending_account_from_session
|
8
9
|
end
|
9
10
|
|
10
11
|
|
@@ -45,12 +46,57 @@ module QuoVadis
|
|
45
46
|
end
|
46
47
|
|
47
48
|
account.confirmed!
|
48
|
-
|
49
49
|
qv.log account, Log::ACCOUNT_CONFIRMATION
|
50
50
|
|
51
|
+
session.delete :account_pending_confirmation
|
52
|
+
|
51
53
|
login account.model, true
|
52
54
|
redirect_to qv.path_after_authentication, notice: QuoVadis.translate('flash.confirmation.confirmed')
|
53
55
|
end
|
54
56
|
|
57
|
+
|
58
|
+
def edit_email
|
59
|
+
account = find_pending_account_from_session
|
60
|
+
|
61
|
+
unless account
|
62
|
+
redirect_to confirmations_path, alert: QuoVadis.translate('flash.confirmation.unknown') and return
|
63
|
+
end
|
64
|
+
|
65
|
+
@email = account.model.email
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def update_email
|
70
|
+
account = find_pending_account_from_session
|
71
|
+
|
72
|
+
unless account
|
73
|
+
redirect_to confirmations_path, alert: QuoVadis.translate('flash.confirmation.unknown') and return
|
74
|
+
end
|
75
|
+
|
76
|
+
account.model.update email: params[:email]
|
77
|
+
|
78
|
+
request_confirmation account.model
|
79
|
+
redirect_to confirmations_path
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def resend
|
84
|
+
account = find_pending_account_from_session
|
85
|
+
|
86
|
+
unless account
|
87
|
+
redirect_to confirmations_path, alert: QuoVadis.translate('flash.confirmation.unknown') and return
|
88
|
+
end
|
89
|
+
|
90
|
+
request_confirmation account.model
|
91
|
+
redirect_to confirmations_path
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def find_pending_account_from_session
|
98
|
+
Account.find(session[:account_pending_confirmation]) if session[:account_pending_confirmation]
|
99
|
+
end
|
100
|
+
|
55
101
|
end
|
56
102
|
end
|
@@ -21,7 +21,7 @@ module QuoVadis
|
|
21
21
|
account = QuoVadis.find_account_by_identifier_in_params params
|
22
22
|
|
23
23
|
unless account
|
24
|
-
qv.log nil, Log::LOGIN_UNKNOWN
|
24
|
+
qv.log nil, Log::LOGIN_UNKNOWN, identifier: QuoVadis.identifier_value_in_params(params)
|
25
25
|
flash.now[:alert] = QuoVadis.translate 'flash.login.failed'
|
26
26
|
render :new
|
27
27
|
return
|
data/config/routes.rb
CHANGED
@@ -15,7 +15,13 @@ QuoVadis::Engine.routes.draw do
|
|
15
15
|
get '/pwd-reset/:token', to: 'password_resets#edit', as: 'edit_password_reset'
|
16
16
|
put '/pwd-reset/:token', to: 'password_resets#update', as: 'password_reset'
|
17
17
|
|
18
|
-
resources :confirmations, only: [:new, :create, :index]
|
18
|
+
resources :confirmations, only: [:new, :create, :index] do
|
19
|
+
collection do
|
20
|
+
get :edit_email
|
21
|
+
put :update_email
|
22
|
+
post :resend
|
23
|
+
end
|
24
|
+
end
|
19
25
|
get '/confirm/:token', to: 'confirmations#edit', as: 'edit_confirmation'
|
20
26
|
put '/confirm/:token', to: 'confirmations#update', as: 'confirmation'
|
21
27
|
|
data/lib/quo_vadis.rb
CHANGED
@@ -45,8 +45,12 @@ module QuoVadis
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def find_account_by_identifier_in_params(params)
|
48
|
+
Account.find_by identifier: identifier_value_in_params(params)
|
49
|
+
end
|
50
|
+
|
51
|
+
def identifier_value_in_params(params)
|
48
52
|
identifier = detect_identifier params.keys
|
49
|
-
|
53
|
+
params[identifier]
|
50
54
|
end
|
51
55
|
|
52
56
|
# model - string class name, e.g. 'User'
|
data/lib/quo_vadis/controller.rb
CHANGED
@@ -89,6 +89,7 @@ module QuoVadis
|
|
89
89
|
def request_confirmation(model)
|
90
90
|
token = QuoVadis::AccountConfirmationToken.generate model.qv_account
|
91
91
|
QuoVadis.deliver :account_confirmation, email: model.email, url: quo_vadis.edit_confirmation_url(token)
|
92
|
+
session[:account_pending_confirmation] = model.qv_account.id
|
92
93
|
|
93
94
|
flash[:notice] = QuoVadis.translate 'flash.confirmation.create'
|
94
95
|
end
|
data/lib/quo_vadis/version.rb
CHANGED
@@ -13,7 +13,7 @@ class SignUpsController < ApplicationController
|
|
13
13
|
if @user.save
|
14
14
|
if QuoVadis.accounts_require_confirmation
|
15
15
|
request_confirmation @user
|
16
|
-
redirect_to
|
16
|
+
redirect_to quo_vadis.confirmations_path
|
17
17
|
else
|
18
18
|
redirect_to articles_path
|
19
19
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<h1>Account confirmation: change email</h1>
|
2
|
+
|
3
|
+
<p>Please update your email address.</p>
|
4
|
+
|
5
|
+
<%= form_with url: update_email_confirmations_path, method: :put do |f| %>
|
6
|
+
<p>
|
7
|
+
<%= f.label :email %>
|
8
|
+
<%= f.text_field :email, value: @email, inputmode: 'email', autocomplete: 'email' %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<%= f.submit 'Update my email address and send me a new confirmation email' %>
|
13
|
+
</p>
|
14
|
+
<% end %>
|
@@ -1,5 +1,14 @@
|
|
1
1
|
<h1>Account confirmation</h1>
|
2
2
|
|
3
|
-
|
3
|
+
<% if @account %>
|
4
|
+
<p>We have sent an email to <%= @account.model.email %>.</p>
|
4
5
|
|
5
|
-
<p
|
6
|
+
<p>Wrong address? <%= link_to 'Change it', edit_email_confirmations_path %>.</p>
|
7
|
+
|
8
|
+
<p>Didn't receive it? <%= button_to 'Get another one', resend_confirmations_path %></p>
|
9
|
+
|
10
|
+
<% else %>
|
11
|
+
<p>We have sent an email to you.</p>
|
12
|
+
|
13
|
+
<p><%= link_to 'Request a new email', new_confirmation_path %></p>
|
14
|
+
<% end %>
|
@@ -6,6 +6,10 @@ class AccountConfirmationTest < IntegrationTest
|
|
6
6
|
QuoVadis.accounts_require_confirmation true
|
7
7
|
end
|
8
8
|
|
9
|
+
teardown do
|
10
|
+
QuoVadis.accounts_require_confirmation false
|
11
|
+
end
|
12
|
+
|
9
13
|
|
10
14
|
test 'new signup requiring confirmation' do
|
11
15
|
assert_emails 1 do
|
@@ -36,8 +40,37 @@ class AccountConfirmationTest < IntegrationTest
|
|
36
40
|
end
|
37
41
|
|
38
42
|
|
43
|
+
test 'new signup updates email' do
|
44
|
+
assert_emails 1 do
|
45
|
+
post sign_ups_path(user: {name: 'Bob', email: 'bob@example.com', password: '123456789abc'})
|
46
|
+
end
|
47
|
+
|
48
|
+
get quo_vadis.edit_email_confirmations_path
|
49
|
+
assert_response :success
|
50
|
+
|
51
|
+
# First email: changed-email notifier sent to original address
|
52
|
+
# Second email: confirmation email sent to new address
|
53
|
+
assert_emails 2 do
|
54
|
+
put quo_vadis.update_email_confirmations_path(email: 'bobby@example.com')
|
55
|
+
end
|
56
|
+
assert_equal ['bobby@example.com'], ActionMailer::Base.deliveries.last.to
|
57
|
+
assert_redirected_to quo_vadis.confirmations_path
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
test 'resend confirmation email in same session' do
|
62
|
+
assert_emails 1 do
|
63
|
+
post sign_ups_path(user: {name: 'Bob', email: 'bob@example.com', password: '123456789abc'})
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_emails 1 do
|
67
|
+
post quo_vadis.resend_confirmations_path
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
39
72
|
test 'resend confirmation email: valid identifier' do
|
40
|
-
|
73
|
+
User.create! name: 'bob', email: 'bob@example.com', password: '123456789abc'
|
41
74
|
|
42
75
|
get quo_vadis.new_confirmation_path
|
43
76
|
assert_response :success
|
@@ -91,7 +124,7 @@ class AccountConfirmationTest < IntegrationTest
|
|
91
124
|
|
92
125
|
|
93
126
|
test 'accounts requiring confirmation cannot log in' do
|
94
|
-
|
127
|
+
User.create! name: 'bob', email: 'bob@example.com', password: '123456789abc'
|
95
128
|
post quo_vadis.login_path(email: 'bob@example.com', password: '123456789abc')
|
96
129
|
assert_redirected_to quo_vadis.new_confirmation_path
|
97
130
|
assert_equal 'Please confirm your account first.', flash[:notice]
|
@@ -43,7 +43,7 @@ class LoggingTest < IntegrationTest
|
|
43
43
|
|
44
44
|
|
45
45
|
test 'login.unknown' do
|
46
|
-
assert_log QuoVadis::Log::LOGIN_UNKNOWN, {}, nil do
|
46
|
+
assert_log QuoVadis::Log::LOGIN_UNKNOWN, {'identifier' => 'wrong'}, nil do
|
47
47
|
post quo_vadis.login_path(email: 'wrong', password: 'wrong')
|
48
48
|
end
|
49
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quo_vadis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- test/dummy/app/views/articles/very_secret.html.erb
|
133
133
|
- test/dummy/app/views/layouts/application.html.erb
|
134
134
|
- test/dummy/app/views/quo_vadis/confirmations/edit.html.erb
|
135
|
+
- test/dummy/app/views/quo_vadis/confirmations/edit_email.html.erb
|
135
136
|
- test/dummy/app/views/quo_vadis/confirmations/index.html.erb
|
136
137
|
- test/dummy/app/views/quo_vadis/confirmations/new.html.erb
|
137
138
|
- test/dummy/app/views/quo_vadis/logs/index.html.erb
|