Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
CampaignsSecondaryAuthenticationProvider | |
0.00% |
0 / 37 |
|
0.00% |
0 / 4 |
240 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthenticationRequests | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
beginSecondaryAuthentication | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
beginSecondaryAccountCreation | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
90 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Campaigns; |
4 | |
5 | use MediaWiki\Auth\AbstractSecondaryAuthenticationProvider; |
6 | use MediaWiki\Auth\AuthenticationRequest; |
7 | use MediaWiki\Auth\AuthenticationResponse; |
8 | use MediaWiki\Auth\AuthManager; |
9 | use MediaWiki\Extension\EventLogging\EventLogging; |
10 | use MediaWiki\Registration\ExtensionRegistry; |
11 | use MediaWiki\User\TempUser\TempUserConfig; |
12 | use MobileContext; |
13 | |
14 | /** |
15 | * Log user creations to EventLogging, including the parameter "campaign" that |
16 | * was set on account creation form link if one was present. |
17 | */ |
18 | class CampaignsSecondaryAuthenticationProvider |
19 | extends AbstractSecondaryAuthenticationProvider { |
20 | |
21 | private TempUserConfig $tempUserConfig; |
22 | |
23 | /** |
24 | * @param TempUserConfig $tempUserConfig |
25 | */ |
26 | public function __construct( TempUserConfig $tempUserConfig ) { |
27 | $this->tempUserConfig = $tempUserConfig; |
28 | } |
29 | |
30 | /** @inheritDoc */ |
31 | public function getAuthenticationRequests( $action, array $options ) { |
32 | if ( $action === AuthManager::ACTION_CREATE ) { |
33 | $useCampaignField = !isset( $options['username'] ) || |
34 | ( $this->tempUserConfig->isEnabled() && $this->tempUserConfig->isTempName( $options['username'] ) ); |
35 | |
36 | return [ new CampaignsAuthenticationRequest( |
37 | $this->manager->getRequest(), |
38 | $useCampaignField |
39 | ) ]; |
40 | } |
41 | |
42 | return []; |
43 | } |
44 | |
45 | /** @inheritDoc */ |
46 | public function beginSecondaryAuthentication( $user, array $reqs ) { |
47 | return AuthenticationResponse::newAbstain(); |
48 | } |
49 | |
50 | /** @inheritDoc */ |
51 | public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) { |
52 | $req = AuthenticationRequest::getRequestByClass( |
53 | $reqs, CampaignsAuthenticationRequest::class |
54 | ); |
55 | |
56 | $request = $this->manager->getRequest(); |
57 | $userId = $user->getId(); |
58 | $creatorUserId = $creator->getId(); |
59 | |
60 | // MediaWiki allows existing users to create accounts on behalf |
61 | // of others. In such cases the ID of the newly-created user and |
62 | // the ID of the user making this web request are different. |
63 | $isSelfMade = ( $userId && $userId === $creatorUserId ) || !$creatorUserId; |
64 | |
65 | $displayMobile = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) && |
66 | MobileContext::singleton()->shouldDisplayMobileView(); |
67 | |
68 | $event = [ |
69 | 'userId' => $userId, |
70 | 'userName' => $user->getName(), |
71 | 'isSelfMade' => $isSelfMade, |
72 | 'campaign' => $req ? $req->campaign : '', |
73 | 'displayMobile' => $displayMobile, |
74 | // @todo: Remove these unused fields when they're no longer required by the schema. |
75 | 'token' => '', |
76 | 'userBuckets' => '', |
77 | 'isApi' => defined( 'MW_API' ), |
78 | ]; |
79 | |
80 | $returnTo = $request->getVal( 'returnto', $req ? $req->returnTo : null ); |
81 | if ( $returnTo !== null ) { |
82 | $event[ 'returnTo' ] = $returnTo; |
83 | } |
84 | |
85 | $returnToQuery = $request->getVal( 'returntoquery', $req ? $req->returnToQuery : null ); |
86 | if ( $returnToQuery !== null ) { |
87 | $event[ 'returnToQuery' ] = $returnToQuery; |
88 | } |
89 | |
90 | // This has been migrated to an Event Platform schema; schema revision is no longer used |
91 | // in this call. Versioned schema URI is set in extension.json. |
92 | EventLogging::logEvent( 'ServerSideAccountCreation', -1, $event ); |
93 | |
94 | return AuthenticationResponse::newPass(); |
95 | } |
96 | } |