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             $this->addTplParam( 'user', $sUser );
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', $sUser );
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         $aLanguages = oxLang::getInstance()->getAdminTplLanguageArray();
00114         if ( !isset( $aLanguages[$iLang] ) ) {
00115             $iLang = key( $aLanguages );
00116         }
00117 
00118         $myUtilsServer->setOxCookie( "oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/" );
00119 
00120         //P
00121         //oxSession::setVar( "blAdminTemplateLanguage", $iLang );
00122         oxLang::getInstance()->setTplLanguage( $iLang );
00123 
00124         return "admin_start";
00125     }
00126 
00132     protected function _authorize()
00133     {
00134         // users are always authorized to use login page
00135         return true;
00136     }
00137 
00143     public function getViewId()
00144     {
00145         return strtolower( get_class( $this ) );
00146     }
00147 
00153     protected function _getAvailableLanguages()
00154     {
00155         $sDefLang = oxUtilsServer::getInstance()->getOxCookie( 'oxidadminlanguage' );
00156         $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
00157 
00158         $aLanguages = oxLang::getInstance()->getAdminTplLanguageArray();
00159         foreach ( $aLanguages as $oLang ) {
00160             $oLang->selected = ( $sDefLang == $oLang->abbr ) ? 1 : 0;
00161         }
00162 
00163         return $aLanguages;
00164     }
00165 
00171     protected function _getBrowserLanguage()
00172     {
00173         return strtolower( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
00174     }
00175 }

Generated by  doxygen 1.6.2