Return authentication error as JSON when script was POSTed to instead of performing a redirect to the login page.

This commit is contained in:
Josh Sherman 2011-01-26 23:42:16 -05:00
parent 477a16a863
commit 95e75226d3

View file

@ -235,12 +235,20 @@ class Controller extends Object
if ($is_authenticated == false)
{
// Sets variable for the destination
$_SESSION['__pickles']['login']['destination'] = $_REQUEST['request'];
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
exit('{ "status": "error", "message": "You are not properly authenticated" }');
}
else
{
// Sets variable for the destination
$_SESSION['__pickles']['login']['destination'] = $_REQUEST['request'];
// Redirect to login page, potentially configured in the config, else /login
header('Location: /' . (isset($this->config->security['login']) ? $this->config->security['login'] : 'login'));
exit;
// Redirect to login page, potentially configured in the config, else /login
header('Location: /' . (isset($this->config->security['login']) ? $this->config->security['login'] : 'login'));
exit;
}
}
}
@ -441,7 +449,7 @@ class Controller extends Object
$module_class = strtr($basename, '/', '_');
$module_filename = SITE_MODULE_PATH . $basename . '.php';
$template_basename = $basename;
$css_class = $module_class;
$css_class = $module_class;
$js_basename = $basename;
// Scrubs class names with hyphens
@ -449,7 +457,7 @@ class Controller extends Object
{
$module_class = preg_replace('/(-(.{1}))/e', 'strtoupper("$2")', $module_class);
}
return array($module_class, $module_filename, $template_basename, $css_class, $js_basename);
}
}