login.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Login extends oxAdminView
00008 {
00012     public function __construct()
00013     {
00014         $this->getConfig()->setConfigParam( 'blAdmin', true );
00015         $this->_sThisAction  = "login";
00016     }
00017 
00024     public function render()
00025     {   $myConfig = $this->getConfig();
00026 
00027         //resets user once on this screen.
00028         $oUser = oxNew( "oxuser" );
00029         $oUser->logout();
00030 
00031         oxView::render();
00032 
00033         //if( $myConfig->blDemoMode)
00034         $oBaseShop = oxNew( "oxshop" );
00035 
00036         $oBaseShop->load( $myConfig->getBaseShopId());
00037             $sVersion = $oBaseShop->oxshops__oxversion->value;
00038 
00039         $this->getViewConfig()->setViewConfigParam( 'sShopVersion', $sVersion );
00040 
00041         if ( $myConfig->isDemoShop() ) {
00042             // demo
00043             $this->addTplParam( "user", "admin");
00044             $this->addTplParam( "pwd", "admin");
00045         }
00046         //#533 user profile
00047         $this->addTplParam( "profiles", oxRegistry::getUtils()->loadAdminProfile( $myConfig->getConfigParam( 'aInterfaceProfiles' ) ) );
00048 
00049         $aLanguages = $this->_getAvailableLanguages();
00050         $this->addTplParam( "aLanguages", $aLanguages );
00051 
00052         // setting templates language to selected language id
00053         foreach ($aLanguages as $iKey => $oLang) {
00054             if ( $aLanguages[$iKey]->selected ) {
00055                 oxRegistry::getLang()->setTplLanguage( $iKey );
00056                 break;
00057             }
00058         }
00059 
00060         return "login.tpl";
00061     }
00062 
00068     public function checklogin()
00069     {
00070         $myUtilsServer = oxRegistry::get("oxUtilsServer");
00071         $myUtilsView   = oxRegistry::get("oxUtilsView");
00072 
00073         $sUser    = oxConfig::getParameter( 'user', true );
00074         $sPass    = oxConfig::getParameter( 'pwd', true );
00075         $sProfile = oxConfig::getParameter( 'profile' );
00076 
00077         try { // trying to login
00078             $oUser = oxNew( "oxuser" );
00079             $oUser->login( $sUser, $sPass );
00080             $iSubshop = (int)$oUser->oxuser__oxrights->value;
00081             if ($iSubshop) {
00082                 oxSession::setVar( "shp", $iSubshop );
00083                 oxSession::setVar( 'currentadminshop', $iSubshop );
00084                 oxRegistry::getConfig()->setShopId($iSubshop);
00085             }
00086         } catch ( oxUserException $oEx ) {
00087             $myUtilsView->addErrorToDisplay('LOGIN_ERROR');
00088             $oStr = getStr();
00089             $this->addTplParam( 'user', $oStr->htmlspecialchars( $sUser ) );
00090             $this->addTplParam( 'pwd', $oStr->htmlspecialchars( $sPass ) );
00091             $this->addTplParam( 'profile', $oStr->htmlspecialchars( $sProfile ) );
00092             return;
00093         } catch ( oxCookieException $oEx ) {
00094             $myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
00095             $oStr = getStr();
00096             $this->addTplParam( 'user', $oStr->htmlspecialchars( $sUser ) );
00097             $this->addTplParam( 'pwd', $oStr->htmlspecialchars( $sPass ) );
00098             $this->addTplParam( 'profile', $oStr->htmlspecialchars( $sProfile ) );
00099             return;
00100         } catch ( oxConnectionException $oEx ) {
00101             $myUtilsView->addErrorToDisplay($oEx);
00102         }
00103 
00104         // success
00105         oxRegistry::getUtils()->logger( "login successful" );
00106         // #533
00107         if ( isset( $sProfile ) ) {
00108             $aProfiles = oxSession::getVar( "aAdminProfiles" );
00109             if ( $aProfiles && isset($aProfiles[$sProfile])) {
00110                 // setting cookie to store last locally used profile
00111                 $myUtilsServer->setOxCookie ("oxidadminprofile", $sProfile."@".implode( "@", $aProfiles[$sProfile]), time()+31536000, "/" );
00112                 oxSession::setVar( "profile", $aProfiles[$sProfile] );
00113             }
00114         } else {
00115             //deleting cookie info, as setting profile to default
00116             $myUtilsServer->setOxCookie( "oxidadminprofile", "", time()-3600, "/" );
00117         }
00118 
00119         // languages
00120         $iLang = oxConfig::getParameter( "chlanguage" );
00121         $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00122         if ( !isset( $aLanguages[$iLang] ) ) {
00123             $iLang = key( $aLanguages );
00124         }
00125 
00126         $myUtilsServer->setOxCookie( "oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/" );
00127 
00128         //P
00129         //oxSession::setVar( "blAdminTemplateLanguage", $iLang );
00130         oxRegistry::getLang()->setTplLanguage( $iLang );
00131 
00132         return "admin_start";
00133     }
00134 
00140     protected function _authorize()
00141     {
00142         // users are always authorized to use login page
00143         return true;
00144     }
00145 
00151     public function getViewId()
00152     {
00153         return strtolower( get_class( $this ) );
00154     }
00155 
00161     protected function _getAvailableLanguages()
00162     {
00163         $sDefLang = oxRegistry::get("oxUtilsServer")->getOxCookie( 'oxidadminlanguage' );
00164         $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
00165 
00166         $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00167         foreach ( $aLanguages as $oLang ) {
00168             $oLang->selected = ( $sDefLang == $oLang->abbr ) ? 1 : 0;
00169         }
00170 
00171         return $aLanguages;
00172     }
00173 
00179     protected function _getBrowserLanguage()
00180     {
00181         return strtolower( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
00182     }
00183 }