Enable API after user login success and returns authentication token, helps for external applications

This commit is contained in:
Diego Najar 2019-11-02 17:06:34 +01:00
parent c943506ff8
commit 142159a8e9
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
checkRole(array('admin'));
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
// ============================================================================
// Main after POST
// ============================================================================
activatePlugin('pluginAPI');
$apiURL = DOMAIN_BASE.'api/';
$pluginAPI = getPlugin('pluginAPI');
$apiToken = $pluginAPI->getToken();
$username = $login->username();
$admin = new User($username);
$authToken = $admin->tokenAuth();
$output = array(
'apiURL'=>$apiURL,
'username'=>$username,
'apiToken'=>$apiToken,
'authToken'=>$authToken
);
exit(json_encode($output));
?>

View File

@ -26,6 +26,9 @@ function checkLogin($args)
// Renew the token. This token will be the same inside the session for multiple forms.
$security->generateTokenCSRF();
if (isset($_GET['enableAPI'])) {
Redirect::page('api');
}
Redirect::page('dashboard');
return true;
}