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