Skip to content

Commit 324fc22

Browse files
committed
Fixes when a new email address is confirmed, the saved current email address is verified and a new verification email is NTO sent
1 parent 43bf9d3 commit 324fc22

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

features/user/new_email_address.feature

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Feature: Register process via a form
3333
| referer | http://www.website.com | /submit?email_redirect=/another-path/{{ username }}/{{ new_email }}/{{ token }} | custom_change_email_confirmation |
3434

3535
@loginUser
36-
@restartBrowser # << Required otherwise the BrowserKit client will have a history and auto-populate the referer header. We are testing for non-standard browser behaviour or hacks
36+
@restartBrowser # << Required otherwise the BrowserKit client will have a history and auto-populate the referer header. We are testing for non-standard browser behaviour or hacks
3737
Scenario Outline: Test invalid referer and missing referer and origin headers
3838
Given there is a "new_email" form
3939
And I add "<headerName>" header equal to "<headerValue>"
@@ -73,6 +73,7 @@ Feature: Register process via a form
7373
Then the response status code should be 422
7474
And the JSON node "formView.children[0].vars.errors[0]" should be equal to "Your new email address should be different."
7575
And the JSON should be valid according to the schema file "form.schema.json"
76+
And I should not receive any emails
7677

7778
@loginUser
7879
Scenario: I get an invalid response if I try to change my email address to one that already exists
@@ -90,6 +91,7 @@ Feature: Register process via a form
9091
Then the response status code should be 422
9192
And the JSON node "formView.children[0].vars.errors[0]" should be equal to "Someone else is already registered with that email address."
9293
And the JSON should be valid according to the schema file "form.schema.json"
94+
And I should not receive any emails
9395

9496
@loginSuperAdmin
9597
Scenario: I can authenticate that I am not able to change my email address to a blank string
@@ -106,6 +108,7 @@ Feature: Register process via a form
106108
And the JSON node "violations[0].propertyPath" should be equal to "newEmailAddress"
107109
And the JSON node "violations[0].message" should be equal to "This value should not be blank."
108110
And the JSON should be valid according to the schema file "validation_errors_object.schema.json"
111+
And I should not receive any emails
109112

110113
@loginSuperAdmin
111114
Scenario: I can authenticate that I am not able to change my email address to a blank string
@@ -159,13 +162,14 @@ Feature: Register process via a form
159162
And I should not receive any emails
160163

161164
Scenario: I can verify my new email address
162-
Given there is a user with the username "my_username" password "password" and role "ROLE_USER"
165+
Given there is a user with the username "my_username" password "password" and role "ROLE_USER" and the email address "old@email.com"
163166
And the user has a new email address "new@email.com" and confirmation token abc123
164167
And I add "referer" header equal to "http://www.website.com"
165168
When I send a "GET" request to "/confirm-email/my_username/new@email.com/abc123"
166169
Then the response status code should be 200
167170
And the new email address should be "new@email.com" for username "my_username"
168-
And I should get a "verify_email" email sent to the email address "new@email.com"
171+
And the user "my_username" should have a verified email address
172+
And I should not receive any emails
169173

170174
Scenario: Email verification reset if another user now has confirmed email same as the one this user is trying to confirm
171175
Given there is a user with the username "new@email.com" password "password" and role "ROLE_USER" and the email address "new@email.com"

src/Helper/User/EmailAddressManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function confirmNewEmailAddress(string $username, string $email, string $
7474
$user
7575
->setEmailAddress($user->getNewEmailAddress())
7676
->setNewEmailAddress(null)
77-
->setEmailAddressVerified(false)
77+
->setEmailAddressVerified(true)
7878
->setNewEmailConfirmationToken(null);
7979

8080
$this->userDataProcessor->processChanges($user, $previousUser);

src/Helper/User/UserDataProcessor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public function processChanges(AbstractUser $user, ?AbstractUser $previousUser):
100100
} else {
101101
// invalidate any existing requests
102102
$user->setNewEmailConfirmationToken(null);
103+
if ($previousUser->getNewEmailAddress() === $user->getEmailAddress() && $user->plainEmailAddressVerifyToken) {
104+
$user->plainEmailAddressVerifyToken = null;
105+
$user->setEmailAddressVerifyToken(null);
106+
}
103107
}
104108
}
105109
}

0 commit comments

Comments
 (0)