conditional_login.class.php 1.3 KB

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