Postgres: make sure ar_len is added when updating, alpha stuff in updaters.inc
[lhc/web/wiklou.git] / includes / SpecialConfirmemail.php
1 <?php
2
3 /**
4 * Special page allows users to request email confirmation message, and handles
5 * processing of the confirmation code when the link in the email is followed
6 *
7 * @addtogroup Special pages
8 * @author Rob Church <robchur@gmail.com>
9 */
10
11 /**
12 * Main execution point
13 *
14 * @param $par Parameters passed to the page
15 */
16 function wfSpecialConfirmemail( $par ) {
17 $form = new EmailConfirmation();
18 $form->execute( $par );
19 }
20
21 class EmailConfirmation extends SpecialPage {
22
23 /**
24 * Main execution point
25 *
26 * @param $code Confirmation code passed to the page
27 */
28 function execute( $code ) {
29 global $wgUser, $wgOut;
30 if( empty( $code ) ) {
31 if( $wgUser->isLoggedIn() ) {
32 if( User::isValidEmailAddr( $wgUser->getEmail() ) ) {
33 $this->showRequestForm();
34 } else {
35 $wgOut->addWikiText( wfMsg( 'confirmemail_noemail' ) );
36 }
37 } else {
38 $title = SpecialPage::getTitleFor( 'Userlogin' );
39 $self = SpecialPage::getTitleFor( 'Confirmemail' );
40 $skin = $wgUser->getSkin();
41 $llink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $self->getPrefixedUrl() );
42 $wgOut->addHtml( wfMsgWikiHtml( 'confirmemail_needlogin', $llink ) );
43 }
44 } else {
45 $this->attemptConfirm( $code );
46 }
47 }
48
49 /**
50 * Show a nice form for the user to request a confirmation mail
51 */
52 function showRequestForm() {
53 global $wgOut, $wgUser, $wgLang, $wgRequest;
54 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
55 $ok = $wgUser->sendConfirmationMail();
56 if ( WikiError::isError( $ok ) ) {
57 $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $ok->toString() ) );
58 } else {
59 $wgOut->addWikiText( wfMsg( 'confirmemail_sent' ) );
60 }
61 } else {
62 if( $wgUser->isEmailConfirmed() ) {
63 $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true );
64 $wgOut->addWikiText( wfMsg( 'emailauthenticated', $time ) );
65 }
66 if( $wgUser->isEmailConfirmationPending() ) {
67 $wgOut->addWikiText( wfMsg( 'confirmemail_pending' ) );
68 }
69 $wgOut->addWikiText( wfMsg( 'confirmemail_text' ) );
70 $self = SpecialPage::getTitleFor( 'Confirmemail' );
71 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
72 $form .= wfHidden( 'token', $wgUser->editToken() );
73 $form .= wfSubmitButton( wfMsgHtml( 'confirmemail_send' ) );
74 $form .= wfCloseElement( 'form' );
75 $wgOut->addHtml( $form );
76 }
77 }
78
79 /**
80 * Attempt to confirm the user's email address and show success or failure
81 * as needed; if successful, take the user to log in
82 *
83 * @param $code Confirmation code
84 */
85 function attemptConfirm( $code ) {
86 global $wgUser, $wgOut;
87 $user = User::newFromConfirmationCode( $code );
88 if( is_object( $user ) ) {
89 if( $user->confirmEmail() ) {
90 $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
91 $wgOut->addWikiText( wfMsg( $message ) );
92 if( !$wgUser->isLoggedIn() ) {
93 $title = SpecialPage::getTitleFor( 'Userlogin' );
94 $wgOut->returnToMain( true, $title->getPrefixedText() );
95 }
96 } else {
97 $wgOut->addWikiText( wfMsg( 'confirmemail_error' ) );
98 }
99 } else {
100 $wgOut->addWikiText( wfMsg( 'confirmemail_invalid' ) );
101 }
102 }
103
104 }
105
106 ?>