logincas.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. //----------------------------------------------------------------------
  3. // CAS PLUGIN
  4. //----------------------------------------------------------------------
  5. // Copyright (c) 2006-2007 University Marc Bloch (UMB)
  6. //----------------------------------------------------------------------
  7. // This program is under the terms of the GENERAL PUBLIC LICENSE (GPL)
  8. // as published by the FREE SOFTWARE FOUNDATION. The GPL is available
  9. // through the world-wide-web at http://www.gnu.org/copyleft/gpl.html
  10. //----------------------------------------------------------------------
  11. // Authors: Pierre Cahard
  12. //----------------------------------------------------------------------
  13. // Load required
  14. require '../../inc/global.inc.php';
  15. require_once 'authcas.php';
  16. use ChamiloSession as Session;
  17. global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri;
  18. // phpCAS
  19. /*
  20. If we are not logged and in our browser enter an URL with a name of a course
  21. e.g. http://www.chamilo.fr/chamilo/courses/COURSTESTOSETE/?id_session=0
  22. We go to page api_not_allowed :
  23. > You are not allowed to see this page.
  24. > Sorry, you are not allowed to access this page, or maybe your connection has expired.
  25. > Please click your browser's \"Back\" button or follow the link below to return to the previous page
  26. If we click on the link to go to homepage, some datas are entered in $_SESSION and if we enter our CAS login,
  27. we go to api_not_allowad_page again and again
  28. As a result, if we are not logged on, we have to destroy the session variables, before calling CAS page
  29. */
  30. if (api_is_anonymous()) {
  31. Session::destroy();
  32. }
  33. if (cas_configured()) {
  34. $firstpage = "";
  35. if (isset($_GET['firstpage'])) {
  36. $firstpage = $_GET['firstpage'];
  37. setcookie("GotoCourse", $firstpage);
  38. }
  39. if (!is_object($PHPCAS_CLIENT)) {
  40. phpCAS::client(
  41. $cas_auth_ver,
  42. $cas_auth_server,
  43. $cas_auth_port,
  44. $cas_auth_uri
  45. );
  46. phpCAS::setNoCasServerValidation();
  47. }
  48. phpCAS::forceAuthentication();
  49. header('Location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login'));
  50. } else {
  51. header('Location: '.api_get_path(WEB_PATH));
  52. }