Skip to content

Commit bb1ac03

Browse files
committed
Merge branch '3.3.x'
2 parents 3085762 + 5404b8d commit bb1ac03

File tree

6 files changed

+130
-7
lines changed

6 files changed

+130
-7
lines changed

console/command/user/add.php

+31-3
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,17 @@ protected function send_activation_email($user_id)
296296
{
297297
case USER_ACTIVATION_SELF:
298298
$email_template = 'user_welcome_inactive';
299-
$user_actkey = gen_rand_string(mt_rand(6, 10));
300299
break;
301300
case USER_ACTIVATION_ADMIN:
302301
$email_template = 'admin_welcome_inactive';
303-
$user_actkey = gen_rand_string(mt_rand(6, 10));
304302
break;
305303
default:
306304
$email_template = 'user_welcome';
307-
$user_actkey = '';
308305
break;
309306
}
310307

308+
$user_actkey = $this->get_activation_key($user_id);
309+
311310
if (!class_exists('messenger'))
312311
{
313312
require($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
@@ -327,6 +326,35 @@ protected function send_activation_email($user_id)
327326
$messenger->send(NOTIFY_EMAIL);
328327
}
329328

329+
/**
330+
* Get user activation key
331+
*
332+
* @param int $user_id User ID
333+
*
334+
* @return string User activation key for user
335+
*/
336+
protected function get_activation_key(int $user_id): string
337+
{
338+
$user_actkey = '';
339+
340+
if ($this->config['require_activation'] == USER_ACTIVATION_SELF || $this->config['require_activation'] == USER_ACTIVATION_ADMIN)
341+
{
342+
$user_actkey = gen_rand_string(mt_rand(6, 10));
343+
344+
$sql_ary = [
345+
'user_actkey' => $user_actkey,
346+
'user_actkey_expiration' => \phpbb\user::get_token_expiration(),
347+
];
348+
349+
$sql = 'UPDATE ' . USERS_TABLE . '
350+
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
351+
WHERE user_id = ' . (int) $user_id;
352+
$this->db->sql_query($sql);
353+
}
354+
355+
return $user_actkey;
356+
}
357+
330358
/**
331359
* Helper to translate questions to the user
332360
*

cron/event/cron_runner_listener.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ public function on_kernel_terminate(TerminateEvent $event)
8585
{
8686
$task->run();
8787
}
88-
89-
$this->cron_lock->release();
9088
}
89+
$this->cron_lock->release();
9190
}
9291
}
9392

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
namespace phpbb\db\migration\data\v33x;
15+
16+
use phpbb\db\migration\migration;
17+
18+
class add_resend_activation_expiration extends migration
19+
{
20+
public static function depends_on(): array
21+
{
22+
return [
23+
'\phpbb\db\migration\data\v33x\v3311',
24+
];
25+
}
26+
27+
public function update_schema(): array
28+
{
29+
return [
30+
'add_columns' => [
31+
$this->table_prefix . 'users' => [
32+
'user_actkey_expiration' => ['TIMESTAMP', 0, 'after' => 'user_actkey'],
33+
],
34+
],
35+
];
36+
}
37+
38+
public function revert_schema(): array
39+
{
40+
return [
41+
'drop_columns' => [
42+
$this->table_prefix . 'users' => [
43+
'user_actkey_expiration',
44+
],
45+
],
46+
];
47+
}
48+
}

db/migration/data/v33x/v3312.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
namespace phpbb\db\migration\data\v33x;
15+
16+
class v3312 extends \phpbb\db\migration\migration
17+
{
18+
public function effectively_installed()
19+
{
20+
return version_compare($this->config['version'], '3.3.12', '>=');
21+
}
22+
23+
public static function depends_on()
24+
{
25+
return [
26+
'\phpbb\db\migration\data\v33x\add_resend_activation_expiration',
27+
'\phpbb\db\migration\data\v33x\add_user_last_active',
28+
'\phpbb\db\migration\data\v33x\v3312rc1',
29+
];
30+
}
31+
32+
public function update_data()
33+
{
34+
return [
35+
['config.update', ['version', '3.3.12']],
36+
];
37+
}
38+
}

ucp/controller/reset_password.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function request()
242242

243243
$sql_ary = [
244244
'reset_token' => $reset_token,
245-
'reset_token_expiration' => strtotime('+1 day'),
245+
'reset_token_expiration' => $this->user::get_token_expiration(),
246246
];
247247

248248
$sql = 'UPDATE ' . $this->users_table . '

user.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class user extends \phpbb\session
5959
* @param \phpbb\language\language $lang phpBB's Language loader
6060
* @param string $datetime_class Class name of datetime class
6161
*/
62-
function __construct(\phpbb\language\language $lang, $datetime_class)
62+
public function __construct(\phpbb\language\language $lang, $datetime_class)
6363
{
6464
global $phpbb_root_path;
6565

@@ -80,6 +80,16 @@ public function is_setup()
8080
return $this->is_setup_flag;
8181
}
8282

83+
/**
84+
* Get expiration time for user tokens, e.g. activation or reset password tokens
85+
*
86+
* @return int Expiration for user tokens
87+
*/
88+
public static function get_token_expiration(): int
89+
{
90+
return strtotime('+1 day') ?: 0;
91+
}
92+
8393
/**
8494
* Magic getter for BC compatibility
8595
*

0 commit comments

Comments
 (0)