Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UserCreationHookHandler | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
onLocalUserCreated | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Extension\CentralAuth\Hooks\Handlers; |
22 | |
23 | use MediaWiki\Auth\Hook\LocalUserCreatedHook; |
24 | use MediaWiki\Extension\CentralAuth\CentralAuthDatabaseManager; |
25 | use MediaWiki\Extension\CentralAuth\CentralAuthUtilityService; |
26 | use MediaWiki\Extension\CentralAuth\User\CentralAuthAntiSpoofManager; |
27 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
28 | use MediaWiki\User\User; |
29 | use MediaWiki\WikiMap\WikiMap; |
30 | |
31 | class UserCreationHookHandler implements LocalUserCreatedHook { |
32 | |
33 | private CentralAuthAntiSpoofManager $caAntiSpoofManager; |
34 | private CentralAuthDatabaseManager $databaseManager; |
35 | private CentralAuthUtilityService $utilityService; |
36 | |
37 | public function __construct( |
38 | CentralAuthAntiSpoofManager $caAntiSpoofManager, |
39 | CentralAuthDatabaseManager $databaseManager, |
40 | CentralAuthUtilityService $utilityService |
41 | ) { |
42 | $this->caAntiSpoofManager = $caAntiSpoofManager; |
43 | $this->databaseManager = $databaseManager; |
44 | $this->utilityService = $utilityService; |
45 | } |
46 | |
47 | /** |
48 | * Populate localuser table and update AntiSpoof system |
49 | * |
50 | * @param User $user |
51 | * @param bool $autocreated |
52 | * @return void |
53 | */ |
54 | public function onLocalUserCreated( $user, $autocreated ) { |
55 | $centralUser = CentralAuthUser::getPrimaryInstance( $user ); |
56 | |
57 | // If some other AuthManager PrimaryAuthenticationProvider is creating |
58 | // the user, we should still create a central user for them so |
59 | // CentralAuthIdLookup can have an ID for this new user right away. |
60 | if ( !$centralUser->exists() && !$centralUser->listUnattached() ) { |
61 | if ( $centralUser->register( null, $user->getEmail() ) ) { |
62 | $centralUser->attach( WikiMap::getCurrentWikiId(), 'new' ); |
63 | $this->databaseManager->getCentralPrimaryDB()->onTransactionCommitOrIdle( |
64 | function () use ( $centralUser ) { |
65 | $this->utilityService->scheduleCreationJobs( $centralUser ); |
66 | }, |
67 | __METHOD__ |
68 | ); |
69 | } |
70 | } |
71 | |
72 | $centralUser->addLocalName( WikiMap::getCurrentWikiId() ); |
73 | |
74 | // Record the username's thing-bob after a user account is created |
75 | $spoof = $this->caAntiSpoofManager->getSpoofUser( $user->getName() ); |
76 | $spoof->record(); |
77 | } |
78 | } |