login.ldap.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // External login module : LDAP
  3. /**
  4. *
  5. * This file is included in main/inc/local.inc.php at user login if the user have 'external_ldap' in
  6. * his auth_source field insted of platform
  7. *
  8. * Variables that can be used :
  9. * - $login : string containing the username posted by the user
  10. * - $password : string containing the password posted by the user
  11. * - $uData : associative array with those keys :
  12. * -username
  13. * -password
  14. * -auth_source
  15. * -active
  16. * -expiration_date
  17. *
  18. * If login succeeds, we have 2 choices :
  19. * 1. - set $loginFailed to false,
  20. * - set $_SESSION['_user']['user_id'] with the dokeos user_id
  21. * - set $uidReset to true
  22. * - upgrade user info in dokeos database if needeed
  23. * - let the script local.inc.php continue
  24. *
  25. * 2. - set $_SESSION['_user']['user_id'] with the dokeos user_id
  26. * - set $_SESSION['_user']['uidReset'] to true
  27. * - upgrade user info in dokeos database if needeed
  28. * - redirect to any page and let local.inc.php do the magic
  29. *
  30. * If login fails we have to redirect to index.php with the right message
  31. * Possible messages are :
  32. * - index.php?loginFailed=1&error=access_url_inactive
  33. * - index.php?loginFailed=1&error=account_expired
  34. * - index.php?loginFailed=1&error=account_inactive
  35. * - index.php?loginFailed=1&error=user_password_incorrect
  36. * - index.php?loginFailed=1&error=unrecognize_sso_origin');
  37. *
  38. * */
  39. use \ChamiloSession as Session;
  40. require_once dirname(__FILE__) . '/ldap.inc.php';
  41. require_once dirname(__FILE__) . '/functions.inc.php';
  42. error_log('Entering login.ldap.php');
  43. $ldap_user = extldap_authenticate($login, $password);
  44. if ($ldap_user !== false) {
  45. error_log('extldap_authenticate works');
  46. $chamilo_user = extldap_get_chamilo_user($ldap_user);
  47. //userid is not on the ldap, we have to use $uData variable from local.inc.php
  48. $chamilo_user['user_id'] = $uData['user_id'];
  49. error_log("chamilo_user found user_id: {$uData['user_id']}");
  50. //Update user info
  51. if (isset($extldap_config['update_userinfo']) && $extldap_config['update_userinfo']) {
  52. external_update_user($chamilo_user);
  53. error_log("Calling external_update_user");
  54. }
  55. $loginFailed = false;
  56. $_user['user_id'] = $chamilo_user['user_id'];
  57. $_user['status'] = (isset($chamilo_user['status']) ? $chamilo_user['status'] : 5);
  58. $_user['uidReset'] = true;
  59. Session::write('_user', $_user);
  60. $uidReset = true;
  61. event_login();
  62. error_log("Calling event_login");
  63. } else {
  64. error_log('extldap_authenticate error');
  65. $loginFailed = true;
  66. $uidReset = false;
  67. unset($_user['user_id']);
  68. }