mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Cleaning up the AuthComponent
Simplify if statements, return early and less variable use
This commit is contained in:
parent
51e0715001
commit
2c70319d27
1 changed files with 35 additions and 33 deletions
|
@ -300,23 +300,24 @@ class AuthComponent extends Component {
|
|||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (!$this->_getUser()) {
|
||||
if (!$request->is('ajax')) {
|
||||
$this->flash($this->authError);
|
||||
$this->Session->write('Auth.redirect', $request->here());
|
||||
$controller->redirect($loginAction);
|
||||
return false;
|
||||
} elseif (!empty($this->ajaxLogin)) {
|
||||
$controller->viewPath = 'Elements';
|
||||
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
|
||||
$this->_stop();
|
||||
return false;
|
||||
} else {
|
||||
$controller->redirect(null, 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->_getUser()) {
|
||||
if (!$request->is('ajax')) {
|
||||
$this->flash($this->authError);
|
||||
$this->Session->write('Auth.redirect', $request->here());
|
||||
$controller->redirect($loginAction);
|
||||
return false;
|
||||
}
|
||||
if (!empty($this->ajaxLogin)) {
|
||||
$controller->viewPath = 'Elements';
|
||||
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
|
||||
$this->_stop();
|
||||
return false;
|
||||
}
|
||||
$controller->redirect(null, 403);
|
||||
}
|
||||
|
||||
if (empty($this->authorize) || $this->isAuthorized($this->user())) {
|
||||
return true;
|
||||
}
|
||||
|
@ -360,7 +361,8 @@ class AuthComponent extends Component {
|
|||
public function isAuthorized($user = null, $request = null) {
|
||||
if (empty($user) && !$this->user()) {
|
||||
return false;
|
||||
} elseif (empty($user)) {
|
||||
}
|
||||
if (empty($user)) {
|
||||
$user = $this->user();
|
||||
}
|
||||
if (empty($request)) {
|
||||
|
@ -428,12 +430,12 @@ class AuthComponent extends Component {
|
|||
$args = func_get_args();
|
||||
if (empty($args) || $action === null) {
|
||||
$this->allowedActions = $this->_methods;
|
||||
} else {
|
||||
if (isset($args[0]) && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
}
|
||||
$this->allowedActions = array_merge($this->allowedActions, $args);
|
||||
return;
|
||||
}
|
||||
if (isset($args[0]) && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
}
|
||||
$this->allowedActions = array_merge($this->allowedActions, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -454,18 +456,18 @@ class AuthComponent extends Component {
|
|||
$args = func_get_args();
|
||||
if (empty($args) || $action === null) {
|
||||
$this->allowedActions = array();
|
||||
} else {
|
||||
if (isset($args[0]) && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
}
|
||||
foreach ($args as $arg) {
|
||||
$i = array_search($arg, $this->allowedActions);
|
||||
if (is_int($i)) {
|
||||
unset($this->allowedActions[$i]);
|
||||
}
|
||||
}
|
||||
$this->allowedActions = array_values($this->allowedActions);
|
||||
return;
|
||||
}
|
||||
if (isset($args[0]) && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
}
|
||||
foreach ($args as $arg) {
|
||||
$i = array_search($arg, $this->allowedActions);
|
||||
if (is_int($i)) {
|
||||
unset($this->allowedActions[$i]);
|
||||
}
|
||||
}
|
||||
$this->allowedActions = array_values($this->allowedActions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue