Whispeak: Add revocation page - refs BT#18476

pull/3814/head
Angel Fernando Quiroz Campos 5 years ago
parent cdf5a31897
commit dca33853c5
  1. 55
      plugin/whispeakauth/Request/ApiRequest.php
  2. 15
      plugin/whispeakauth/admin.php
  3. 3
      plugin/whispeakauth/lang/english.php
  4. 3
      plugin/whispeakauth/lang/french.php
  5. 3
      plugin/whispeakauth/lang/spanish.php
  6. 96
      plugin/whispeakauth/revocation.php

@ -98,6 +98,35 @@ class ApiRequest
);
}
/**
* @param \Chamilo\UserBundle\Entity\User $user
*
* @throws \Exception
*
* @return array
*/
public function deleteEnrollment(User $user)
{
$apiKey = $this->plugin->get(\WhispeakAuthPlugin::SETTING_TOKEN);
$langIso = api_get_language_isocode($user->getLanguage());
$userAuthKey = \WhispeakAuthPlugin::getAuthUidValue($user->getId());
if (empty($userAuthKey) || empty($userAuthKey->getValue())) {
throw new \Exception(get_plugin_lang('NoEnrollment', 'WhispeakAuthPlugin'));
}
$queryData = ['speaker' => $userAuthKey->getValue()];
return $this->sendRequest(
'delete',
'enroll',
$apiKey,
$langIso,
[],
$queryData
);
}
/**
* @param string $token
* @param string $audioFilePath
@ -140,27 +169,35 @@ class ApiRequest
* @param string $uri
* @param string $authBearer
* @param string $lang
* @param array $multipart
* @param array $queryParams
*
* @throws \Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return array
*/
private function sendRequest($method, $uri, $authBearer, $lang, array $multipart = [])
private function sendRequest($method, $uri, $authBearer, $lang, array $multipart = [], $queryParams = [])
{
$httpClient = new Client(['base_uri' => $this->plugin->getApiUrl()]);
$options = [];
$options['headers'] = [
'Authorization' => "Bearer $authBearer",
'Accept-Language' => $lang,
];
if ($queryParams) {
$options['query'] = $queryParams;
} else {
$options['multipart'] = $multipart;
}
try {
$responseBody = $httpClient
->request(
$method,
$uri,
[
'headers' => [
'Authorization' => "Bearer $authBearer",
'Accept-Language' => $lang,
],
'multipart' => $multipart,
]
$options
)
->getBody()
->getContents();

@ -126,7 +126,22 @@ $interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
];
$actionsLeft = '';
if (!empty($results)) {
$actionsLeft = Display::url(
Display::return_icon('back.png', $plugin->get_lang('Back'), [], ICON_SIZE_MEDIUM),
api_get_self()
);
}
$actionsRight = Display::url(
Display::return_icon('delete_terms.png', $plugin->get_lang('Revocation'), [], ICON_SIZE_MEDIUM),
'revocation.php'
);
$template = new Template($plugin->get_title());
$template->assign('actions', Display::toolbarAction('whispeak_admin', [$actionsLeft, $actionsRight]));
$template->assign(
'content',
$form->returnForm().PHP_EOL.$pageContent

@ -42,3 +42,6 @@ $strings['ActivityId'] = "Activity ID";
$strings['Success'] = "Success";
$strings['MarkForSpeechAuthentication'] = 'Mark it for speech authentication';
$strings['EnrollmentTitle'] = "Enrollment to generate voice print with Whispeak";
$strings['Revocation'] = "Revocation";
$strings['NoEnrollment'] = "No enrollment.";
$strings['EnrollmentDeleted'] = "Enrollment deleted";

@ -42,3 +42,6 @@ $strings['ActivityId'] = "Activity ID";
$strings['Success'] = "Success";
$strings['MarkForSpeechAuthentication'] = 'Cocher pour l\'authentification par la voix';
$strings['EnrollmentTitle'] = "Enrôlement pour générer l'empreinte vocale avec Whispeak";
$strings['Revocation'] = "Révocation";
$strings['NoEnrollment'] = "Aucune inscription";
$strings['EnrollmentDeleted'] = "Inscription supprimée.";

@ -42,3 +42,6 @@ $strings['ActivityId'] = "Identificador de actividad";
$strings['Success'] = "Satisfactotio";
$strings['MarkForSpeechAuthentication'] = 'Marcarlo para autenticación con voz';
$strings['EnrollmentTitle'] = "Inscripción para generar huella de voz con Whispeak";
$strings['Revocation'] = "Revocación";
$strings['NoEnrollment'] = "Sin inscripción.";
$strings['EnrollmentDeleted'] = "Inscripción anulada.";

@ -0,0 +1,96 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\PluginBundle\Entity\WhispeakAuth\LogEvent;
use Chamilo\PluginBundle\Entity\WhispeakAuth\LogEventLp;
use Chamilo\PluginBundle\Entity\WhispeakAuth\LogEventQuiz;
use Chamilo\PluginBundle\WhispeakAuth\Request\ApiRequest;
$cidReset = true;
require_once __DIR__.'/../../main/inc/global.inc.php';
$plugin = WhispeakAuthPlugin::create();
api_protect_admin_script(true);
$plugin->protectTool();
$pageContent = '';
$form = new FormValidator('frm_revocation', 'GET');
$slctUsers = $form->addSelectAjax(
'users',
get_lang('Users'),
[],
[
'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like',
'id' => 'user_id',
'multiple' => true,
]
);
$form->addButtonSearch(get_lang('Search'));
$form->addRule('users', get_lang('ThisFieldIsRequired'), 'required');
$userIds = [];
if ($form->validate()) {
$formValues = $form->exportValues();
$userIds = $formValues['users'] ?: [];
/** @var int $userId */
foreach ($userIds as $userId) {
$user = api_get_user_entity($userId);
if (null === $user) {
continue;
}
$slctUsers->addOption($user->getCompleteNameWithUsername(), $user->getId());
$request = new ApiRequest();
$pageContent .= Display::page_subheader($user->getCompleteNameWithUsername(), null, 'h4');
try {
$request->deleteEnrollment($user);
$response = WhispeakAuthPlugin::deleteEnrollment($user->getId());
$pageContent .= Display::return_message(
$plugin->get_lang('EnrollmentDeleted'),
'success'
);
} catch (Exception $e) {
$pageContent .= Display::return_message(
$e->getMessage(),
'error'
);
}
}
}
$interbreadcrumb[] = [
'name' => get_lang('Administration'),
'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
];
$interbreadcrumb[] = [
'name' => $plugin->get_title(),
'url' => 'admin.php',
];
$actionsLeft = Display::url(
Display::return_icon('back.png', $plugin->get_lang('Back'), [], ICON_SIZE_MEDIUM),
'admin.php'
);
$pageTitle = $plugin->get_lang('Revocation');
$template = new Template($pageTitle);
$template->assign('actions', Display::toolbarAction('whispeak_admin', [$actionsLeft]));
$template->assign('header', $pageTitle);
$template->assign(
'content',
$form->returnForm().PHP_EOL.$pageContent
);
$template->display_one_col_template();
Loading…
Cancel
Save