OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
login.php
Go to the documentation of this file.
1 <?php
2 
7 class Login extends oxAdminView
8 {
12  public function __construct()
13  {
14  $this->getConfig()->setConfigParam( 'blAdmin', true );
15  $this->_sThisAction = "login";
16  }
17 
24  public function render()
25  {
26  $oConfig = $this->getConfig();
27 
28  //resets user once on this screen.
29  $oUser = oxNew( "oxuser" );
30  $oUser->logout();
31 
33 
34  //if( $oConfig->blDemoMode)
35  $oBaseShop = oxNew( "oxshop" );
36 
37  $oBaseShop->load( $oConfig->getBaseShopId());
38  $sVersion = $oBaseShop->oxshops__oxversion->value;
39 
40  $this->getViewConfig()->setViewConfigParam( 'sShopVersion', $sVersion );
41 
42  if ( $oConfig->isDemoShop() ) {
43  // demo
44  $this->addTplParam( "user", "admin");
45  $this->addTplParam( "pwd", "admin");
46  }
47  //#533 user profile
48  $this->addTplParam( "profiles", oxRegistry::getUtils()->loadAdminProfile( $oConfig->getConfigParam( 'aInterfaceProfiles' ) ) );
49 
51  $this->addTplParam( "aLanguages", $aLanguages );
52 
53  // setting templates language to selected language id
54  foreach ($aLanguages as $iKey => $oLang) {
55  if ( $aLanguages[$iKey]->selected ) {
56  oxRegistry::getLang()->setTplLanguage( $iKey );
57  break;
58  }
59  }
60 
61  return "login.tpl";
62  }
63 
69  public function checklogin()
70  {
71  $myUtilsServer = oxRegistry::get("oxUtilsServer");
72  $myUtilsView = oxRegistry::get("oxUtilsView");
73 
74  $sUser = oxConfig::getParameter( 'user', true );
75  $sPass = oxConfig::getParameter( 'pwd', true );
76  $sProfile = oxConfig::getParameter( 'profile' );
77 
78  try { // trying to login
79  $oUser = oxNew( "oxuser" );
80  $oUser->login( $sUser, $sPass );
81  $iSubshop = (int)$oUser->oxuser__oxrights->value;
82  if ($iSubshop) {
83  oxSession::setVar( "shp", $iSubshop );
84  oxSession::setVar( 'currentadminshop', $iSubshop );
85  oxRegistry::getConfig()->setShopId($iSubshop);
86  }
87  } catch ( oxUserException $oEx ) {
88  $myUtilsView->addErrorToDisplay('LOGIN_ERROR');
89  $oStr = getStr();
90  $this->addTplParam( 'user', $oStr->htmlspecialchars( $sUser ) );
91  $this->addTplParam( 'pwd', $oStr->htmlspecialchars( $sPass ) );
92  $this->addTplParam( 'profile', $oStr->htmlspecialchars( $sProfile ) );
93  return;
94  } catch ( oxCookieException $oEx ) {
95  $myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
96  $oStr = getStr();
97  $this->addTplParam( 'user', $oStr->htmlspecialchars( $sUser ) );
98  $this->addTplParam( 'pwd', $oStr->htmlspecialchars( $sPass ) );
99  $this->addTplParam( 'profile', $oStr->htmlspecialchars( $sProfile ) );
100  return;
101  } catch ( oxConnectionException $oEx ) {
102  $myUtilsView->addErrorToDisplay($oEx);
103  }
104 
105  // success
106  oxRegistry::getUtils()->logger( "login successful" );
107 
108  //execute onAdminLogin() event
109  $oEvenHandler = oxNew("oxSystemEventHandler");
110  $oEvenHandler->onAdminLogin( oxRegistry::getConfig()->getShopId() );
111 
112  // #533
113  if ( isset( $sProfile ) ) {
114  $aProfiles = oxSession::getVar( "aAdminProfiles" );
115  if ( $aProfiles && isset($aProfiles[$sProfile])) {
116  // setting cookie to store last locally used profile
117  $myUtilsServer->setOxCookie ("oxidadminprofile", $sProfile."@".implode( "@", $aProfiles[$sProfile]), time()+31536000, "/" );
118  oxSession::setVar( "profile", $aProfiles[$sProfile] );
119  }
120  } else {
121  //deleting cookie info, as setting profile to default
122  $myUtilsServer->setOxCookie( "oxidadminprofile", "", time()-3600, "/" );
123  }
124 
125  // languages
126  $iLang = oxConfig::getParameter( "chlanguage" );
127  $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
128  if ( !isset( $aLanguages[$iLang] ) ) {
129  $iLang = key( $aLanguages );
130  }
131 
132  $myUtilsServer->setOxCookie( "oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/" );
133 
134  //P
135  //oxSession::setVar( "blAdminTemplateLanguage", $iLang );
136  oxRegistry::getLang()->setTplLanguage( $iLang );
137 
138  return "admin_start";
139  }
140 
146  protected function _authorize()
147  {
148  // users are always authorized to use login page
149  return true;
150  }
151 
157  public function getViewId()
158  {
159  return strtolower( get_class( $this ) );
160  }
161 
162 
168  protected function _getAvailableLanguages()
169  {
170  $sDefLang = oxRegistry::get("oxUtilsServer")->getOxCookie( 'oxidadminlanguage' );
171  $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
172 
173  $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
174  foreach ( $aLanguages as $oLang ) {
175  $oLang->selected = ( $sDefLang == $oLang->abbr ) ? 1 : 0;
176  }
177 
178  return $aLanguages;
179  }
180 
186  protected function _getBrowserLanguage()
187  {
188  return strtolower( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
189  }
190 }