/**
* провкрка авторизации по конфигу
* @return type
* @throws HTTP_Exception_401
*/
private function checkAuth()
{
if (!class_exists("Kohana_Auth")) {
return;
}
$haveAccess = NULL;
$authConfig = Kohana::$config->load("structure.kohana.auth");
$authRoles = explode(",", $authConfig['roles']);
if ($authConfig['enabled']) {
$this->auth = Auth::instance();
$user = $this->auth->get_user();
if (!$user) {
throw new HTTP_Exception_401();
}
$roles = $user->roles->find_all()->as_array();
foreach ($roles as $userRole) {
$userRoles[] = $userRole->name;
}
foreach ($userRoles as $currentUserRole) {
if (in_array($currentUserRole, $authRoles)) {
$haveAccess = $currentUserRole;
}
}
if (!$haveAccess) {
throw new HTTP_Exception_401();
}
}
return $haveAccess;
}