Pluing: Whispeak validate maximum attempts - refs BT#15820

pull/3377/head
Angel Fernando Quiroz Campos 6 years ago
parent 7fbd1c0d64
commit b2dd661fa2
  1. 2
      plugin/whispeakauth/WhispeakAuthPlugin.php
  2. 41
      plugin/whispeakauth/ajax/record_audio.php
  3. 4
      plugin/whispeakauth/lang/english.php
  4. 4
      plugin/whispeakauth/lang/french.php
  5. 4
      plugin/whispeakauth/lang/spanish.php

@ -18,6 +18,8 @@ class WhispeakAuthPlugin extends Plugin
const API_URL = 'http://api.whispeak.io:8080/v1.1/';
const SESSION_FAILED_LOGINS = 'whispeak_failed_logins';
/**
* StudentFollowUpPlugin constructor.
*/

@ -22,6 +22,8 @@ if ($isEnrollment) {
$isAllowed = !empty($_FILES['audio']);
} elseif ($isAuthentify) {
$isAllowed = !empty($_POST['username']) && !empty($_FILES['audio']);
} else {
$isAllowed = false;
}
if (!$isAllowed) {
@ -34,7 +36,13 @@ $plugin = WhispeakAuthPlugin::create();
$plugin->protectTool(false);
$failedLogins = 0;
$maxAttempts = 0;
if ($isAuthentify) {
$failedLogins = ChamiloSession::read(WhispeakAuthPlugin::SESSION_FAILED_LOGINS, 0);
$maxAttempts = $plugin->getMaxAttempts();
$em = Database::getManager();
/** @var User|null $user */
$user = $em->getRepository('ChamiloUserBundle:User')->findOneBy(['username' => $_POST['username']]);
@ -93,9 +101,9 @@ if ($isEnrollment) {
$qualityNote = !empty($enrollmentResult['quality']) ? explode('|', $enrollmentResult['quality']) : [];
$qualityNote = array_map('ucfirst', $qualityNote);
if ($reliability <= 0) {
$message = $plugin->get_lang('EnrollmentSignature0');
} else {
$message = $plugin->get_lang('EnrollmentSignature0');
if ($reliability > 0) {
$plugin->saveEnrollment($user, $enrollmentResult['wsid']);
$message = '<strong>'.$plugin->get_lang('EnrollmentSuccess').'</strong>';
@ -115,16 +123,22 @@ if ($isEnrollment) {
}
if ($isAuthentify) {
if ($maxAttempts && $failedLogins >= $maxAttempts) {
echo Display::return_message($plugin->get_lang('MaxAttemptsReached'), 'warning');
exit;
}
$wsid = WhispeakAuthPlugin::getAuthUidValue($user->getId());
try {
if (empty($wsid)) {
throw new Exception($plugin->get_lang('AuthentifyFailed'));
throw new Exception();
}
$authentifyResult = $plugin->authentify($wsid->getValue(), $newFullPath);
} catch (Exception $exception) {
echo Display::return_message($plugin->get_lang('AuthentifyFailed'), 'error');
echo Display::return_message($plugin->get_lang('TryAgain'), 'error');
exit;
}
@ -133,14 +147,22 @@ if ($isAuthentify) {
$qualityNote = !empty($authentifyResult['quality']) ? explode('|', $authentifyResult['quality']) : [];
$qualityNote = array_map('ucfirst', $qualityNote);
$message = $plugin->get_lang('AuthentifySuccess');
if (!$success) {
$message = $plugin->get_lang('TryAgain');
} else {
$message = $plugin->get_lang('AuthentifySuccess');
$message = $plugin->get_lang('AuthentifyFailed');
ChamiloSession::write(WhispeakAuthPlugin::SESSION_FAILED_LOGINS, ++$failedLogins);
if ($maxAttempts && $failedLogins >= $maxAttempts) {
$message .= PHP_EOL.$plugin->get_lang('MaxAttemptsReached');
} else {
$message .= PHP_EOL.$plugin->get_lang('TryAgain');
}
}
foreach ($qualityNote as $note) {
$message .= PHP_EOL.'<br>'.$plugin->get_lang("AudioQuality$note");
$message .= '<br>'.PHP_EOL.$plugin->get_lang("AudioQuality$note");
}
echo Display::return_message(
@ -156,6 +178,7 @@ if ($isAuthentify) {
'uidReset' => true,
];
ChamiloSession::erase(WhispeakAuthPlugin::SESSION_FAILED_LOGINS);
ChamiloSession::write('_user', $loggedUser);
Login::init_user($user->getId(), true);

@ -41,4 +41,6 @@ $strings['AudioQualityNoisy'] = 'Too noisy audio';
$strings['AudioQualityFrequency'] = 'Missing some audio frequencies';
$strings['AudioQualityPoorness'] = 'Too poor general audio quality';
$strings['AgreeAllowResearch'] = 'I agree to allow the use of data for research (no commercial usage)';
$strings['AgreeAllowResearch'] = 'I agree to allow the use of data for research (no commercial usage).';
$strings['MaxAttemptsReached'] = 'You reached the maximum number of attempts allowed.';

@ -40,3 +40,7 @@ $strings['AudioQualityLoud'] = 'Too loud audio';
$strings['AudioQualityNoisy'] = 'Too noisy audio';
$strings['AudioQualityFrequency'] = 'Missing some audio frequencies';
$strings['AudioQualityPoorness'] = 'Too poor general audio quality';
$strings['AgreeAllowResearch'] = 'I agree to allow the use of data for research (no commercial usage).';
$strings['MaxAttemptsReached'] = 'You reached the maximum number of attempts allowed.';

@ -40,3 +40,7 @@ $strings['AudioQualityLoud'] = 'Audio demasiado alto';
$strings['AudioQualityNoisy'] = 'Audio demasiado ruidoso';
$strings['AudioQualityFrequency'] = 'Falta algunas frecuencias de audio';
$strings['AudioQualityPoorness'] = 'Calidad de audio general demasiado pobre';
$strings['AgreeAllowResearch'] = 'Estoy de acuerdo en permitir el uso de datos para investigación (no uso comercial).';
$strings['MaxAttemptsReached'] = 'Ha alcanzado el número máximo de intentos permitidos.';

Loading…
Cancel
Save