Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Separate activation from resetToken #24461

Open
wants to merge 42 commits into
base: 5.2-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
86115e9
Merge pull request #1 from joomla/4.0-dev
Arpit-24 Mar 23, 2019
5df490b
Fix overlap of editor and options
Arpit-24 Mar 24, 2019
8e99112
Move tinymce change to it own file
Arpit-24 Mar 25, 2019
618b947
Move tinymce change to it own file
Arpit-24 Mar 25, 2019
c64bf2d
Merge branch '4.0-dev' into 4.0-dev
infograf768 Mar 25, 2019
e6d3c7d
Restore original file
Arpit-24 Mar 25, 2019
7deff97
Restore file
Arpit-24 Mar 25, 2019
6d90683
Fix Joomla logo to center
Arpit-24 Mar 27, 2019
63f7b59
Restore
Arpit-24 Mar 27, 2019
03fc4a7
Merge pull request #3 from joomla/4.0-dev
Arpit-24 Mar 29, 2019
13e1e3f
Merge pull request #4 from joomla/4.0-dev
Arpit-24 Mar 30, 2019
c6bc370
Add resetToken column
Arpit-24 Apr 2, 2019
f1e6b36
Add resetToken column
Arpit-24 Apr 2, 2019
8fac696
resetToken column used instead of activation
Arpit-24 Apr 2, 2019
3f1645c
Added text for resetToken expired
Arpit-24 Apr 2, 2019
a8fc48a
Merge branch '4.0-dev' into 4.0-resetToken
Arpit-24 Nov 16, 2019
e8b6284
Update ResetModel.php
Arpit-24 Nov 16, 2019
08fe27f
Update ResetModel.php
Arpit-24 Nov 16, 2019
5552003
Update ResetModel.php
Arpit-24 Nov 16, 2019
48a9222
Merge branch '4.0-dev' into 4.0-resetToken
Nov 16, 2019
d2d134f
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-resetToken
Arpit-24 Aug 2, 2020
e3f0b5d
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-resetToken
Arpit-24 Aug 2, 2020
602056c
Update com_users.ini
Arpit-24 Aug 2, 2020
a43ece1
Rename update SQL scripts and fix PostgreSQL syntax
richard67 Mar 15, 2021
a2fe5b6
Add the new column to base.sql for new installations
richard67 Mar 15, 2021
0e1fa02
Merge branch '4.0-dev' into 4.0-resetToken
richard67 Mar 15, 2021
36e1f11
Merge branch '4.1-dev' into 4.0-resetToken
bembelimen Jan 22, 2022
38f7ff3
Update components/com_users/src/Model/ResetModel.php
Jan 27, 2022
6a68265
Update components/com_users/src/Model/ResetModel.php
Jan 27, 2022
f101243
Merge branch '4.1-dev' into 4.0-resetToken
Jan 28, 2022
1f89fb4
Merge branch '4.1-dev' into 4.0-resetToken
laoneo Apr 14, 2022
e06ccb4
Merge tag 'psr12anchor' into psr12/merge/24461
joomla-bot Jun 27, 2022
33c0c7a
Phase 1 convert BRANCH to PSR-12
joomla-bot Jun 27, 2022
bdfba5e
Phase 2 convert BRANCH to PSR-12
joomla-bot Jun 27, 2022
c8f6e5d
Merge tag 'psr12final' into psr12/merge/24461
joomla-bot Jun 27, 2022
afd9b93
Merge branch '5.0-dev' into 4.0-resetToken
rdeutz Oct 21, 2022
284d093
Improve difference calculation for dates
bembelimen Oct 22, 2022
bd77e59
Fix wrong sign
bembelimen Oct 22, 2022
71266a2
Merge branch '5.0-dev' into 4.0-resetToken
drmenzelit Oct 22, 2022
dfb0875
CS fix
bembelimen Oct 23, 2022
a502fc0
Merge branch '5.0-dev' into 4.0-resetToken
bembelimen Oct 23, 2022
26497b4
Merge branch '5.2-dev' into 4.0-resetToken
bembelimen Mar 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `#__users` ADD COLUMN `resetToken` varchar(100) NOT NULL DEFAULT '';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "#__users" ADD COLUMN "resetToken" varchar(100) DEFAULT '' NOT NULL;
26 changes: 19 additions & 7 deletions components/com_users/src/Model/ResetModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function processResetComplete($data)
$app->getDispatcher()->dispatch($event->getName(), $event);

// Check for a user and that the tokens match.
if (empty($user) || $user->activation !== $token) {
if (empty($user) || $user->resetToken !== $token) {
$this->setError(Text::_('COM_USERS_USER_NOT_FOUND'));

return false;
Expand All @@ -230,7 +230,7 @@ public function processResetComplete($data)

// Prepare user data.
$data['password'] = $data['password1'];
$data['activation'] = '';
$data['resetToken'] = '';

// Update the user object.
if (!$user->bind($data)) {
Expand Down Expand Up @@ -302,7 +302,7 @@ public function processResetConfirm($data)
// Find the user id for the given token.
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName(['activation', 'id', 'block']))
->select($db->quoteName(['activation', 'resetToken', 'lastResetTime', 'id', 'block']))
->from($db->quoteName('#__users'))
->where($db->quoteName('username') . ' = :username')
->bind(':username', $data['username']);
Expand All @@ -323,14 +323,14 @@ public function processResetConfirm($data)
return false;
}

if (!$user->activation) {
if ($user->activation) {
$this->setError(Text::_('COM_USERS_USER_NOT_FOUND'));

return false;
}

// Verify the token
if (!UserHelper::verifyPassword($data['token'], $user->activation)) {
if (!UserHelper::verifyPassword($data['token'], $user->resetToken)) {
$this->setError(Text::_('COM_USERS_USER_NOT_FOUND'));

return false;
Expand All @@ -343,9 +343,21 @@ public function processResetConfirm($data)
return false;
}

// Check if the token is expired or not
$now = Factory::getDate();
$lastReset = Factory::getDate($user->lastResetTime);

$now->modify('-3 days');

if ($now > $lastReset) {
$this->setError(Text::_('COM_USERS_RESET_TOKEN_EXPIRED'));

return false;
}

// Push the user data into the session.
$app = Factory::getApplication();
$app->setUserState('com_users.reset.token', $user->activation);
$app->setUserState('com_users.reset.token', $user->resetToken);
$app->setUserState('com_users.reset.user', $user->id);

return true;
Expand Down Expand Up @@ -449,7 +461,7 @@ public function processResetRequest($data)
$token = ApplicationHelper::getHash(UserHelper::genRandomPassword());
$hashedToken = UserHelper::hashPassword($token);

$user->activation = $hashedToken;
$user->resetToken = $hashedToken;

$event = AbstractEvent::create(
'onUserBeforeResetRequest',
Expand Down
1 change: 1 addition & 0 deletions installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ CREATE TABLE IF NOT EXISTS `#__users` (
`registerDate` datetime NOT NULL,
`lastvisitDate` datetime,
`activation` varchar(100) NOT NULL DEFAULT '',
`resetToken` varchar(100) NOT NULL DEFAULT '',
`params` text NOT NULL,
`lastResetTime` datetime COMMENT 'Date of last password reset',
`resetCount` int NOT NULL DEFAULT 0 COMMENT 'Count of password resets since lastResetTime',
Expand Down
1 change: 1 addition & 0 deletions installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ CREATE TABLE IF NOT EXISTS "#__users" (
"registerDate" timestamp without time zone NOT NULL,
"lastvisitDate" timestamp without time zone,
"activation" varchar(100) DEFAULT '' NOT NULL,
"resetToken" varchar(100) DEFAULT '' NOT NULL,
"params" text NOT NULL,
"lastResetTime" timestamp without time zone,
"resetCount" bigint DEFAULT 0 NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions language/en-GB/com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ COM_USERS_RESET_REQUEST="If the email address you entered is registered on this
COM_USERS_RESET_REQUEST_ERROR="Error requesting password reset."
COM_USERS_RESET_REQUEST_FAILED="Reset password failed: %s"
COM_USERS_RESET_REQUEST_LABEL="Please enter the email address for your account. A verification code will be sent to you. Once you have received the verification code, you will be able to choose a new password for your account."
COM_USERS_RESET_TOKEN_EXPIRED="Verification code has expired, please request a new one."
COM_USERS_SETTINGS_FIELDSET_LABEL="Basic Settings"
COM_USERS_USER_BACKUPCODE="Backup Code"
COM_USERS_USER_BACKUPCODES="Backup Codes"
Expand Down