Thanks Patrick! So I guess the solution was (as usual) staring me in the face. And I was trying to make things more complicated than they actually are (also typical for me). I guess it was confusion over what the access variable was doing.
Anyways, I (you) got it to work. Hooray! Here’s the final code for anyone else looking to do something similar, with the extra check for the “forgot password” link added:
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$this->_preventSiteAccess($request);
$this->_preventAdminAccess($request);
$this->_warnUnconfirmedUsers($request);
}
protected function _preventSiteAccess($request)
{
$user = current_user();
$allowAccess = false;
$requestParams = $request->getParams();
if ($requestParams['controller'] == 'users' && $requestParams['action'] == 'login') {
$allowAccess = true;
}
if ($requestParams['module'] == 'guest-user' && $requestParams['action'] == 'register') {
$allowAccess = true;
}
if ($requestParams['controller'] == 'users' && $requestParams['action'] == 'forgot-password') {
$allowAccess = true;
}
// prevent access to site for anyone not logged in, including guests.
if (!$user && !$allowAccess){
$this->_getRedirect()->gotoUrl(WEB_ROOT .'/users/login');
}
}