OXID eShop CE  4.9.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 {
9 
13  public function __construct()
14  {
15  $this->getConfig()->setConfigParam('blAdmin', true);
16  $this->_sThisAction = "login";
17  }
18 
25  public function render()
26  {
27  $myConfig = $this->getConfig();
28 
29  // automatically redirect to SSL login
30  if (!$myConfig->isSsl() && strpos($myConfig->getConfigParam('sAdminSSLURL'), 'https://') === 0) {
31  oxRegistry::getUtils()->redirect($myConfig->getConfigParam('sAdminSSLURL'), false, 302);
32  }
33 
34  //resets user once on this screen.
35  $oUser = oxNew("oxuser");
36  $oUser->logout();
37 
39 
40  //if( $myConfig->blDemoMode)
41  $oBaseShop = oxNew("oxshop");
42 
43  $oBaseShop->load($myConfig->getBaseShopId());
44  $sVersion = $oBaseShop->oxshops__oxversion->value;
45 
46  $this->getViewConfig()->setViewConfigParam('sShopVersion', $sVersion);
47 
48  if ($myConfig->isDemoShop()) {
49  // demo
50  $this->addTplParam("user", "admin");
51  $this->addTplParam("pwd", "admin");
52  }
53  //#533 user profile
54  $this->addTplParam("profiles", oxRegistry::getUtils()->loadAdminProfile($myConfig->getConfigParam('aInterfaceProfiles')));
55 
57  $this->addTplParam("aLanguages", $aLanguages);
58 
59  // setting templates language to selected language id
60  foreach ($aLanguages as $iKey => $oLang) {
61  if ($aLanguages[$iKey]->selected) {
62  oxRegistry::getLang()->setTplLanguage($iKey);
63  break;
64  }
65  }
66 
67  return "login.tpl";
68  }
69 
75  public function checklogin()
76  {
77  $myUtilsServer = oxRegistry::get("oxUtilsServer");
78  $myUtilsView = oxRegistry::get("oxUtilsView");
79 
80  $sUser = oxRegistry::getConfig()->getRequestParameter('user', true);
81  $sPass = oxRegistry::getConfig()->getRequestParameter('pwd', true);
82  $sProfile = oxRegistry::getConfig()->getRequestParameter('profile');
83 
84  try { // trying to login
86  $oUser = oxNew("oxuser");
87  $oUser->login($sUser, $sPass);
88  $iSubshop = (int) $oUser->oxuser__oxrights->value;
89  if ($iSubshop) {
90  oxRegistry::getSession()->setVariable("shp", $iSubshop);
91  oxRegistry::getSession()->setVariable('currentadminshop', $iSubshop);
92  oxRegistry::getConfig()->setShopId($iSubshop);
93  }
94  } catch (oxUserException $oEx) {
95  $myUtilsView->addErrorToDisplay('LOGIN_ERROR');
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 
101  return;
102  } catch (oxCookieException $oEx) {
103  $myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
104  $oStr = getStr();
105  $this->addTplParam('user', $oStr->htmlspecialchars($sUser));
106  $this->addTplParam('pwd', $oStr->htmlspecialchars($sPass));
107  $this->addTplParam('profile', $oStr->htmlspecialchars($sProfile));
108 
109  return;
110  } catch (oxConnectionException $oEx) {
111  $myUtilsView->addErrorToDisplay($oEx);
112  }
113 
114  // success
115  oxRegistry::getUtils()->logger("login successful");
116 
117  //execute onAdminLogin() event
118  $oEvenHandler = oxNew("oxSystemEventHandler");
119  $oEvenHandler->onAdminLogin(oxRegistry::getConfig()->getShopId());
120 
121  // #533
122  if (isset($sProfile)) {
123  $aProfiles = oxRegistry::getSession()->getVariable("aAdminProfiles");
124  if ($aProfiles && isset($aProfiles[$sProfile])) {
125  // setting cookie to store last locally used profile
126  $myUtilsServer->setOxCookie("oxidadminprofile", $sProfile . "@" . implode("@", $aProfiles[$sProfile]), time() + 31536000, "/");
127  oxRegistry::getSession()->setVariable("profile", $aProfiles[$sProfile]);
128  }
129  } else {
130  //deleting cookie info, as setting profile to default
131  $myUtilsServer->setOxCookie("oxidadminprofile", "", time() - 3600, "/");
132  }
133 
134  // languages
135  $iLang = oxRegistry::getConfig()->getRequestParameter("chlanguage");
136  $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
137  if (!isset($aLanguages[$iLang])) {
138  $iLang = key($aLanguages);
139  }
140 
141  $myUtilsServer->setOxCookie("oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/");
142 
143  //P
144  //oxRegistry::getSession()->setVariable( "blAdminTemplateLanguage", $iLang );
145  oxRegistry::getLang()->setTplLanguage($iLang);
146 
147  return "admin_start";
148  }
149 
155  protected function _authorize()
156  {
157  // users are always authorized to use login page
158  return true;
159  }
160 
166  public function getViewId()
167  {
168  return strtolower(get_class($this));
169  }
170 
171 
177  protected function _getAvailableLanguages()
178  {
179  $sDefLang = oxRegistry::get("oxUtilsServer")->getOxCookie('oxidadminlanguage');
180  $sDefLang = $sDefLang ? $sDefLang : $this->_getBrowserLanguage();
181 
182  $aLanguages = oxRegistry::getLang()->getAdminTplLanguageArray();
183  foreach ($aLanguages as $oLang) {
184  $oLang->selected = ($sDefLang == $oLang->abbr) ? 1 : 0;
185  }
186 
187  return $aLanguages;
188  }
189 
195  protected function _getBrowserLanguage()
196  {
197  return strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
198  }
199 }