Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
EmailableUser | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
newFromName | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
sendConfirmAndMigrateMail | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
6 |
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\User; |
22 | |
23 | use MediaWiki\MediaWikiServices; |
24 | use MediaWiki\Status\Status; |
25 | use MediaWiki\Title\Title; |
26 | use MediaWiki\User\User; |
27 | use MediaWiki\User\UserNameUtils; |
28 | |
29 | class EmailableUser extends User { |
30 | |
31 | /** |
32 | * Static factory method for creation from username. |
33 | * |
34 | * @param string $name Username, validated by Title::newFromText() |
35 | * @param string|bool $validate Type of validation to use |
36 | * Takes the same parameters as UserNameUtils::getCanonical(), |
37 | * except that true is accepted as an alias for RIGOR_VALID |
38 | * Use of UserNameUtils' class public constants RIGOR_* is preferred |
39 | * - RIGOR_NONE No validation |
40 | * - RIGOR_VALID Valid for batch processes |
41 | * - RIGOR_USABLE Valid for batch processes and login |
42 | * - RIGOR_CREATABLE Valid for batch processes, login and account creation |
43 | * |
44 | * @return EmailableUser|false EmailableUser object, or false if the |
45 | * username is invalid (e.g. if it contains illegal characters or is an IP address). |
46 | * If the username is not present in the database, the result will be a EmailableUser |
47 | * object with a name, zero user ID and default settings. |
48 | */ |
49 | public static function newFromName( $name, $validate = UserNameUtils::RIGOR_VALID ) { |
50 | $userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils(); |
51 | if ( $validate === true ) { |
52 | $validate = UserNameUtils::RIGOR_VALID; |
53 | } |
54 | $name = $userNameUtils->getCanonical( $name, $validate ); |
55 | if ( $name === false ) { |
56 | return false; |
57 | } else { |
58 | # Create unloaded user object |
59 | $u = new EmailableUser; |
60 | $u->mName = $name; |
61 | $u->mFrom = 'name'; |
62 | $u->setItemLoaded( 'name' ); |
63 | return $u; |
64 | } |
65 | } |
66 | |
67 | /** |
68 | * Generate a new e-mail confirmation token and send a confirmation/invalidation |
69 | * mail to the user's given address. |
70 | * |
71 | * @return Status |
72 | */ |
73 | public function sendConfirmAndMigrateMail() { |
74 | // 14 days |
75 | $tokenLife = 14 * 24 * 60 * 60; |
76 | |
77 | $token = $this->confirmationToken( $expiration ); |
78 | |
79 | // we want this token to last a little bit longer since we are cold-emailing |
80 | // users and we really want as many responses as possible |
81 | $now = time(); |
82 | $expires = $now + $tokenLife; |
83 | $expiration = wfTimestamp( TS_MW, $expires ); |
84 | $this->mEmailTokenExpires = $expiration; |
85 | |
86 | if ( $this->isEmailConfirmed() ) { |
87 | // Hack to bypass localization of 'Special:' |
88 | // @see User::getTokenUrl |
89 | $mergeAccountUrl = Title::makeTitle( NS_MAIN, 'Special:MergeAccount' )->getCanonicalURL(); |
90 | } else { |
91 | // create a "token url" for MergeAccount since we have added email |
92 | // confirmation there |
93 | $mergeAccountUrl = $this->getTokenUrl( 'MergeAccount', $token ); |
94 | } |
95 | |
96 | $invalidateURL = $this->invalidationTokenUrl( $token ); |
97 | $this->saveSettings(); |
98 | |
99 | return $this->sendMail( |
100 | wfMessage( 'centralauth-finishglobaliseemail_subject' )->text(), |
101 | wfMessage( "centralauth-finishglobaliseemail_body", |
102 | $this->getRequest()->getIP(), |
103 | $this->getName(), |
104 | $mergeAccountUrl |
105 | )->dateTimeParams( |
106 | $expiration |
107 | )->params( |
108 | $invalidateURL |
109 | )->dateParams( |
110 | $expiration |
111 | )->timeParams( |
112 | $expiration |
113 | )->text() |
114 | ); |
115 | } |
116 | } |