conditional_login.class.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Conditional login
  5. * Used to implement the loading of custom pages
  6. * 2011, Noel Dieschburg <noel@cblue.be>.
  7. */
  8. class ConditionalLogin
  9. {
  10. /**
  11. * Check conditions based in the $login_conditions see conditional_login.php file.
  12. *
  13. * @param type $user
  14. */
  15. public static function check_conditions($user)
  16. {
  17. $file = api_get_path(SYS_CODE_PATH).'auth/conditional_login/conditional_login.php';
  18. if (file_exists($file)) {
  19. include_once $file;
  20. if (isset($login_conditions)) {
  21. foreach ($login_conditions as $condition) {
  22. //If condition fails we redirect to the URL defined by the condition
  23. if (isset($condition['conditional_function'])) {
  24. $function = $condition['conditional_function'];
  25. $result = $function($user);
  26. if ($result == false) {
  27. $_SESSION['conditional_login']['uid'] = $user['user_id'];
  28. $_SESSION['conditional_login']['can_login'] = false;
  29. header("Location: ".$condition['url']);
  30. exit;
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }
  37. public static function login()
  38. {
  39. $_SESSION['conditional_login']['can_login'] = true;
  40. LoginRedirection::redirect();
  41. }
  42. }