Enable API after user login success and returns authentication token, helps for external applications
This commit is contained in:
parent
c943506ff8
commit
142159a8e9
|
@ -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));
|
||||||
|
|
||||||
|
?>
|
|
@ -26,6 +26,9 @@ function checkLogin($args)
|
||||||
// Renew the token. This token will be the same inside the session for multiple forms.
|
// Renew the token. This token will be the same inside the session for multiple forms.
|
||||||
$security->generateTokenCSRF();
|
$security->generateTokenCSRF();
|
||||||
|
|
||||||
|
if (isset($_GET['enableAPI'])) {
|
||||||
|
Redirect::page('api');
|
||||||
|
}
|
||||||
Redirect::page('dashboard');
|
Redirect::page('dashboard');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue