| Conditions | 17 |
| Paths | 412 |
| Total Lines | 67 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 35 | function check_authentication($authentication, &$error, &$errorcode, &$errorlabel) |
||
| 36 | { |
||
| 37 | global $db, $conf, $langs; |
||
| 38 | global $dolibarr_main_authentication, $dolibarr_auto_user; |
||
| 39 | |||
| 40 | $fuser = new User($db); |
||
| 41 | |||
| 42 | if (!$error && ($authentication['dolibarrkey'] != $conf->global->WEBSERVICES_KEY)) { |
||
| 43 | $error++; |
||
| 44 | $errorcode = 'BAD_VALUE_FOR_SECURITY_KEY'; |
||
| 45 | $errorlabel = 'Value provided into dolibarrkey entry field does not match security key defined in Webservice module setup'; |
||
| 46 | } |
||
| 47 | |||
| 48 | if (!$error && !empty($authentication['entity']) && !is_numeric($authentication['entity'])) { |
||
| 49 | $error++; |
||
| 50 | $errorcode = 'BAD_PARAMETERS'; |
||
| 51 | $errorlabel = "The entity parameter must be empty (or filled with numeric id of instance if multicompany module is used)."; |
||
| 52 | } |
||
| 53 | |||
| 54 | if (!$error) { |
||
| 55 | $result = $fuser->fetch('', $authentication['login'], '', 0); |
||
| 56 | if ($result < 0) { |
||
| 57 | $error++; |
||
| 58 | $errorcode = 'ERROR_FETCH_USER'; |
||
| 59 | $errorlabel = 'A technical error occurred during fetch of user'; |
||
| 60 | } elseif ($result == 0) { |
||
| 61 | $error++; |
||
| 62 | $errorcode = 'BAD_CREDENTIALS'; |
||
| 63 | $errorlabel = 'Bad value for login or password'; |
||
| 64 | } |
||
| 65 | |||
| 66 | if (!$error && $fuser->statut == 0) { |
||
| 67 | $error++; |
||
| 68 | $errorcode = 'ERROR_USER_DISABLED'; |
||
| 69 | $errorlabel = 'This user has been locked or disabled'; |
||
| 70 | } |
||
| 71 | |||
| 72 | // Validation of login |
||
| 73 | if (!$error) { |
||
| 74 | $fuser->getrights(); // Load permission of user |
||
| 75 | |||
| 76 | // Authentication mode |
||
| 77 | if (empty($dolibarr_main_authentication)) { |
||
| 78 | $dolibarr_main_authentication = 'http,dolibarr'; |
||
| 79 | } |
||
| 80 | // Authentication mode: forceuser |
||
| 81 | if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) { |
||
| 82 | $dolibarr_auto_user = 'auto'; |
||
| 83 | } |
||
| 84 | // Set authmode |
||
| 85 | $authmode = explode(',', $dolibarr_main_authentication); |
||
| 86 | |||
| 87 | include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
||
| 88 | $login = checkLoginPassEntity($authentication['login'], $authentication['password'], $authentication['entity'], $authmode, 'ws'); |
||
| 89 | if ($login === '--bad-login-validity--') { |
||
| 90 | $login = ''; |
||
| 91 | } |
||
| 92 | |||
| 93 | if (empty($login)) { |
||
| 94 | $error++; |
||
| 95 | $errorcode = 'BAD_CREDENTIALS'; |
||
| 96 | $errorlabel = 'Bad value for login or password'; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | return $fuser; |
||
| 102 | } |
||
| 103 |