chg: [AppController] move login redirects to dedicated functions

This makes it easier to modify the login redirect behaviour in a unified
way. For now this just uses the default Auth loginAction while setting
the `admin` attribute to `false`. Thus application behaviour should be
unchanged.
pull/5187/head
Andreas Rammhold 2019-05-13 09:17:59 +02:00 committed by Chris Halls
parent d9d03f7c75
commit 9edffd01ba
1 changed files with 9 additions and 3 deletions

View File

@ -342,7 +342,7 @@ class AppController extends Controller
throw new ForbiddenException('Authentication failed. Your user account has been disabled.');
} else {
$this->Flash->error('Your user account has been disabled.', array('key' => 'error'));
$this->redirect(array('controller' => 'users', 'action' => 'login', 'admin' => false));
$this->_redirectToLogin();
}
}
$this->set('default_memory_limit', ini_get('memory_limit'));
@ -362,7 +362,7 @@ class AppController extends Controller
if (!$this->request->is('ajax')) {
$this->Session->write('pre_login_requested_url', $this->here);
}
$this->redirect(array('controller' => 'users', 'action' => 'login', 'admin' => false));
$this->_redirectToLogin();
}
}
@ -400,7 +400,7 @@ class AppController extends Controller
$this->Flash->info($message);
}
$this->Auth->logout();
$this->redirect(array('controller' => 'users', 'action' => 'login', 'admin' => false));
$this->_redirectToLogin();
}
if (!empty(Configure::read('MISP.terms_file')) && !$this->Auth->user('termsaccepted') && (!in_array($this->request->here, array($base_dir.'/users/terms', $base_dir.'/users/logout', $base_dir.'/users/login', $base_dir.'/users/downloadTerms')))) {
//if ($this->_isRest()) throw new MethodNotAllowedException('You have not accepted the terms of use yet, please log in via the web interface and accept them.');
@ -1027,4 +1027,10 @@ class AppController extends Controller
Configure::write('Session', $session);
}
}
private function _redirectToLogin() {
$targetRoute = $this->Auth->loginAction;
$targetRoute['admin'] = false;
$this->redirect($targetRoute);
}
}