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 {
00026 $oConfig = $this->getConfig();
00027
00028
00029 $oUser = oxNew( "oxuser" );
00030 $oUser->logout();
00031
00032 oxView::render();
00033
00034
00035 $oBaseShop = oxNew( "oxshop" );
00036
00037 $oBaseShop->load( $oConfig->getBaseShopId());
00038 $sVersion = $oBaseShop->oxshops__oxversion->value;
00039
00040 $this->getViewConfig()->setViewConfigParam( 'sShopVersion', $sVersion );
00041
00042 if ( $oConfig->isDemoShop() ) {
00043
00044 $this->addTplParam( "user", "admin");
00045 $this->addTplParam( "pwd", "admin");
00046 }
00047
00048 $this->addTplParam( "profiles", oxRegistry::getUtils()->loadAdminProfile( $oConfig->getConfigParam( 'aInterfaceProfiles' ) ) );
00049
00050 $aLanguages = $this->_getAvailableLanguages();
00051 $this->addTplParam( "aLanguages", $aLanguages );
00052
00053
00054 foreach ($aLanguages as $iKey => $oLang) {
00055 if ( $aLanguages[$iKey]->selected ) {
00056 oxRegistry::getLang()->setTplLanguage( $iKey );
00057 break;
00058 }
00059 }
00060
00061 return "login.tpl";
00062 }
00063
00069 public function checklogin()
00070 {
00071 $myUtilsServer = oxRegistry::get("oxUtilsServer");
00072 $myUtilsView = oxRegistry::get("oxUtilsView");
00073
00074 $sUser = oxConfig::getParameter( 'user', true );
00075 $sPass = oxConfig::getParameter( 'pwd', true );
00076 $sProfile = oxConfig::getParameter( 'profile' );
00077
00078 try {
00079 $oUser = oxNew( "oxuser" );
00080 $oUser->login( $sUser, $sPass );
00081 $iSubshop = (int)$oUser->oxuser__oxrights->value;
00082 if ($iSubshop) {
00083 oxSession::setVar( "shp", $iSubshop );
00084 oxSession::setVar( 'currentadminshop', $iSubshop );
00085 oxRegistry::getConfig()->setShopId($iSubshop);
00086 }
00087 } catch ( oxUserException $oEx ) {
00088 $myUtilsView->addErrorToDisplay('LOGIN_ERROR');
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 ( oxCookieException $oEx ) {
00095 $myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
00096 $oStr = getStr();
00097 $this->addTplParam( 'user', $oStr->htmlspecialchars( $sUser ) );
00098 $this->addTplParam( 'pwd', $oStr->htmlspecialchars( $sPass ) );
00099 $this->addTplParam( 'profile', $oStr->htmlspecialchars( $sProfile ) );
00100 return;
00101 } catch ( oxConnectionException $oEx ) {
00102 $myUtilsView->addErrorToDisplay($oEx);
00103 }
00104
00105
00106 oxRegistry::getUtils()->logger( "login successful" );
00107
00108
00109 $oEvenHandler = oxNew("oxSystemEventHandler");
00110 $oEvenHandler->onAdminLogin( oxRegistry::getConfig()->getShopId() );
00111
00112
00113 if ( isset( $sProfile ) ) {
00114 $aProfiles = oxSession::getVar( "aAdminProfiles" );
00115 if ( $aProfiles && isset($aProfiles[$sProfile])) {
00116
00117 $myUtilsServer->setOxCookie ("oxidadminprofile", $sProfile."@".implode( "@", $aProfiles[$sProfile]), time()+31536000, "/" );
00118 oxSession::setVar( "profile", $aProfiles[$sProfile] );
00119 }
00120 } else {
00121
00122 $myUtilsServer->setOxCookie( "oxidadminprofile", "", time()-3600, "/" );
00123 }
00124
00125
00126 $iLang = oxConfig::getParameter( "chlanguage" );
00127 $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00128 if ( !isset( $aLanguages[$iLang] ) ) {
00129 $iLang = key( $aLanguages );
00130 }
00131
00132 $myUtilsServer->setOxCookie( "oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/" );
00133
00134
00135
00136 oxRegistry::getLang()->setTplLanguage( $iLang );
00137
00138 return "admin_start";
00139 }
00140
00146 protected function _authorize()
00147 {
00148
00149 return true;
00150 }
00151
00157 public function getViewId()
00158 {
00159 return strtolower( get_class( $this ) );
00160 }
00161
00162
00168 protected function _getAvailableLanguages()
00169 {
00170 $sDefLang = oxRegistry::get("oxUtilsServer")->getOxCookie( 'oxidadminlanguage' );
00171 $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
00172
00173 $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00174 foreach ( $aLanguages as $oLang ) {
00175 $oLang->selected = ( $sDefLang == $oLang->abbr ) ? 1 : 0;
00176 }
00177
00178 return $aLanguages;
00179 }
00180
00186 protected function _getBrowserLanguage()
00187 {
00188 return strtolower( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
00189 }
00190 }