Index: trunk/extensions/CrowdAuthentication/CrowdAuthentication.php |
— | — | @@ -78,16 +78,36 @@ |
79 | 79 | /** |
80 | 80 | * @var PasswordCredential |
81 | 81 | */ |
82 | | - public /**/ $credential; |
83 | | - public /*string*/ $name; |
84 | | - public /*ValidationFactor[]*/ $validationFactors = null; |
| 82 | + public $credential; |
| 83 | + |
| 84 | + /** |
| 85 | + * @var string |
| 86 | + */ |
| 87 | + public $name; |
| 88 | + |
| 89 | + /** |
| 90 | + * @var array |
| 91 | + */ |
| 92 | + public $validationFactors = null; |
85 | 93 | } |
86 | 94 | |
87 | 95 | class caPrincipalAuthenticationContext { |
88 | | - public /*string*/ $application; |
89 | | - public /*PasswordCredential*/ $credential; |
90 | | - public /*string*/ $name; |
91 | | - public /*ValidationFactor[]*/ $validationFactors = null; |
| 96 | + public $application; |
| 97 | + |
| 98 | + /** |
| 99 | + * @var PasswordCredential |
| 100 | + */ |
| 101 | + public $credential; |
| 102 | + |
| 103 | + /** |
| 104 | + * @var string |
| 105 | + */ |
| 106 | + public $name; |
| 107 | + |
| 108 | + /** |
| 109 | + * @var array |
| 110 | + */ |
| 111 | + public $validationFactors = null; |
92 | 112 | } |
93 | 113 | |
94 | 114 | class CrowdAuthenticator extends AuthPlugin { |
— | — | @@ -133,7 +153,7 @@ |
134 | 154 | |
135 | 155 | /** |
136 | 156 | * @param $name string |
137 | | - * @return bool |
| 157 | + * @return string|null |
138 | 158 | */ |
139 | 159 | private function findUsername( $name ) { |
140 | 160 | /* |
— | — | @@ -159,12 +179,21 @@ |
160 | 180 | return null; |
161 | 181 | } |
162 | 182 | |
163 | | - public function /*bool*/ userExists( /*string*/ $name ) { |
| 183 | + /** |
| 184 | + * @param $name string |
| 185 | + * @return bool |
| 186 | + */ |
| 187 | + public function userExists( $name ) { |
164 | 188 | return !is_null( $this->findUsername( $name ) ); |
165 | 189 | } |
166 | 190 | |
167 | | - public function /*bool*/ authenticate( /*string*/ $username, /*string*/ $password ) { |
168 | | - global $caApplicationName, $caImportGroups, $caOverwriteLocalGroups; |
| 191 | + /** |
| 192 | + * @param $username string |
| 193 | + * @param $password string |
| 194 | + * @return bool |
| 195 | + */ |
| 196 | + public function authenticate( $username, $password ) { |
| 197 | + global $caApplicationName; |
169 | 198 | |
170 | 199 | $crowd = $this->getCrowd(); |
171 | 200 | $cred = new caPasswordCredential(); |
— | — | @@ -182,11 +211,16 @@ |
183 | 212 | } |
184 | 213 | } |
185 | 214 | |
186 | | - public function /*void*/ updateUser( /*User*/ &$user ) { |
187 | | - global $caImportGroups, $caOverwriteLocalGroups; |
| 215 | + /** |
| 216 | + * @param $user User |
| 217 | + * @return bool |
| 218 | + */ |
| 219 | + public function updateUser( &$user ) { |
| 220 | + global $caImportGroups, $caOverwriteLocalGroups; |
188 | 221 | |
189 | | - if ( !$caImportGroups ) |
| 222 | + if ( !$caImportGroups ) { |
190 | 223 | return true; |
| 224 | + } |
191 | 225 | |
192 | 226 | /* |
193 | 227 | * Find the groups this user is a member of. |
— | — | @@ -199,27 +233,43 @@ |
200 | 234 | $groups = $groups->out->SOAPGroup; |
201 | 235 | |
202 | 236 | $dbw = wfGetDB( DB_MASTER ); |
203 | | - if ( $caOverwriteLocalGroups ) |
| 237 | + if ( $caOverwriteLocalGroups ) { |
204 | 238 | $dbw->delete( 'user_group', array( 'ug_user' => $user->getId() ) ); |
| 239 | + } |
205 | 240 | |
206 | 241 | foreach ( $groups as $group ) { |
207 | 242 | $user->addGroup( $group->name ); |
208 | 243 | } |
| 244 | + return true; |
209 | 245 | } |
210 | 246 | |
211 | | - public function /*bool*/ autoCreate( /*void*/ ) { |
| 247 | + /** |
| 248 | + * @return bool |
| 249 | + */ |
| 250 | + public function autoCreate() { |
212 | 251 | return true; |
213 | 252 | } |
214 | 253 | |
215 | | - public function /*bool*/ strict( /*void*/ ) { |
| 254 | + /** |
| 255 | + * @return bool |
| 256 | + */ |
| 257 | + public function strict() { |
216 | 258 | return true; |
217 | 259 | } |
218 | 260 | |
219 | | - public function /*bool*/ allowPasswordChange( /*void*/ ) { |
| 261 | + /** |
| 262 | + * @return bool |
| 263 | + */ |
| 264 | + public function allowPasswordChange() { |
220 | 265 | return true; |
221 | 266 | } |
222 | 267 | |
223 | | - public function /*bool*/ setPassword( /*User*/ $user, /*string*/ $password ) { |
| 268 | + /** |
| 269 | + * @param $user User |
| 270 | + * @param $password string |
| 271 | + * @return bool |
| 272 | + */ |
| 273 | + public function setPassword( $user, $password ) { |
224 | 274 | $newcred = new caPasswordCredential; |
225 | 275 | $newcred->credential = $password; |
226 | 276 | $username = $this->findUsername( $user->getName() ); |
— | — | @@ -235,21 +285,33 @@ |
236 | 286 | } |
237 | 287 | } |
238 | 288 | |
239 | | - public function /*bool*/ canCreateAccounts( /*void*/ ) { |
| 289 | + /** |
| 290 | + * @return bool |
| 291 | + */ |
| 292 | + public function canCreateAccounts() { |
240 | 293 | return true; |
241 | 294 | } |
242 | 295 | |
243 | | - public function /*bool*/ addUser( /*User*/ $user, /*string*/ $password, |
244 | | - /*string*/ $email = '', /*string*/ $realname = '' ) { |
245 | | - global $caDefaultGroups; |
| 296 | + /** |
| 297 | + * @param $user User |
| 298 | + * @param $password string |
| 299 | + * @param $email string |
| 300 | + * @param $realname string |
| 301 | + * @return bool |
| 302 | + */ |
| 303 | + public function addUser( $user, $password, $email = '', $realname = '' ) { |
| 304 | + global $caDefaultGroups; |
246 | 305 | $crowd = $this->getCrowd(); |
247 | 306 | $nameparts = split( " ", $realname, 2 ); |
248 | 307 | $firstname = $user->getName(); |
249 | 308 | $lastname = ""; |
250 | | - if ( count( $nameparts ) > 0 ) |
| 309 | + if ( count( $nameparts ) > 0 ) { |
251 | 310 | $firstname = $nameparts[0]; |
252 | | - if ( count( $nameparts ) > 1 ) |
253 | | - $lastname = $nameparts[1]; |
| 311 | + |
| 312 | + if ( count( $nameparts ) > 1 ) { |
| 313 | + $lastname = $nameparts[1]; |
| 314 | + } |
| 315 | + } |
254 | 316 | $cred = new caPasswordCredential(); |
255 | 317 | $cred->credential = $password; |
256 | 318 | $principal = new caPrincipal(); |
— | — | @@ -271,8 +333,9 @@ |
272 | 334 | $crowd->addPrincipal( array( "in0" => $this->token, |
273 | 335 | "in1" => $principal, |
274 | 336 | "in2" => $cred ) ); |
275 | | - foreach ( $caDefaultGroups as $group ) |
| 337 | + foreach ( $caDefaultGroups as $group ) { |
276 | 338 | $crowd->addPrincipalToGroup( array( "in0" => $this->token, "in1" => $user->getName(), "in2" => $group ) ); |
| 339 | + } |
277 | 340 | |
278 | 341 | return true; |
279 | 342 | } catch ( Exception $e ) { |