conditional_login.class.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. * @param type $user
  13. */
  14. public static function check_conditions($user)
  15. {
  16. if (file_exists(api_get_path(SYS_PATH).'main/auth/conditional_login/conditional_login.php')) {
  17. include_once api_get_path(SYS_PATH).'main/auth/conditional_login/conditional_login.php';
  18. if (isset($login_conditions)) {
  19. foreach ($login_conditions as $condition) {
  20. //If condition fails we redirect to the URL defined by the condition
  21. if (isset($condition['conditional_function']) && $condition['conditional_function']($user) == false) {
  22. $_SESSION['conditional_login']['uid'] = $user['user_id'];
  23. $_SESSION['conditional_login']['can_login'] = false;
  24. header("Location:".$condition['url']);
  25. exit();
  26. }
  27. }
  28. }
  29. }
  30. }
  31. public static function login()
  32. {
  33. $_SESSION['conditional_login']['can_login'] = true;
  34. LoginRedirection::redirect();
  35. }
  36. }