00001 <?php
00002
00003
00004 define( 'USER_LOGIN_SUCCESS', 1 );
00005 define( 'USER_LOGIN_FAIL', 2 );
00006 define( 'USER_LOGOUT', 3 );
00007
00013 class oxcmp_user extends oxView
00014 {
00019 protected $_blIsNewUser = false;
00020
00025 protected $_blIsComponent = true;
00026
00031 protected $_blNewsSubscriptionStatus = null;
00032
00040 protected $_iLoginStatus = null;
00041
00047 protected $_sTermsVer = null;
00048
00054 protected $_aAllowedClasses = array(
00055 'register',
00056 'forgotpwd',
00057 'content',
00058 'account',
00059 'clearcookies',
00060 'oxwServiceMenu',
00061 );
00071 public function init()
00072 {
00073
00074 $blShow = oxConfig::getParameter( 'blshowshipaddress' );
00075 if (!isset($blShow)) {
00076 $blShow = oxSession::getVar( 'blshowshipaddress' );
00077 }
00078
00079 oxSession::setVar( 'blshowshipaddress', $blShow );
00080
00081
00082 $this->_loadSessionUser();
00083 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) ) {
00084
00085 $this->getInvitor();
00086 $this->setRecipient();
00087 }
00088
00089 parent::init();
00090 }
00091
00101 public function render()
00102 {
00103
00104 $this->_checkPsState();
00105
00106 parent::render();
00107
00108
00109
00110 if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00111 oxSession::setVar( 'dgr', $sDynGoup );
00112 }
00113
00114 return $this->getUser();
00115 }
00116
00127 protected function _checkPsState()
00128 {
00129 $oConfig = $this->getConfig();
00130 if ( $this->getParent()->isEnabledPrivateSales() ) {
00131
00132 $oUser = $this->getUser();
00133 $sClass = $this->getParent()->getClassName();
00134
00135
00136 if ( !$oUser && !in_array( $sClass, $this->_aAllowedClasses ) ) {
00137 oxRegistry::getUtils()->redirect( $oConfig->getShopHomeURL() . 'cl=account', false, 302 );
00138 }
00139
00140 if ( $oUser && !$oUser->isTermsAccepted() && !in_array( $sClass, $this->_aAllowedClasses ) ) {
00141 oxRegistry::getUtils()->redirect( $oConfig->getShopHomeURL() . 'cl=account&term=1', false, 302 );
00142 }
00143 }
00144 }
00145
00151 protected function _loadSessionUser()
00152 {
00153 $myConfig = $this->getConfig();
00154 $oUser = $this->getUser();
00155
00156
00157 if ( !$oUser ) {
00158 return;
00159 }
00160
00161
00162 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00163 oxRegistry::getUtils()->redirect( $myConfig->getShopHomeURL() . 'cl=content&tpl=user_blocked.tpl', true, 302 );
00164 }
00165
00166
00167 if ( $oUser->isLoadedFromCookie() && !$myConfig->getConfigParam( 'blPerfNoBasketSaving' )) {
00168
00169 if ( $oBasket = $this->getSession()->getBasket() ) {
00170 $oBasket->load();
00171 $oBasket->onUpdate();
00172 }
00173 }
00174 }
00175
00189 public function login()
00190 {
00191 $sUser = oxConfig::getParameter( 'lgn_usr' );
00192 $sPassword = oxConfig::getParameter( 'lgn_pwd', true );
00193 $sCookie = oxConfig::getParameter( 'lgn_cook' );
00194
00195
00196 $this->setLoginStatus( USER_LOGIN_FAIL );
00197
00198
00199 try {
00200 $oUser = oxNew( 'oxuser' );
00201 $oUser->login( $sUser, $sPassword, $sCookie );
00202 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00203 } catch ( oxUserException $oEx ) {
00204
00205 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true, '', false );
00206 return 'user';
00207 } catch( oxCookieException $oEx ){
00208 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
00209 return 'user';
00210 }
00211
00212 return $this->_afterLogin( $oUser );
00213 }
00214
00232 protected function _afterLogin( $oUser )
00233 {
00234 $oSession = $this->getSession();
00235
00236
00237 if ( $this->getLoginStatus() === USER_LOGIN_SUCCESS ) {
00238 $oSession->regenerateSessionId();
00239 }
00240
00241 $myConfig = $this->getConfig();
00242
00243
00244 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00245 oxRegistry::getUtils()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl', true, 302 );
00246 }
00247
00248
00249 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00250
00251
00252 if ( $oBasket = $oSession->getBasket() ) {
00253 $oBasket->onUpdate();
00254 }
00255
00256
00257 return 'payment';
00258 }
00259
00266 public function login_noredirect()
00267 {
00268 $blAgb = oxConfig::getParameter( 'ord_agb' );
00269 $oConfig = $this->getConfig();
00270 if ( $this->getParent()->isEnabledPrivateSales() && $blAgb !== null && ( $oUser = $this->getUser() ) ) {
00271 if ( $blAgb ) {
00272 $oUser->acceptTerms();
00273 }
00274 } else {
00275 $this->login();
00276
00277 if ( !$this->isAdmin() && !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' )) {
00278
00279 try {
00280 if ( $oBasket = $this->getSession()->getBasket() ) {
00281 $oBasket->load();
00282 }
00283 } catch ( Exception $oE ) {
00284
00285 }
00286 }
00287
00288
00289 }
00290 }
00291
00298 public function login_updateFbId()
00299 {
00300 $this->login();
00301
00302 if ( $oUser = $this->getUser() ) {
00303
00304 if ( $oUser->updateFbId() ) {
00305 oxSession::setVar( '_blFbUserIdUpdated', true );
00306 }
00307 }
00308 }
00309
00318 protected function _afterLogout()
00319 {
00320 oxSession::deleteVar( 'paymentid' );
00321 oxSession::deleteVar( 'sShipSet' );
00322 oxSession::deleteVar( 'deladrid' );
00323 oxSession::deleteVar( 'dynvalue' );
00324
00325
00326 if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00327 $oBasket->resetUserInfo();
00328 $oBasket->onUpdate();
00329 }
00330 }
00331
00340 public function logout()
00341 {
00342 $myConfig = $this->getConfig();
00343 $oUser = oxNew( 'oxuser' );
00344
00345 if ( $oUser->logout() ) {
00346
00347 $this->setLoginStatus( USER_LOGOUT );
00348
00349
00350 $this->_afterLogout();
00351
00352
00353 if ( $this->getParent()->isEnabledPrivateSales() ) {
00354 return 'account';
00355 }
00356
00357
00358 if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00359 oxRegistry::getUtils()->redirect( $this->_getLogoutLink());
00360 }
00361 }
00362 }
00363
00373 public function changeUser( )
00374 {
00375 $blUserRegistered = $this->_changeUser_noRedirect();
00376
00377 if ( $blUserRegistered === true ) {
00378 return 'payment';
00379 } else {
00380 return $blUserRegistered;
00381 }
00382 }
00383
00390 public function changeuser_testvalues()
00391 {
00392
00393
00394
00395
00396 if ( $this->_changeUser_noRedirect() ) {
00397 return 'account_user';
00398 }
00399 }
00400
00422 public function createUser()
00423 {
00424 $blActiveLogin = $this->getParent()->isEnabledPrivateSales();
00425
00426 $myConfig = $this->getConfig();
00427 if ( $blActiveLogin && !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00428 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'READ_AND_CONFIRM_TERMS', false, true );
00429 return;
00430 }
00431
00432 $myUtils = oxRegistry::getUtils();
00433
00434
00435 $sUser = oxConfig::getParameter( 'lgn_usr' );
00436
00437
00438 $sPassword = oxConfig::getParameter( 'lgn_pwd', true );
00439
00440
00441 $sPassword2 = oxConfig::getParameter( 'lgn_pwd2', true );
00442
00443 $aInvAdress = oxConfig::getParameter( 'invadr', true );
00444 $aDelAdress = $this->_getDelAddressData();
00445
00446 $oUser = oxNew( 'oxuser' );
00447
00448 try {
00449
00450 $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00451
00452 $iActState = $blActiveLogin ? 0 : 1;
00453
00454
00455 $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00456 $oUser->setPassword( $sPassword );
00457 $oUser->oxuser__oxactive = new oxField( $iActState, oxField::T_RAW);
00458
00459
00460 $iSubscriptionStatus = $oUser->getNewsSubscription()->getOptInStatus();
00461
00462 $oUser->createUser();
00463 $oUser->load($oUser->getId());
00464 $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00465
00466 if ( $blActiveLogin ) {
00467
00468 $oUser->acceptTerms();
00469 }
00470
00471 $sUserId = oxSession::getVar( "su" );
00472 $sRecEmail = oxSession::getVar( "re" );
00473 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) && $sUserId && $sRecEmail ) {
00474
00475 $oUser->setCreditPointsForRegistrant( $sUserId, $sRecEmail );
00476 }
00477
00478
00479 $blOptin = oxRegistry::getConfig()->getRequestParameter( 'blnewssubscribed' );
00480 if ( $blOptin && $iSubscriptionStatus == 1 ) {
00481
00482 $oUser->getNewsSubscription()->setOptInStatus(1);
00483 $oUser->addToGroup( 'oxidnewsletter' );
00484 $this->_blNewsSubscriptionStatus = 1;
00485 } else {
00486 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00487 }
00488
00489 $oUser->addToGroup( 'oxidnotyetordered' );
00490 $oUser->addDynGroup( oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ) );
00491 $oUser->logout();
00492
00493 } catch ( oxUserException $oEx ) {
00494 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true );
00495 return false;
00496 } catch( oxInputException $oEx ){
00497 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true );
00498 return false;
00499 } catch( oxConnectionException $oEx ){
00500 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true );
00501 return false;
00502 }
00503
00504 if ( !$blActiveLogin ) {
00505
00506 oxSession::setVar( 'usr', $oUser->getId() );
00507 $this->_afterLogin( $oUser );
00508
00509
00510
00511
00512 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00513 if ( $sOrderRemark ) {
00514 oxSession::setVar( 'ordrem', $sOrderRemark );
00515 }
00516 }
00517
00518
00519
00520 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00521 $oxEMail = oxNew( 'oxemail' );
00522 if ( $blActiveLogin ) {
00523 $oxEMail->sendRegisterConfirmEmail( $oUser );
00524 } else {
00525 $oxEMail->sendRegisterEmail( $oUser );
00526 }
00527 }
00528
00529
00530 $this->_blIsNewUser = true;
00531
00532 return 'payment';
00533 }
00534
00540 public function registerUser()
00541 {
00542
00543 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00544 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00545 return 'register?success=1';
00546 } else {
00547 return 'register?success=1&newslettererror=4';
00548 }
00549 } else {
00550
00551 $this->logout();
00552 }
00553 }
00554
00568 protected function _changeUser_noRedirect( )
00569 {
00570 if (!$this->getSession()->checkSessionChallenge()) {
00571 return;
00572 }
00573
00574
00575 $oUser = $this->getUser();
00576 if ( !$oUser ) {
00577 return;
00578 }
00579
00580
00581 $aDelAdress = $this->_getDelAddressData();
00582
00583
00584 $aInvAdress = oxConfig::getParameter( 'invadr', true );
00585
00586 $sUserName = $oUser->oxuser__oxusername->value;
00587 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00588
00589 try {
00590 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00591
00592 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00593 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00594 }
00595
00596 $blForceCheckOptIn = ( $aInvAdress['oxuser__oxusername'] !== null && $aInvAdress['oxuser__oxusername'] !== $sUserName );
00597 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ), $blForceCheckOptIn );
00598
00599 } catch ( oxUserException $oEx ) {
00600
00601
00602 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
00603 return;
00604 } catch(oxInputException $oEx) {
00605 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
00606 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'input_not_all_fields');
00607 return;
00608 } catch(oxConnectionException $oEx){
00609
00610 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
00611 return;
00612 }
00613
00614
00615
00616 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00617
00618 if ( $sOrderRemark ) {
00619 oxSession::setVar( 'ordrem', $sOrderRemark );
00620 } else {
00621 oxSession::deleteVar( 'ordrem' );
00622 }
00623
00624 if ( $oBasket = $this->getSession()->getBasket() ) {
00625 $oBasket->onUpdate();
00626 }
00627 return true;
00628 }
00629
00636 protected function _getDelAddressData()
00637 {
00638
00639 $aDelAdress = $aDeladr = (oxConfig::getParameter( 'blshowshipaddress' ) || oxSession::getVar( 'blshowshipaddress' )) ? oxConfig::getParameter( 'deladr', true ) : array();
00640
00641 if ( is_array( $aDeladr ) ) {
00642
00643 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00644 unset( $aDeladr['oxaddress__oxsal'] );
00645 }
00646 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00647
00648 $aDelAdress = array();
00649 }
00650 }
00651 return $aDelAdress;
00652 }
00653
00659 protected function _getLogoutLink()
00660 {
00661 $oConfig = $this->getConfig();
00662
00663 $sLogoutLink = $oConfig->isSsl()? $oConfig->getShopSecureHomeUrl() : $oConfig->getShopHomeUrl();
00664 $sLogoutLink .= 'cl='.$oConfig->getRequestParameter('cl').$this->getParent()->getDynUrlParams();
00665 if ( $sParam = $oConfig->getRequestParameter('anid') ) {
00666 $sLogoutLink .= '&anid='.$sParam;
00667 }
00668 if ( $sParam = $oConfig->getRequestParameter('cnid') ) {
00669 $sLogoutLink .= '&cnid='.$sParam;
00670 }
00671 if ( $sParam = $oConfig->getRequestParameter('mnid') ) {
00672 $sLogoutLink .= '&mnid='.$sParam;
00673 }
00674 if ( $sParam = $oConfig->getRequestParameter('tpl') ) {
00675 $sLogoutLink .= '&tpl='.$sParam;
00676 }
00677 if ( $sParam = $oConfig->getRequestParameter('oxloadid') ) {
00678 $sLogoutLink .= '&oxloadid='.$sParam;
00679 }
00680 if ( $sParam = $oConfig->getRequestParameter('recommid') ) {
00681 $sLogoutLink .= '&recommid='.$sParam;
00682 }
00683 return $sLogoutLink.'&fnc=logout';
00684 }
00685
00693 public function setLoginStatus( $iStatus )
00694 {
00695 $this->_iLoginStatus = $iStatus;
00696 }
00697
00706 public function getLoginStatus()
00707 {
00708 return $this->_iLoginStatus;
00709 }
00710
00716 public function getInvitor()
00717 {
00718 $sSu = oxSession::getVar( 'su' );
00719 if ( !$sSu && ( $sSuNew = oxConfig::getParameter( 'su' ) ) ) {
00720 oxSession::setVar( 'su', $sSuNew );
00721 }
00722 }
00723
00729 public function setRecipient()
00730 {
00731 $sRe = oxSession::getVar( 're' );
00732 if ( !$sRe && ( $sReNew = oxConfig::getParameter( 're' ) ) ) {
00733 oxSession::setVar( 're', $sReNew );
00734 }
00735 }
00736 }