conditional_login.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /*
  5. This script is included by local.inc.php to redirect users to some url if some conditions are satisfied.
  6. * Please populate the $login_conditions array with a conditional function and an url.
  7. * If the conditional function returns true the user will be redirected to URL at login.
  8. * This array must be filled for this module to work.
  9. * This is an example asking the user to enter his phone number if it is empty.
  10. * Note you can enter more than one condition in the array. They will be checked in the array order.
  11. */
  12. /**
  13. * Please implements the functions of the $login_conditions array.
  14. * Each of these function will take a user array
  15. * (user_id, username, password (crypted), auth_source, active, expiration_date).
  16. */
  17. $login_conditions = [];
  18. // "Terms and conditions" condition
  19. array_push(
  20. $login_conditions,
  21. [
  22. 'conditional_function' => 'check_platform_legal_conditions',
  23. 'url' => api_get_path(WEB_CODE_PATH).'auth/inscription.php',
  24. ]
  25. );
  26. //array_push($login_conditions, array(
  27. // 'conditional_function' => 'dc_check_phone_number',
  28. // 'url' => api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php'
  29. //));
  30. function dc_check_phone_number($user)
  31. {
  32. $uInfo = api_get_user_info($user['user_id']);
  33. if (empty($uInfo['phone'])) {
  34. return false;
  35. }
  36. return true;
  37. }
  38. /**
  39. * Checks if the user accepted or not the legal conditions.
  40. *
  41. * @param array $user
  42. *
  43. * @return bool true if user pass, false otherwise
  44. */
  45. function check_platform_legal_conditions($user)
  46. {
  47. if (api_get_setting('allow_terms_conditions') === 'true' &&
  48. api_get_setting('load_term_conditions_section') === 'login'
  49. ) {
  50. $termAndConditionStatus = api_check_term_condition($user['user_id']);
  51. // @todo not sure why we need the login password and update_term_status
  52. if ($termAndConditionStatus === false) {
  53. Session::write('term_and_condition', ['user_id' => $user['user_id']]);
  54. return false;
  55. } else {
  56. Session::erase('term_and_condition');
  57. return true;
  58. }
  59. } else {
  60. // No validation user can pass
  61. return true;
  62. }
  63. }