authentify_password.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../../main/inc/global.inc.php';
  5. $plugin = WhispeakAuthPlugin::create();
  6. $plugin->protectTool();
  7. $userId = ChamiloSession::read(WhispeakAuthPlugin::SESSION_2FA_USER, 0) ?: api_get_user_id();
  8. /** @var array $lpItemInfo */
  9. $lpItemInfo = ChamiloSession::read(WhispeakAuthPlugin::SESSION_LP_ITEM, []);
  10. /** @var learnpath $oLp */
  11. $oLp = ChamiloSession::read('oLP', null);
  12. /** @var array $lpQuestionInfo */
  13. $lpQuestionInfo = ChamiloSession::read(WhispeakAuthPlugin::SESSION_QUIZ_QUESTION, []);
  14. /** @var Exercise $objExercise */
  15. $objExercise = ChamiloSession::read('objExercise', null);
  16. $isAuthOnLp = !empty($lpItemInfo) && !empty($oLp);
  17. $isAuthOnQuiz = !empty($lpQuestionInfo) && !empty($objExercise);
  18. $showFullPage = !$isAuthOnLp && !$isAuthOnQuiz;
  19. if (empty($userId)) {
  20. api_not_allowed($showFullPage);
  21. }
  22. if (!empty($lpQuestionInfo) && empty($lpItemInfo)) {
  23. echo Display::return_message(
  24. $plugin->get_lang('MaxAttemptsReached').'<br>'
  25. .'<strong>'.$plugin->get_lang('LoginWithUsernameAndPassword').'</strong>',
  26. 'warning',
  27. false
  28. );
  29. }
  30. $form = new FormValidator(
  31. 'form-login',
  32. 'POST',
  33. api_get_path(WEB_PLUGIN_PATH).'whispeakauth/ajax/authentify_password.php',
  34. null,
  35. null,
  36. FormValidator::LAYOUT_BOX_NO_LABEL
  37. );
  38. $form->addElement(
  39. 'password',
  40. 'password',
  41. get_lang('Pass'),
  42. ['id' => 'password', 'icon' => 'lock fa-fw', 'placeholder' => get_lang('Pass')]
  43. );
  44. $form->addHidden('sec_token', '');
  45. $form->setConstants(['sec_token' => Security::get_token()]);
  46. $form->addButton('submitAuth', get_lang('LoginEnter'), 'check', 'primary', 'default', 'btn-block');
  47. $template = new Template(
  48. !$showFullPage ? '' : $plugin->get_title(),
  49. $showFullPage,
  50. $showFullPage,
  51. false,
  52. true,
  53. false
  54. );
  55. $template->assign('form', $form->returnForm());
  56. $content = $template->fetch('whispeakauth/view/authentify_password.html.twig');
  57. if (!empty($lpQuestionInfo) && empty($lpItemInfo)) {
  58. echo $content;
  59. exit;
  60. }
  61. $template->assign('header', $plugin->get_title());
  62. $template->assign('content', $content);
  63. $template->display_one_col_template();