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         //resets user once on this screen.
00030         $oUser = oxNew("oxuser");
00031         $oUser->logout();
00032 
00033         oxView::render();
00034 
00035         //if( $myConfig->blDemoMode)
00036         $oBaseShop = oxNew("oxshop");
00037 
00038         $oBaseShop->load($myConfig->getBaseShopId());
00039         $sVersion = $oBaseShop->oxshops__oxversion->value;
00040 
00041         $this->getViewConfig()->setViewConfigParam('sShopVersion', $sVersion);
00042 
00043         if ($myConfig->isDemoShop()) {
00044             // demo
00045             $this->addTplParam("user", "admin");
00046             $this->addTplParam("pwd", "admin");
00047         }
00048         //#533 user profile
00049         $this->addTplParam("profiles", oxRegistry::getUtils()->loadAdminProfile($myConfig->getConfigParam('aInterfaceProfiles')));
00050 
00051         $aLanguages = $this->_getAvailableLanguages();
00052         $this->addTplParam("aLanguages", $aLanguages);
00053 
00054         // setting templates language to selected language id
00055         foreach ($aLanguages as $iKey => $oLang) {
00056             if ($aLanguages[$iKey]->selected) {
00057                 oxRegistry::getLang()->setTplLanguage($iKey);
00058                 break;
00059             }
00060         }
00061 
00062         return "login.tpl";
00063     }
00064 
00070     public function checklogin()
00071     {
00072         $myUtilsServer = oxRegistry::get("oxUtilsServer");
00073         $myUtilsView = oxRegistry::get("oxUtilsView");
00074 
00075         $sUser = oxRegistry::getConfig()->getRequestParameter('user', true);
00076         $sPass = oxRegistry::getConfig()->getRequestParameter('pwd', true);
00077         $sProfile = oxRegistry::getConfig()->getRequestParameter('profile');
00078 
00079         try { // trying to login
00081             $oUser = oxNew("oxuser");
00082             $oUser->login($sUser, $sPass);
00083             $iSubshop = (int) $oUser->oxuser__oxrights->value;
00084             if ($iSubshop) {
00085                 oxRegistry::getSession()->setVariable("shp", $iSubshop);
00086                 oxRegistry::getSession()->setVariable('currentadminshop', $iSubshop);
00087                 oxRegistry::getConfig()->setShopId($iSubshop);
00088             }
00089         } catch (oxUserException $oEx) {
00090             $myUtilsView->addErrorToDisplay('LOGIN_ERROR');
00091             $oStr = getStr();
00092             $this->addTplParam('user', $oStr->htmlspecialchars($sUser));
00093             $this->addTplParam('pwd', $oStr->htmlspecialchars($sPass));
00094             $this->addTplParam('profile', $oStr->htmlspecialchars($sProfile));
00095 
00096             return;
00097         } catch (oxCookieException $oEx) {
00098             $myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
00099             $oStr = getStr();
00100             $this->addTplParam('user', $oStr->htmlspecialchars($sUser));
00101             $this->addTplParam('pwd', $oStr->htmlspecialchars($sPass));
00102             $this->addTplParam('profile', $oStr->htmlspecialchars($sProfile));
00103 
00104             return;
00105         } catch (oxConnectionException $oEx) {
00106             $myUtilsView->addErrorToDisplay($oEx);
00107         }
00108 
00109         // success
00110         oxRegistry::getUtils()->logger("login successful");
00111 
00112         //execute onAdminLogin() event
00113         $oEvenHandler = oxNew("oxSystemEventHandler");
00114         $oEvenHandler->onAdminLogin(oxRegistry::getConfig()->getShopId());
00115 
00116         // #533
00117         if (isset($sProfile)) {
00118             $aProfiles = oxRegistry::getSession()->getVariable("aAdminProfiles");
00119             if ($aProfiles && isset($aProfiles[$sProfile])) {
00120                 // setting cookie to store last locally used profile
00121                 $myUtilsServer->setOxCookie("oxidadminprofile", $sProfile . "@" . implode("@", $aProfiles[$sProfile]), time() + 31536000, "/");
00122                 oxRegistry::getSession()->setVariable("profile", $aProfiles[$sProfile]);
00123             }
00124         } else {
00125             //deleting cookie info, as setting profile to default
00126             $myUtilsServer->setOxCookie("oxidadminprofile", "", time() - 3600, "/");
00127         }
00128 
00129         // languages
00130         $iLang = oxRegistry::getConfig()->getRequestParameter("chlanguage");
00131         $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00132         if (!isset($aLanguages[$iLang])) {
00133             $iLang = key($aLanguages);
00134         }
00135 
00136         $myUtilsServer->setOxCookie("oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/");
00137 
00138         //P
00139         //oxRegistry::getSession()->setVariable( "blAdminTemplateLanguage", $iLang );
00140         oxRegistry::getLang()->setTplLanguage($iLang);
00141 
00142         return "admin_start";
00143     }
00144 
00150     protected function _authorize()
00151     {
00152         // users are always authorized to use login page
00153         return true;
00154     }
00155 
00161     public function getViewId()
00162     {
00163         return strtolower(get_class($this));
00164     }
00165 
00166 
00172     protected function _getAvailableLanguages()
00173     {
00174         $sDefLang = oxRegistry::get("oxUtilsServer")->getOxCookie('oxidadminlanguage');
00175         $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
00176 
00177         $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00178         foreach ($aLanguages as $oLang) {
00179             $oLang->selected = ($sDefLang == $oLang->abbr) ? 1 : 0;
00180         }
00181 
00182         return $aLanguages;
00183     }
00184 
00190     protected function _getBrowserLanguage()
00191     {
00192         return strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
00193     }
00194 }