123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- /* For licensing terms, see /license.txt */
- $cidReset = true;
- require_once __DIR__.'/../../main/inc/global.inc.php';
- $plugin = WhispeakAuthPlugin::create();
- $plugin->protectTool();
- $userId = ChamiloSession::read(WhispeakAuthPlugin::SESSION_2FA_USER, 0) ?: api_get_user_id();
- $showForm = !$userId;
- /** @var array $lpItemInfo */
- $lpItemInfo = ChamiloSession::read(WhispeakAuthPlugin::SESSION_LP_ITEM, []);
- /** @var learnpath $oLp */
- $oLp = ChamiloSession::read('oLP', null);
- /** @var array $lpQuestionInfo */
- $lpQuestionInfo = ChamiloSession::read(WhispeakAuthPlugin::SESSION_QUIZ_QUESTION, []);
- /** @var Exercise $objExercise */
- $objExercise = ChamiloSession::read('objExercise', null);
- $isAuthOnLp = !empty($lpItemInfo) && !empty($oLp);
- $isAuthOnQuiz = !empty($lpQuestionInfo) && !empty($objExercise);
- $showFullPage = !$isAuthOnLp && !$isAuthOnQuiz;
- if (ChamiloSession::read(WhispeakAuthPlugin::SESSION_AUTH_PASSWORD, false)) {
- ChamiloSession::erase(WhispeakAuthPlugin::SESSION_AUTH_PASSWORD);
- $message = Display::return_message(
- $plugin->get_lang('MaxAttemptsReached').'<br>'
- .'<strong>'.$plugin->get_lang('LoginWithUsernameAndPassword').'</strong>',
- 'warning'
- );
- if (empty($lpQuestionInfo)) {
- Display::addFlash($message);
- }
- header('Location: '.api_get_path(WEB_PLUGIN_PATH).'whispeakauth/authentify_password.php');
- exit;
- }
- if ($userId) {
- $wsid = WhispeakAuthPlugin::getAuthUidValue($userId);
- if (empty($wsid)) {
- $message = Display::return_message($plugin->get_lang('SpeechAuthNotEnrolled'), 'warning');
- if (!empty($lpQuestionInfo) && empty($lpItemInfo)) {
- echo $message;
- } else {
- Display::addFlash($message);
- }
- header('Location: '.api_get_path(WEB_PLUGIN_PATH).'whispeakauth/authentify_password.php');
- exit;
- }
- }
- if (!empty($lpQuestionInfo) && empty($lpItemInfo)) {
- echo api_get_js('rtc/RecordRTC.js');
- echo api_get_js_simple(api_get_path(WEB_PLUGIN_PATH).'whispeakauth/assets/js/RecordAudio.js');
- } else {
- $htmlHeadXtra[] = api_get_js('rtc/RecordRTC.js');
- $htmlHeadXtra[] = api_get_js_simple(api_get_path(WEB_PLUGIN_PATH).'whispeakauth/assets/js/RecordAudio.js');
- }
- $sampleText = '';
- try {
- $sampleText = WhispeakAuthRequest::authenticateSentence($plugin);
- } catch (Exception $exception) {
- if ($showFullPage) {
- api_not_allowed(
- true,
- Display::return_message($exception->getMessage(), 'error')
- );
- }
- if (!$showFullPage && $oLp) {
- api_not_allowed(
- false,
- Display::return_message($exception->getMessage(), 'error')
- );
- }
- WhispeakAuthPlugin::displayNotAllowedMessage($exception->getMessage());
- }
- ChamiloSession::write(WhispeakAuthPlugin::SESSION_SENTENCE_TEXT, $sampleText);
- $template = new Template(
- !$showFullPage ? '' : $plugin->get_title(),
- $showFullPage,
- $showFullPage,
- false,
- true,
- false
- );
- $template->assign('show_form', $showForm);
- $template->assign('sample_text', $sampleText);
- $content = $template->fetch('whispeakauth/view/authentify_recorder.html.twig');
- if (!empty($lpQuestionInfo) && empty($lpItemInfo)) {
- echo $content;
- exit;
- }
- $template->assign('header', $plugin->get_title());
- $template->assign('content', $content);
- $template->display_one_col_template();
|