2828use auth_userkey \userkey_manager_interface ;
2929use core_external \external_value ;
3030
31- require_once ($ CFG ->libdir . '/authlib.php ' );
31+ require_once ($ CFG ->libdir . '/authlib.php ' );
3232require_once ($ CFG ->dirroot . '/user/lib.php ' );
3333
3434/**
3535 * User key authentication plugin.
3636 */
3737class auth_plugin_userkey extends auth_plugin_base {
38-
3938 /**
4039 * Default mapping field.
4140 */
@@ -53,7 +52,7 @@ class auth_plugin_userkey extends auth_plugin_base {
5352 *
5453 * @var array
5554 */
56- protected $ defaults = array (
55+ protected $ defaults = [
5756 'mappingfield ' => self ::DEFAULT_MAPPING_FIELD ,
5857 'keylifetime ' => 60 ,
5958 'iprestriction ' => 0 ,
@@ -62,7 +61,7 @@ class auth_plugin_userkey extends auth_plugin_base {
6261 'ssourl ' => '' ,
6362 'createuser ' => false ,
6463 'updateuser ' => false ,
65- ) ;
64+ ] ;
6665
6766 /**
6867 * Constructor.
@@ -297,14 +296,16 @@ protected function create_user(array $data) {
297296 throw new invalid_parameter_exception ('Unable to create user, missing value(s): ' . implode (', ' , $ missingfields ));
298297 }
299298
300- if ($ DB ->record_exists ('user ' , array ( 'username ' => $ user ['username ' ], 'mnethostid ' => $ CFG ->mnet_localhost_id ) )) {
301- throw new invalid_parameter_exception ('Username already exists: ' . $ user ['username ' ]);
299+ if ($ DB ->record_exists ('user ' , [ 'username ' => $ user ['username ' ], 'mnethostid ' => $ CFG ->mnet_localhost_id ] )) {
300+ throw new invalid_parameter_exception ('Username already exists: ' . $ user ['username ' ]);
302301 }
303302 if (!validate_email ($ user ['email ' ])) {
304- throw new invalid_parameter_exception ('Email address is invalid: ' .$ user ['email ' ]);
305- } else if (empty ($ CFG ->allowaccountssameemail ) &&
306- $ DB ->record_exists ('user ' , array ('email ' => $ user ['email ' ], 'mnethostid ' => $ user ['mnethostid ' ]))) {
307- throw new invalid_parameter_exception ('Email address already exists: ' .$ user ['email ' ]);
303+ throw new invalid_parameter_exception ('Email address is invalid: ' . $ user ['email ' ]);
304+ } else if (
305+ empty ($ CFG ->allowaccountssameemail ) &&
306+ $ DB ->record_exists ('user ' , ['email ' => $ user ['email ' ], 'mnethostid ' => $ user ['mnethostid ' ]])
307+ ) {
308+ throw new invalid_parameter_exception ('Email address already exists: ' . $ user ['email ' ]);
308309 }
309310
310311 $ userid = user_create_user ($ user );
@@ -341,20 +342,20 @@ protected function update_user(\stdClass $user, array $data) {
341342 if (
342343 $ user ->username != $ userdata ['username ' ]
343344 &&
344- $ DB ->record_exists ('user ' , array ( 'username ' => $ userdata ['username ' ], 'mnethostid ' => $ CFG ->mnet_localhost_id ) )
345+ $ DB ->record_exists ('user ' , [ 'username ' => $ userdata ['username ' ], 'mnethostid ' => $ CFG ->mnet_localhost_id ] )
345346 ) {
346- throw new invalid_parameter_exception ('Username already exists: ' . $ userdata ['username ' ]);
347+ throw new invalid_parameter_exception ('Username already exists: ' . $ userdata ['username ' ]);
347348 }
348349 if (!validate_email ($ userdata ['email ' ])) {
349- throw new invalid_parameter_exception ('Email address is invalid: ' . $ userdata ['email ' ]);
350+ throw new invalid_parameter_exception ('Email address is invalid: ' . $ userdata ['email ' ]);
350351 } else if (
351352 empty ($ CFG ->allowaccountssameemail )
352353 &&
353354 $ user ->email != $ userdata ['email ' ]
354355 &&
355- $ DB ->record_exists ('user ' , array ( 'email ' => $ userdata ['email ' ], 'mnethostid ' => $ CFG ->mnet_localhost_id ) )
356+ $ DB ->record_exists ('user ' , [ 'email ' => $ userdata ['email ' ], 'mnethostid ' => $ CFG ->mnet_localhost_id ] )
356357 ) {
357- throw new invalid_parameter_exception ('Email address already exists: ' . $ userdata ['email ' ]);
358+ throw new invalid_parameter_exception ('Email address already exists: ' . $ userdata ['email ' ]);
358359 }
359360 $ userdata ['id ' ] = $ user ->id ;
360361
@@ -402,10 +403,10 @@ protected function get_user(array $data) {
402403
403404 $ mappingfield = $ this ->get_mapping_field ();
404405
405- $ params = array (
406+ $ params = [
406407 $ mappingfield => $ data [$ mappingfield ],
407408 'mnethostid ' => $ CFG ->mnet_localhost_id ,
408- ) ;
409+ ] ;
409410
410411 $ user = $ DB ->get_record ('user ' , $ params );
411412
@@ -476,11 +477,11 @@ public function get_login_url($data) {
476477 * @return array
477478 */
478479 public function get_allowed_mapping_fields () {
479- return array (
480+ return [
480481 'username ' => get_string ('username ' ),
481482 'email ' => get_string ('email ' ),
482483 'idnumber ' => get_string ('idnumber ' ),
483- ) ;
484+ ] ;
484485 }
485486
486487 /**
@@ -493,34 +494,34 @@ protected function get_mapping_parameter() {
493494
494495 switch ($ mappingfield ) {
495496 case 'username ' :
496- $ parameter = array (
497+ $ parameter = [
497498 'username ' => new external_value (
498499 PARAM_USERNAME ,
499500 'Username '
500501 ),
501- ) ;
502+ ] ;
502503 break ;
503504
504505 case 'email ' :
505- $ parameter = array (
506+ $ parameter = [
506507 'email ' => new external_value (
507508 PARAM_EMAIL ,
508509 'A valid email address '
509510 ),
510- ) ;
511+ ] ;
511512 break ;
512513
513514 case 'idnumber ' :
514- $ parameter = array (
515+ $ parameter = [
515516 'idnumber ' => new external_value (
516517 PARAM_RAW ,
517518 'An arbitrary ID code number perhaps from the institution '
518519 ),
519- ) ;
520+ ] ;
520521 break ;
521522
522523 default :
523- $ parameter = array () ;
524+ $ parameter = [] ;
524525 break ;
525526 }
526527
@@ -533,7 +534,7 @@ protected function get_mapping_parameter() {
533534 * @return array
534535 */
535536 protected function get_user_fields_parameters () {
536- $ parameters = array () ;
537+ $ parameters = [] ;
537538
538539 if ($ this ->is_ip_restriction_enabled ()) {
539540 $ parameters ['ip ' ] = new external_value (
@@ -594,7 +595,6 @@ protected function should_login_redirect() {
594595 if (isset ($ this ->config ->ssourl ) && $ this ->config ->ssourl != '' && !$ skipsso ) {
595596 return true ;
596597 }
597-
598598 }
599599
600600 /**
0 commit comments