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", oxUtils::getInstance()->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]->blSelected ) {
00055                 oxLang::getInstance()->setTplLanguage( $iKey );
00056                 break;
00057             }
00058         }
00059 
00060         return "login.tpl";
00061     }
00062 
00068     public function checklogin()
00069     {
00070         $myUtilsServer = oxUtilsServer::getInstance();
00071         $myUtilsView   = oxUtilsView::getInstance();
00072 
00073         $sLoginName = 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( $sLoginName, $sPass );
00080         } catch ( oxUserException $oEx ) {
00081             $myUtilsView->addErrorToDisplay( 'LOGIN_ERROR' );
00082             $this->addTplParam( 'user', $sLoginName );
00083             $this->addTplParam( 'pwd', $sPass );
00084             $this->addTplParam( 'profile', $sProfile );
00085             return;
00086         } catch ( oxCookieException $oEx ) {
00087             $myUtilsView->addErrorToDisplay( 'LOGIN_NO_COOKIE_SUPPORT' );
00088             $this->addTplParam( 'user', $sLoginName );
00089             $this->addTplParam( 'pwd', $sPass );
00090             $this->addTplParam( 'profile', $sProfile );
00091             return;
00092         } catch ( oxConnectionException $oEx ) {
00093             $myUtilsView->addErrorToDisplay( $oEx );
00094         }
00095 
00096         // success
00097         oxUtils::getInstance()->logger( "login successful" );
00098         // #533
00099         if ( isset( $sProfile ) ) {
00100             $aProfiles = oxSession::getVar( "aAdminProfiles" );
00101             if ( $aProfiles && isset( $aProfiles[$sProfile] ) ) {
00102                 // setting cookie to store last locally used profile
00103                 $myUtilsServer->setOxCookie( "oxidadminprofile", $sProfile."@".implode( "@", $aProfiles[$sProfile]), time()+31536000, "/" );
00104                 oxSession::setVar( "profile", $aProfiles[$sProfile] );
00105             }
00106         } else {
00107             //deleting cookie info, as setting profile to default
00108             $myUtilsServer->setOxCookie( "oxidadminprofile", "", time()-3600, "/" );
00109         }
00110 
00111         // languages
00112         $iLang = oxConfig::getParameter( "chlanguage" );
00113         $myUtilsServer->setOxCookie( "oxidadminlanguage", $iLang, time()+31536000, "/" );
00114 
00115         //P
00116         //oxSession::setVar( "blAdminTemplateLanguage", $iLang );
00117         oxLang::getInstance()->setTplLanguage( $iLang );
00118 
00119         return "admin_start";
00120     }
00121 
00127     protected function _authorize()
00128     {
00129         // users are always authorized to use login page
00130         return true;
00131     }
00132 
00138     public function getViewId()
00139     {
00140         return strtolower( get_class( $this ) );
00141     }
00142 
00148     protected function _getAvailableLanguages()
00149     {
00150         $myConfig = $this->getConfig();
00151 
00152         // #656 add admin languages
00153         $aLanguages = array();
00154         $sSourceDir = $myConfig->getConfigParam('sShopDir') . $myConfig->getTemplateBase( true );
00155         $iDefLangId = oxUtilsServer::getInstance()->getOxCookie('oxidadminlanguage');
00156         $sBrowserLang = $this->_getBrowserLanguage();
00157 
00158         // setting template language ..
00159         $aLangParams = $myConfig->getConfigParam('aLanguageParams');
00160 
00161         $handle = opendir( $sSourceDir );
00162         while ( false !== ( $file = readdir( $handle ) ) ) {
00163             $sLangName = "";
00164             $iLangNr = 0;
00165 
00166             if ( is_dir("$sSourceDir/$file") && file_exists("$sSourceDir/$file/lang.php") ) {
00167                     include "$sSourceDir/$file/lang.php";
00168                     $oLang = new stdClass();
00169                     $oLang->sValue = $sLangName;
00170                     $oLang->sFile = $file;
00171 
00172                     if ( isset($aLangParams[$file]['baseId']) ) {
00173                         $iLangNr = $aLangParams[$file]['baseId'];
00174                     }
00175 
00176                     $aLanguages[$iLangNr] = $oLang;
00177             }
00178         }
00179 
00180         ksort($aLanguages);
00181 
00182         foreach ($aLanguages as $iKey => $oLang) {
00183             $aLanguages[$iKey]->blSelected = false;
00184             if ( is_null($iDefLangId) || $iDefLangId == "" ) {
00185                 $aLanguages[$iKey]->blSelected  = ( strtolower($aLanguages[$iKey]->sFile) == $sBrowserLang );
00186             } else {
00187                 $aLanguages[$iKey]->blSelected  = ( $iKey == $iDefLangId );
00188             }
00189         }
00190 
00191         return $aLanguages;
00192     }
00193 
00199     protected function _getBrowserLanguage()
00200     {
00201         return strtolower( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
00202     }
00203 }

Generated by  doxygen 1.6.2