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
00028 $oUser = oxNew( "oxuser" );
00029 $oUser->logout();
00030
00031 oxView::render();
00032
00033
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
00043 $this->addTplParam( "user", "admin");
00044 $this->addTplParam( "pwd", "admin");
00045 }
00046
00047 $this->addTplParam( "profiles", oxRegistry::getUtils()->loadAdminProfile( $myConfig->getConfigParam( 'aInterfaceProfiles' ) ) );
00048
00049 $aLanguages = $this->_getAvailableLanguages();
00050 $this->addTplParam( "aLanguages", $aLanguages );
00051
00052
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 {
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
00105 oxRegistry::getUtils()->logger( "login successful" );
00106
00107
00108 $oEvenHandler = oxNew("oxSystemEventHandler");
00109 $oEvenHandler->onAdminLogin( oxRegistry::getConfig()->getShopId() );
00110
00111
00112 if ( isset( $sProfile ) ) {
00113 $aProfiles = oxSession::getVar( "aAdminProfiles" );
00114 if ( $aProfiles && isset($aProfiles[$sProfile])) {
00115
00116 $myUtilsServer->setOxCookie ("oxidadminprofile", $sProfile."@".implode( "@", $aProfiles[$sProfile]), time()+31536000, "/" );
00117 oxSession::setVar( "profile", $aProfiles[$sProfile] );
00118 }
00119 } else {
00120
00121 $myUtilsServer->setOxCookie( "oxidadminprofile", "", time()-3600, "/" );
00122 }
00123
00124
00125 $iLang = oxConfig::getParameter( "chlanguage" );
00126 $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00127 if ( !isset( $aLanguages[$iLang] ) ) {
00128 $iLang = key( $aLanguages );
00129 }
00130
00131 $myUtilsServer->setOxCookie( "oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/" );
00132
00133
00134
00135 oxRegistry::getLang()->setTplLanguage( $iLang );
00136
00137 return "admin_start";
00138 }
00139
00145 protected function _authorize()
00146 {
00147
00148 return true;
00149 }
00150
00156 public function getViewId()
00157 {
00158 return strtolower( get_class( $this ) );
00159 }
00160
00166 protected function _getAvailableLanguages()
00167 {
00168 $sDefLang = oxRegistry::get("oxUtilsServer")->getOxCookie( 'oxidadminlanguage' );
00169 $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
00170
00171 $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
00172 foreach ( $aLanguages as $oLang ) {
00173 $oLang->selected = ( $sDefLang == $oLang->abbr ) ? 1 : 0;
00174 }
00175
00176 return $aLanguages;
00177 }
00178
00184 protected function _getBrowserLanguage()
00185 {
00186 return strtolower( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
00187 }
00188 }