00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/Action.php';
00026 require_once FASTFRAME_ROOT . 'lib/FastFrame/Hooks.php';
00027
00028
00029
00030
00040
00041 class FF_Action_LoginSubmit extends FF_Action {
00042
00043
00050 function run()
00051 {
00052
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
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
00064
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
00081 $o_profileModel->setId($s_userId);
00082 FF_Auth::setCredential('userId', $s_userId);
00083
00084
00085 $o_hooks->run('login', array($o_profileModel->getLastLogin()));
00086
00087
00088 $o_profileModel->fillById($s_userId);
00089
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
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
00139 $s_redirectURL = FastFrame::url($s_redirectURL, array(), true);
00140 }
00141
00142
00143
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
00160
00167 function getProblemMessage()
00168 {
00169 return _('Login failed. Please check your username and password and try again.');
00170 }
00171
00172
00173
00174
00181 function setProblemActionId()
00182 {
00183 $this->o_nextAction->setNextActionId(ACTION_LOGIN);
00184 }
00185
00186
00187
00188
00195 function setSuccessActionId()
00196 {
00197 $this->o_nextAction->setNextActionId(ACTION_DISPLAY);
00198 }
00199
00200
00201
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 ?>