LoginSubmit.php

Go to the documentation of this file.
00001 <?php
00003 // {{{ license
00004 
00005 // +----------------------------------------------------------------------+
00006 // | FastFrame Application Framework                                      |
00007 // +----------------------------------------------------------------------+
00008 // | Copyright (c) 2002-2006 The Codejanitor Group                        |
00009 // +----------------------------------------------------------------------+
00010 // | This source file is subject to the GNU Lesser Public License (LGPL), |
00011 // | that is bundled with this package in the file LICENSE, and is        |
00012 // | available at through the world-wide-web at                           |
00013 // | http://www.fsf.org/copyleft/lesser.html                              |
00014 // | If you did not receive a copy of the LGPL and are unable to          |
00015 // | obtain it through the world-wide-web, you can get it by writing the  |
00016 // | Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
00017 // | MA 02111-1307, USA.                                                  |
00018 // +----------------------------------------------------------------------+
00019 // | Authors: Jason Rust <jrust@codejanitor.com>                          |
00020 // +----------------------------------------------------------------------+
00021 
00022 // }}}
00023 // {{{ requires
00024 
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/Action.php';
00026 require_once FASTFRAME_ROOT . 'lib/FastFrame/Hooks.php';
00027 
00028 // }}}
00029 // {{{ class FF_Action_LoginSubmit
00030 
00040 // }}}
00041 class FF_Action_LoginSubmit extends FF_Action {
00042     // {{{ run()
00043     
00050     function run()
00051     {
00052         // isAdminLogin is used when logging into another user's account via profile list
00053         if (FF_Request::getParam('isAdminLogin', 's', false) ||
00054             (($o_result = FF_Auth::authenticate(FF_Request::getParam('username', 'p'), FF_Request::getParam('password', 'p'))) && $o_result->isSuccess())) {
00055             $o_hooks =& FF_Hooks::singleton();
00056             // If the profile application is installed then set the user Id
00057             if ($this->o_registry->hasApp('profile')) {
00058                 require_once $this->o_registry->getAppFile('Model/ProfileManager.php', 'profile', 'libs');
00059                 $o_profileManager =& new FF_Model_ProfileManager();
00060                 $o_profileModel =& $o_profileManager->getModelObject('profile');
00061                 $s_userId = $o_profileModel->getIdByUsername(FF_Auth::getCredential('username'), 
00062                         FF_Auth::getCredential('authSource'));
00063                 // if they were able to log on, but don't have a user id, then they logged on
00064                 // with an auth source other than the profile database, so give them an empty profile
00065                 if (is_null($s_userId)) {
00066                     $o_profileModel->setUsername(FF_Auth::getCredential('username'));
00067                     $o_profileModel->setAuthSource(FF_Auth::getCredential('authSource'));
00068                     $o_result =& $o_profileManager->addMinimalProfile();
00069                     if (!$o_result->isSuccess()) {
00070                         $this->o_output->setMessage(_('Error encountered in creating your profile.'));
00071                         $this->o_output->setMessage($o_result->getMessages());
00072                         $this->setProblemActionId();
00073                         return $this->o_nextAction;
00074                     }
00075                     else {
00076                         $s_userId = $o_profileModel->getId();
00077                     }
00078                 }
00079 
00080                 // Load in some of their profile settings as credentials
00081                 $o_profileModel->setId($s_userId);
00082                 FF_Auth::setCredential('userId', $s_userId); 
00083 
00084                 // Now that defaults are loaded, run the login hooks
00085                 $o_hooks->run('login', array($o_profileModel->getLastLogin()));
00086 
00087                 // Now that anything that could affect their profile is done, update a few things
00088                 $o_profileModel->fillById($s_userId);
00089                 // See if their profile has been marked inactive
00090                 if ($o_profileModel->getIsInactive()) {
00091                     FF_Auth::logout();
00092                     $this->o_output->setMessage(_('Your account is inactive.  Please contact your system administrator'), FASTFRAME_ERROR_MESSAGE);
00093                     $this->setProblemActionId();
00094                     return $this->o_nextAction;
00095                 }
00096 
00097                 $s_theme = $o_profileModel->getTheme();
00098                 $s_lang = $o_profileModel->getLanguage(); 
00099                 FF_Request::setParam('searchBoxType', $o_profileModel->getListMode(), 's');
00100                 FF_Request::setParam('defDispLimit', $o_profileModel->getListLength(), 's');
00101                 
00102                 if (($a_initPage = $this->getAppByHostName()) == null ) {
00103                     $a_initPage = $o_profileModel->getInitialPage();
00104                 }
00105                 $o_profileModel->setLastLogin(time(), true);
00106                 FF_Auth::setCredential('isProfileComplete', $o_profileManager->isProfileComplete($s_userId));
00107             }
00108             else {
00109                 FF_Auth::setCredential('userId', 0);
00110                 $o_hooks->run('login', array(0));
00111                 $s_theme = $this->o_registry->getConfigParam('general/default_theme');
00112                 $s_lang = FF_Locale::selectLang(); 
00113                 if (($a_initPage = $this->getAppByHostName()) == null ) {
00114                     $tmp_app = $this->o_registry->getConfigParam('general/initial_app'); 
00115                     $tmp_module = $this->o_registry->getConfigParam('general/initial_module', null, $tmp_app); 
00116                     $a_initPage = array('app' => $tmp_app, 'module' => $tmp_module, 'actionId' => null);
00117                 }
00118             
00119             }
00120 
00121             FF_Auth::setCredential('theme', $s_theme);
00122             FF_Auth::setCredential('language', $s_lang);
00123             FF_Auth::setCredential('initPage', $a_initPage);
00124 
00125             // login is successful proceed to initial app or where we came from
00126             $s_redirectURL = FF_Request::getParam('loginRedirect', 'p');
00127             if (empty($s_redirectURL)) {
00128                 if ($a_initPage['app'] != $this->o_registry->getCurrentApp()) {
00129                     $a_initPage['actionId'] = false;
00130                     $s_redirectURL = FastFrame::selfURL($a_initPage, true);
00131                 }
00132                 else {
00133                     $s_redirectURL = FastFrame::selfURL(array('actionId' => ACTION_DISPLAY,
00134                                 'module' => '', 'app' => $this->o_registry->getCurrentApp()), true);
00135                 }
00136             }
00137             else {
00138                 // This adds the session to the url and makes sure the ssl part is correct
00139                 $s_redirectURL = FastFrame::url($s_redirectURL, array(), true);
00140             }
00141 
00142             // Always redirect on successful login.  This prevents the user from hitting
00143             // hitting the back button after logout and re-submitting the login form.
00144             FastFrame::redirect($s_redirectURL, true);
00145         }
00146         else {
00147             if (is_object($o_result)) {
00148                 $this->o_output->setMessage($o_result->getMessages(), FASTFRAME_WARNING_MESSAGE);
00149             }
00150 
00151             $this->o_output->setMessage($this->getProblemMessage(), FASTFRAME_ERROR_MESSAGE);
00152             $this->setProblemActionId();
00153         }
00154 
00155         return $this->o_nextAction;
00156     }
00157 
00158     // }}}
00159     // {{{ getProblemMessage()
00160 
00167     function getProblemMessage()
00168     {
00169         return _('Login failed.  Please check your username and password and try again.');
00170     }
00171 
00172     // }}}
00173     // {{{ setProblemActionId()
00174 
00181     function setProblemActionId()
00182     {
00183         $this->o_nextAction->setNextActionId(ACTION_LOGIN);
00184     }
00185 
00186     // }}}
00187     // {{{ setSuccessActionId()
00188 
00195     function setSuccessActionId()
00196     {
00197         $this->o_nextAction->setNextActionId(ACTION_DISPLAY);
00198     }
00199 
00200     // }}}
00201     // {{{ getAppByHostName()
00202 
00203     function getAppByHostName()
00204     {
00205         foreach ($this->o_registry->getApps() as $s_app) {
00206             $m_hosts = (array) $this->o_registry->getAppParam('hostnames', array(), $s_app); 
00207             foreach ($m_hosts as $s_host ) {
00208                 if (FF_Request::getParam('orig_hostname', 'p') == $s_host ) {
00209                     return array('app' => $s_app, 'module' => '', 'actionId' => '');
00210                 }
00211             }
00212         }
00213 
00214         return null;
00215     }
00216             
00217     // }}}
00218 }
00219 ?>

Generated on Fri Jun 23 11:38:17 2006 for FastFrame by  doxygen 1.4.4