PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/lib/ws.lib.php

https://github.com/asterix14/dolibarr
PHP | 90 lines | 45 code | 11 blank | 34 comment | 18 complexity | f1dd76317f9661731e66bf2010c84e0c MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/lib/ws.lib.php
  20. * \ingroup webservices
  21. * \brief Set of function for manipulating web services
  22. */
  23. /**
  24. * Check authentication array and set error, errorcode, errorlabel
  25. *
  26. * @param array $authentication Array with authentication informations ('login'=>,'password'=>,'entity'=>,'dolibarrkey'=>)
  27. * @param int &$error Number of errors
  28. * @param string &$errorcode Error string code
  29. * @param string &$errorlabel Error string label
  30. * @return User Return user object identified by login/pass/entity into authentication array
  31. */
  32. function check_authentication($authentication,&$error,&$errorcode,&$errorlabel)
  33. {
  34. global $db,$conf,$langs;
  35. global $dolibarr_main_authentication,$dolibarr_auto_user;
  36. $fuser=new User($db);
  37. if (! $error && ($authentication['dolibarrkey'] != $conf->global->WEBSERVICES_KEY))
  38. {
  39. $error++;
  40. $errorcode='BAD_VALUE_FOR_SECURITY_KEY'; $errorlabel='Value provided into dolibarrkey entry field does not match security key defined in Webservice module setup';
  41. }
  42. if (! $error && ! empty($authentication['entity']) && ! is_numeric($authentication['entity']))
  43. {
  44. $error++;
  45. $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter entity must be empty (or filled with numeric id of instance if multicompany module is used).";
  46. }
  47. if (! $error)
  48. {
  49. $result=$fuser->fetch('',$authentication['login'],'',0);
  50. if ($result < 0)
  51. {
  52. $error++;
  53. $errorcode='ERROR_FETCH_USER'; $errorlabel='A technical error occurs during fetch of user';
  54. }
  55. else if ($result == 0)
  56. {
  57. $error++;
  58. $errorcode='BAD_CREDENTIALS'; $errorlabel='Bad value for login or password';
  59. }
  60. // Validation of login
  61. if (! $error)
  62. {
  63. // Authentication mode
  64. if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr';
  65. // Authentication mode: forceuser
  66. if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto';
  67. // Set authmode
  68. $authmode=explode(',',$dolibarr_main_authentication);
  69. $login = checkLoginPassEntity($authentication['login'],$authentication['password'],$authentication['entity'],$authmode);
  70. if (empty($login))
  71. {
  72. $error++;
  73. $errorcode='BAD_CREDENTIALS'; $errorlabel='Bad value for login or password';
  74. }
  75. }
  76. }
  77. return $fuser;
  78. }
  79. ?>