set_temp_password.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * This page aims at requesting a password from a user to access a course
  5. * protected by password. If the password matches the course password, we
  6. * store the fact that user can access it during its session
  7. */
  8. /**
  9. * Initializing context
  10. */
  11. use ChamiloSession as Session;
  12. $cidReset = true;
  13. require_once '../inc/global.inc.php';
  14. $this_section = SECTION_COURSES;
  15. $course_id = isset($_GET['course_id']) ? intval($_GET['course_id']) : null;
  16. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : null;
  17. $user_id = api_get_user_id();
  18. /**
  19. * Security check
  20. */
  21. if (empty($course_id)) {
  22. api_not_allowed();
  23. }
  24. /**
  25. * Code
  26. */
  27. $course_info = api_get_course_info_by_id($course_id);
  28. $tpl = new Template(null);
  29. // Build the form
  30. $form = new FormValidator('set_temp_password', 'POST', api_get_self().'?course_id='.$course_id.'&session_id='.$session_id);
  31. $form->addElement('header', get_lang('CourseRequiresPassword'));
  32. $form->addElement('hidden', 'course_id', $course_id);
  33. $form->addElement('hidden', 'session_id', $session_id);
  34. $form->addElement('password', 'course_password', null, get_lang('Password'));
  35. $form->addButtonSave(get_lang('Accept'));
  36. if ($form->validate()) {
  37. $form_values = $form->exportValues();
  38. if ($form_values['course_password'] === $course_info['registration_code']) {
  39. Session::write('course_password_'.$course_info['real_id'], true);
  40. header('Location: '.api_get_course_url($course_info['code'], $session_id));
  41. exit;
  42. } else {
  43. $tpl->assign('error_message', Display::display_error_message(get_lang('CourseRegistrationCodeIncorrect'), true, true));
  44. }
  45. }
  46. $tpl->assign('form', $form->toHtml());
  47. $content = $tpl->get_template('auth/set_temp_password.tpl');
  48. $tpl->assign('content', $tpl->fetch($content));
  49. $tpl->display_one_col_template();