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]->selected ) {
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         $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         } catch ( oxUserException $oEx ) {
00081             $myUtilsView->addErrorToDisplay('LOGIN_ERROR');
00082             $oStr = getStr();
00083             $this->addTplParam( 'user', $oStr->htmlspecialchars( $sUser ) );
00084             $this->addTplParam( 'pwd', $oStr->htmlspecialchars( $sPass ) );
00085             $this->addTplParam( 'profile', $oStr->htmlspecialchars( $sProfile ) );
00086             return;
00087         } catch ( oxCookieException $oEx ) {
00088             $myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
00089             $oStr = getStr();
00090             $this->addTplParam( 'user', $oStr->htmlspecialchars( $sUser ) );
00091             $this->addTplParam( 'pwd', $oStr->htmlspecialchars( $sPass ) );
00092             $this->addTplParam( 'profile', $oStr->htmlspecialchars( $sProfile ) );
00093             return;
00094         } catch ( oxConnectionException $oEx ) {
00095             $myUtilsView->addErrorToDisplay($oEx);
00096         }
00097 
00098         // success
00099         oxUtils::getInstance()->logger( "login successful" );
00100         // #533
00101         if ( isset( $sProfile ) ) {
00102             $aProfiles = oxSession::getVar( "aAdminProfiles" );
00103             if ( $aProfiles && isset($aProfiles[$sProfile])) {
00104                 // setting cookie to store last locally used profile
00105                 $myUtilsServer->setOxCookie ("oxidadminprofile", $sProfile."@".implode( "@", $aProfiles[$sProfile]), time()+31536000, "/" );
00106                 oxSession::setVar( "profile", $aProfiles[$sProfile] );
00107             }
00108         } else {
00109             //deleting cookie info, as setting profile to default
00110             $myUtilsServer->setOxCookie( "oxidadminprofile", "", time()-3600, "/" );
00111         }
00112 
00113         // languages
00114         $iLang = oxConfig::getParameter( "chlanguage" );
00115         $aLanguages = oxLang::getInstance()->getAdminTplLanguageArray();
00116         if ( !isset( $aLanguages[$iLang] ) ) {
00117             $iLang = key( $aLanguages );
00118         }
00119 
00120         $myUtilsServer->setOxCookie( "oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/" );
00121 
00122         //P
00123         //oxSession::setVar( "blAdminTemplateLanguage", $iLang );
00124         oxLang::getInstance()->setTplLanguage( $iLang );
00125 
00126         return "admin_start";
00127     }
00128 
00134     protected function _authorize()
00135     {
00136         // users are always authorized to use login page
00137         return true;
00138     }
00139 
00145     public function getViewId()
00146     {
00147         return strtolower( get_class( $this ) );
00148     }
00149 
00155     protected function _getAvailableLanguages()
00156     {
00157         $sDefLang = oxUtilsServer::getInstance()->getOxCookie( 'oxidadminlanguage' );
00158         $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
00159 
00160         $aLanguages = oxLang::getInstance()->getAdminTplLanguageArray();
00161         foreach ( $aLanguages as $oLang ) {
00162             $oLang->selected = ( $sDefLang == $oLang->abbr ) ? 1 : 0;
00163         }
00164 
00165         return $aLanguages;
00166     }
00167 
00173     protected function _getBrowserLanguage()
00174     {
00175         return strtolower( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
00176     }
00177 }