* Fixed unclosed <p> tag
[lhc/web/wiklou.git] / includes / SpecialConfirmemail.php
1 <?php
2 /**
3 * Entry point to confirm a user's e-mail address.
4 * When a new address is entered, a random unique code is generated and
5 * mailed to the user. A clickable link to this page is provided.
6 *
7 * @package MediaWiki
8 * @subpackage SpecialPage
9 */
10
11 /** @todo document */
12 function wfSpecialConfirmemail( $code ) {
13 $form = new ConfirmationForm();
14 $form->show( $code );
15 }
16
17 /** @package MediaWiki */
18 class ConfirmationForm {
19 /** */
20 function show( $code ) {
21 if( empty( $code ) ) {
22 $this->showEmpty( $this->checkAndSend() );
23 } else {
24 $this->showCode( $code );
25 }
26 }
27
28 /** */
29 function showCode( $code ) {
30 $user = User::newFromConfirmationCode( $code );
31 if( is_null( $user ) ) {
32 $this->showInvalidCode();
33 } else {
34 $this->confirmAndShow( $user );
35 }
36 }
37
38 /** */
39 function confirmAndShow( $user ) {
40 if( $user->confirmEmail() ) {
41 $this->showSuccess();
42 } else {
43 $this->showError();
44 }
45 }
46
47 /** */
48 function checkAndSend() {
49 global $wgUser, $wgRequest;
50 if( $wgRequest->wasPosted() &&
51 $wgUser->isLoggedIn() &&
52 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
53 $result = $wgUser->sendConfirmationMail();
54 if( WikiError::isError( $result ) ) {
55 return 'confirmemail_sendfailed';
56 } else {
57 return 'confirmemail_sent';
58 }
59 } else {
60 # boo
61 return '';
62 }
63 }
64
65 /** */
66 function showEmpty( $err ) {
67 require_once( 'templates/Confirmemail.php' );
68 global $wgOut, $wgUser;
69
70 $tpl = new ConfirmemailTemplate();
71 $tpl->set( 'error', $err );
72 $tpl->set( 'edittoken', $wgUser->editToken() );
73
74 $title = Title::makeTitle( NS_SPECIAL, 'Confirmemail' );
75 $tpl->set( 'action', $title->getLocalUrl() );
76
77
78 $wgOut->addTemplate( $tpl );
79 }
80
81 /** */
82 function showInvalidCode() {
83 global $wgOut;
84 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );
85 }
86
87 /** */
88 function showError() {
89 global $wgOut;
90 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
91 }
92
93 /** */
94 function showSuccess() {
95 global $wgOut, $wgRequest, $wgUser;
96
97 if( $wgUser->isLoggedIn() ) {
98 $wgOut->addWikiText( wfMsg( 'confirmemail_loggedin' ) );
99 } else {
100 $wgOut->addWikiText( wfMsg( 'confirmemail_success' ) );
101 require_once( 'SpecialUserlogin.php' );
102 $form = new LoginForm( $wgRequest );
103 $form->execute();
104 }
105 }
106 }
107
108 ?>