login.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Login extends oxAdminView
00008 {
00009 
00013     public function __construct()
00014     {
00015         $this->getConfig()->setConfigParam('blAdmin', true);
00016         $this->_sThisAction = "login";
00017     }
00018 
00025     public function render()
00026     {
00027         $myConfig = $this->getConfig();
00028 
00029         // automatically redirect to SSL login
00030         if (!$myConfig->isSsl() && strpos($myConfig->getConfigParam('sAdminSSLURL'), 'https://') === 0) {
00031             oxRegistry::getUtils()->redirect($myConfig->getConfigParam('sAdminSSLURL'), false, 302);
00032         }
00033 
00034         //resets user once on this screen.
00035         $oUser = oxNew("oxuser");
00036         $oUser->logout();
00037 
00038         oxView::render();
00039 
00040         //if( $myConfig->blDemoMode)
00041         $oBaseShop = oxNew("oxshop");
00042 
00043         $oBaseShop->load($myConfig->getBaseShopId());
00044         $sVersion = $oBaseShop->oxshops__oxversion->value;
00045 
00046         $this->getViewConfig()->setViewConfigParam('sShopVersion', $sVersion);
00047 
00048         if ($myConfig->isDemoShop()) {
00049             // demo
00050             $this->addTplParam("user", "admin");
00051             $this->addTplParam("pwd", "admin");
00052         }
00053         //#533 user profile
00054         $this->addTplParam("profiles", oxRegistry::getUtils()->loadAdminProfile($myConfig->getConfigParam('aInterfaceProfiles')));
00055 
00056         $aLanguages = $this->_getAvailableLanguages();
00057         $this->addTplParam("aLanguages", $aLanguages);
00058 
00059         // setting templates language to selected language id
00060         foreach ($aLanguages as $iKey => $oLang) {
00061             if ($aLanguages[$iKey]->selected) {
00062                 oxRegistry::getLang()->setTplLanguage($iKey);
00063                 break;
00064             }
00065         }
00066 
00067         return "login.tpl";
00068     }
00069 
00075     public function checklogin()
00076     {
00077         $myUtilsServer = oxRegistry::get("oxUtilsServer");
00078         $myUtilsView = oxRegistry::get("oxUtilsView");
00079 
00080         $sUser = oxRegistry::getConfig()->getRequestParameter('user', true);
00081         $sPass = oxRegistry::getConfig()->getRequestParameter('pwd', true);
00082         $sProfile = oxRegistry::getConfig()->getRequestParameter('profile');
00083 
00084         try { // trying to login
00086             $oUser = oxNew("oxuser");
00087             $oUser->login($sUser, $sPass);
00088             $iSubshop = (int) $oUser->oxuser__oxrights->value;
00089             if ($iSubshop) {
00090                 oxRegistry::getSession()->setVariable("shp", $iSubshop);
00091                 oxRegistry::getSession()->setVariable('currentadminshop', $iSubshop);
00092                 oxRegistry::getConfig()->setShopId($iSubshop);
00093             }
00094         } catch (oxUserException $oEx) {
00095             $myUtilsView->addErrorToDisplay('LOGIN_ERROR');
00096             $oStr = getStr();
00097             $this->addTplParam('user', $oStr->htmlspecialchars($sUser));
00098             $this->addTplParam('pwd', $oStr->htmlspecialchars($sPass));
00099             $this->addTplParam('profile', $oStr->htmlspecialchars($sProfile));
00100 
00101             return;
00102         } catch (oxCookieException $oEx) {
00103             $myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
00104             $oStr = getStr();
00105             $this->addTplParam('user', $oStr->htmlspecialchars($sUser));
00106             $this->addTplParam('pwd', $oStr->htmlspecialchars($sPass));
00107             $this->addTplParam('profile', $oStr->htmlspecialchars($sProfile));
00108 
00109             return;
00110         } catch (oxConnectionException $oEx) {
00111             $myUtilsView->addErrorToDisplay($oEx);
00112         }
00113 
00114         // success
00115         oxRegistry::getUtils()->logger("login successful");
00116 
00117         //execute onAdminLogin() event
00118         $oEvenHandler = oxNew("oxSystemEventHandler");
00119         $oEvenHandler->onAdminLogin(oxRegistry::getConfig()->getShopId());
00120 
00121         // #533
00122         if (isset($sProfile)) {
00123             $aProfiles = oxRegistry::getSession()->getVariable("aAdminProfiles");
00124             if ($aProfiles && isset($aProfiles[$sProfile])) {
00125                 // setting cookie to store last locally used profile
00126                 $myUtilsServer->setOxCookie("oxidadminprofile", $sProfile . "@" . implode("@", $aProfiles[$sProfile]), time() + 31536000, "/");
00127                 oxRegistry::getSession()->setVariable("profile", $aProfiles[$sProfile]);
00128             }
00129         } else {
00130             //deleting cookie info, as setting profile to default
00131             $myUtilsServer->setOxCookie("oxidadminprofile", "", time() - 3600, "/");
00132         }
00133 
00134         // languages
00135         $iLang = oxRegistry::getConfig()->getRequestParameter("chlanguage");
00136         $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00137         if (!isset($aLanguages[$iLang])) {
00138             $iLang = key($aLanguages);
00139         }
00140 
00141         $myUtilsServer->setOxCookie("oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/");
00142 
00143         //P
00144         //oxRegistry::getSession()->setVariable( "blAdminTemplateLanguage", $iLang );
00145         oxRegistry::getLang()->setTplLanguage($iLang);
00146 
00147         return "admin_start";
00148     }
00149 
00155     protected function _authorize()
00156     {
00157         // users are always authorized to use login page
00158         return true;
00159     }
00160 
00166     public function getViewId()
00167     {
00168         return strtolower(get_class($this));
00169     }
00170 
00171 
00177     protected function _getAvailableLanguages()
00178     {
00179         $sDefLang = oxRegistry::get("oxUtilsServer")->getOxCookie('oxidadminlanguage');
00180         $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
00181 
00182         $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00183         foreach ($aLanguages as $oLang) {
00184             $oLang->selected = ($sDefLang == $oLang->abbr) ? 1 : 0;
00185         }
00186 
00187         return $aLanguages;
00188     }
00189 
00195     protected function _getBrowserLanguage()
00196     {
00197         return strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
00198     }
00199 }