Index: trunk/extensions/SignupAPI/includes/validateSignup.php |
— | — | @@ -1,132 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
5 | | - // Eclipse helper - will be ignored in production |
6 | | - require_once( 'ApiBase.php' ); |
7 | | -} |
8 | | - |
9 | | -/** |
10 | | - * Unit to create accounts in the current wiki |
11 | | - * |
12 | | - * @ingroup API |
13 | | - */ |
14 | | -class validateSignup extends ApiBase { |
15 | | - |
16 | | - public function __construct( $main, $action ) { |
17 | | - parent::__construct( $main, $action ); |
18 | | - } |
19 | | - |
20 | | - public function execute() { |
21 | | - $params = $this->extractRequestParams(); |
22 | | - |
23 | | - $result = array(); |
24 | | - |
25 | | - switch ( $params['field'] ) { |
26 | | - case "username": |
27 | | - $mUser = User::newFromName( $params['inputVal'], 'creatable' ); |
28 | | - if ( !is_object( $mUser ) ) { |
29 | | - $result['result'] = wfMsg( 'noname' ); |
30 | | - $result['icon'] = 'MW-Icon-AlertMark.png'; |
31 | | - } |
32 | | - |
33 | | - if ( 0 != $mUser->idForName() ) { |
34 | | - $result['result'] = wfMsg( 'userexists' ); |
35 | | - $result['icon'] = "MW-Icon-NoMark.png"; |
36 | | - } |
37 | | - |
38 | | - else { |
39 | | - $result['result'] = wfMsg( 'ok' ); |
40 | | - $result['icon'] = "MW-Icon-CheckMark.png"; |
41 | | - } |
42 | | - break; |
43 | | - |
44 | | - case "email" : |
45 | | - if ( $valid = User::isValidEmailAddr( $params['inputVal'] ) ) { |
46 | | - $result['result']= wfMsg( 'ok' ); |
47 | | - $result['icon'] = "MW-Icon-CheckMark.png"; |
48 | | - } |
49 | | - else { |
50 | | - $result['result']= wfMsg( 'invalidemailaddress' ); |
51 | | - $result['icon'] = "MW-Icon-NoMark.png"; |
52 | | - } |
53 | | - break; |
54 | | - |
55 | | - case "passwordlength" : |
56 | | - global $wgMinimalPasswordLength; |
57 | | - $result['result'] = $wgMinimalPasswordLength; |
58 | | - break; |
59 | | - |
60 | | - default : |
61 | | - ApiBase::dieDebug( __METHOD__, "Unhandled case value: {$params['field']}" ); |
62 | | - } |
63 | | - |
64 | | - $this->getResult()->addValue( null, 'signup', $result ); |
65 | | - } |
66 | | - |
67 | | - public function mustBePosted() { |
68 | | - return false; |
69 | | - } |
70 | | - |
71 | | - public function isReadMode() { |
72 | | - return false; |
73 | | - } |
74 | | - |
75 | | - public function getAllowedParams() { |
76 | | - return array( |
77 | | - 'field' => null, |
78 | | - 'inputVal' => null, |
79 | | - 'password' => null, |
80 | | - 'retype' => null, |
81 | | - 'email' => null, |
82 | | - ); |
83 | | - } |
84 | | - |
85 | | - public function getParamDescription() { |
86 | | - return array( |
87 | | - 'name' => 'Desired Username', |
88 | | - 'password' => 'Password', |
89 | | - 'retype' => 'Re-typed Password', |
90 | | - 'email' => 'Email ID(optional)', |
91 | | - ); |
92 | | - } |
93 | | - |
94 | | - public function getDescription() { |
95 | | - return array( |
96 | | - 'This module validates the parameters posted by the signup form.' |
97 | | - ); |
98 | | - } |
99 | | - |
100 | | - public function getPossibleErrors() { |
101 | | - return array_merge( parent::getPossibleErrors(), array( |
102 | | - array( 'code' => 'WrongPassword', 'info' => 'Incorrect password entered. Please try again.' ), |
103 | | - array( 'code' => 'ReadOnlyPage', 'info' => 'Accounts cannot be created with read-only permissions' ), |
104 | | - array( 'code' => 'NoCookies', 'info' => 'The user account was not created, as we could not confirm its source. |
105 | | - Ensure you have cookies enabled, reload this page and try again.' ), |
106 | | - array( 'code' => 'NeedToken', 'info' => 'You need to resubmit your signup with the specified token' ), |
107 | | - array( 'code' => 'WrongToken', 'info' => 'You specified an invalid token' ), |
108 | | - array( 'code' => 'InsufficientPermission', 'info' => 'You do not have sufficient permissions to create account' ), |
109 | | - array( 'code' => 'CreateBlocked', 'info' => 'You have been blocked from creating accounts' ), |
110 | | - array( 'code' => 'IPBlocked', 'info' => 'Your IP is blocked from creating accounts' ), |
111 | | - array( 'code' => 'NoName', 'info' => 'You have not set a valid name for the username parameter' ), |
112 | | - array( 'code' => 'UserExists', 'info' => 'Username entered already in use. Please choose a different name.' ), |
113 | | - array( 'code' => 'WrongRetype', 'info' => 'The passwords you entered do not match.' ), |
114 | | - array( 'code' => 'InvalidPass', 'info' => 'You specified an invalid password' ), |
115 | | - array( 'code' => 'NoEmail', 'info' => 'No e-mail address specified' ), |
116 | | - array( 'code' => 'InvalidEmail', 'info' => 'You specified an invalid email address' ), |
117 | | - array( 'code' => 'BlockedByHook', 'info' => 'A hook blocked account creation' ), |
118 | | - array( 'code' => 'ExternalDBError', 'info' => 'There was either an authentication database error or you are not allowed to update your external account.' ), |
119 | | - array( 'code' => 'Throttled', 'info' => 'You have tried creating accounts too many times in a short period' ), |
120 | | - ) ); |
121 | | - } |
122 | | - |
123 | | - protected function getExamples() { |
124 | | - return array( |
125 | | - 'api.php?action=validatesignup&field=username&name=username' |
126 | | - ); |
127 | | - } |
128 | | - |
129 | | - public function getVersion() { |
130 | | - return __CLASS__ . ': $Id: validateSignup.php 91472 2011-07-05 18:43:51Z akshay $'; |
131 | | - } |
132 | | - |
133 | | -} |