Skip to content
Snippets Groups Projects
Commit 959f211a authored by Tim Steiner's avatar Tim Steiner
Browse files

Get rid of the "You must be logged in..." errors. Just redirect the user to the login page.

parent 25b92c8c
Branches
No related tags found
No related merge requests found
......@@ -96,7 +96,7 @@ class Auth_UserModel extends Unl_Model {
{
$username = Zend_Auth::getInstance()->getIdentity();
if (!$username) {
throw new Exception('You must be logged in to view this page.');
self::authenticateUser(TRUE);
}
return self::findByUsername($username);
......@@ -405,6 +405,39 @@ class Auth_UserModel extends Unl_Model {
$db->query($sql);
}
/**
* If the user is not currently logged in, calling this will attempt to log them in
* and if $required is TRUE, additionally redirect them to the login page.
* @param bool $required
*/
static public function authenticateUser($required = FALSE)
{
$redirectUri = $_SERVER['REQUEST_URI'];
$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
$redirectUri = substr($redirectUri, strlen($baseUrl));
$authSession = new Zend_Session_Namespace('Auth_IndexController');
$authSession->referer = $redirectUri;
if ($_SERVER['HTTPS'] == 'on') {
$serviceUrl = 'https://';
} else {
$serviceUrl = 'http://';
}
$serviceUrl .= $_SERVER['SERVER_NAME'] . Zend_Controller_Front::getInstance()->getBaseUrl() . '/auth/index/validate';
$casAdapter = new Unl_Auth_Adapter_Cas($serviceUrl, 'https://login.unl.edu/cas');
if (!$required) {
$casAdapter->setGateway();
}
if ($casAdapter->isTicketExpired() || !Zend_Auth::getInstance()->hasIdentity()) {
header('Location: ' . $casAdapter->getLoginUrl());
exit;
}
}
public function __toString()
{
return $this->getFirstName() . ' ' . $this->getLastName();
......
......@@ -16,7 +16,6 @@ class Requests_IndexController extends App_Controller_Action
*/
public function indexAction()
{
$this->_authorize->requireLogin();
$in = $this->getRequest()->getParams();
$user = Auth_UserModel::findCurrentUser();
......
......@@ -35,29 +35,6 @@ class App_Controller_Action extends Unl_Controller_Action
return;
}
// Do a passive authentication check
$redirectUri = $_SERVER['REQUEST_URI'];
$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
$redirectUri = substr($redirectUri, strlen($baseUrl));
$authSession = new Zend_Session_Namespace('Auth_IndexController');
$authSession->referer = $redirectUri;
if ($_SERVER['HTTPS'] == 'on') {
$serviceUrl = 'https://';
} else {
$serviceUrl = 'http://';
}
$serviceUrl .= $_SERVER['SERVER_NAME'] . Zend_Controller_Front::getInstance()->getBaseUrl() . '/auth/index/validate';
$casAdapter = new Unl_Auth_Adapter_Cas($serviceUrl, 'https://login.unl.edu/cas', $this->_getParam('ticket'));
$casAdapter->setGateway();
if ($casAdapter->isTicketExpired()) {
$this->_redirect($casAdapter->getLoginUrl());
}
Auth_UserModel::authenticateUser();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment