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 );
00067 protected $_blActiveLogin = false;
00068
00076 protected function _setActiveLogin( $blActiveLogin )
00077 {
00078 $this->_blActiveLogin = $blActiveLogin;
00079 }
00080
00086 protected function _getActiveLogin()
00087 {
00088 return $this->_blActiveLogin;
00089 }
00090
00100 public function init()
00101 {
00102
00103 $blShow = oxConfig::getParameter( 'blshowshipaddress' );
00104 if (!isset($blShow)) {
00105 $blShow = oxSession::getVar( 'blshowshipaddress' );
00106 }
00107
00108 oxSession::setVar( 'blshowshipaddress', $blShow );
00109
00110
00111 $this->_loadSessionUser();
00112 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) ) {
00113
00114 $this->getInvitor();
00115 $this->setRecipient();
00116 }
00117
00118
00119
00120 if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00121 oxSession::setVar( 'dgr', $sDynGoup );
00122 }
00123
00124 parent::init();
00125 }
00126
00136 public function render()
00137 {
00138
00139 $this->_checkPsState();
00140
00141 parent::render();
00142
00143 return $this->getUser();
00144 }
00145
00156 protected function _checkPsState()
00157 {
00158 $oConfig = $this->getConfig();
00159 if ( $this->getParent()->isEnabledPrivateSales() ) {
00160
00161 $oUser = $this->getUser();
00162 $sClass = $this->getParent()->getClassName();
00163
00164
00165 if ( !$oUser && !in_array( $sClass, $this->_aAllowedClasses ) ) {
00166 oxRegistry::getUtils()->redirect( $oConfig->getShopHomeURL() . 'cl=account', false, 302 );
00167 }
00168
00169 if ( $oUser && !$oUser->isTermsAccepted() && !in_array( $sClass, $this->_aAllowedClasses ) ) {
00170 oxRegistry::getUtils()->redirect( $oConfig->getShopHomeURL() . 'cl=account&term=1', false, 302 );
00171 }
00172 }
00173 }
00174
00180 protected function _loadSessionUser()
00181 {
00182 $myConfig = $this->getConfig();
00183 $oUser = $this->getUser();
00184
00185
00186 if ( !$oUser ) {
00187 return;
00188 }
00189
00190
00191 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00192 oxRegistry::getUtils()->redirect( $myConfig->getShopHomeURL() . 'cl=content&tpl=user_blocked.tpl', true, 302 );
00193 }
00194
00195
00196 if ( $oUser->isLoadedFromCookie() && !$myConfig->getConfigParam( 'blPerfNoBasketSaving' )) {
00197
00198 if ( $oBasket = $this->getSession()->getBasket() ) {
00199 $oBasket->load();
00200 $oBasket->onUpdate();
00201 }
00202 }
00203 }
00204
00218 public function login()
00219 {
00220 $sUser = oxConfig::getParameter( 'lgn_usr' );
00221 $sPassword = oxConfig::getParameter( 'lgn_pwd', true );
00222 $sCookie = oxConfig::getParameter( 'lgn_cook' );
00223
00224
00225 $this->setLoginStatus( USER_LOGIN_FAIL );
00226
00227
00228 try {
00229 $oUser = oxNew( 'oxuser' );
00230 $oUser->login( $sUser, $sPassword, $sCookie );
00231 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00232 } catch ( oxUserException $oEx ) {
00233
00234 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true, '', false );
00235 return 'user';
00236 } catch( oxCookieException $oEx ){
00237 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
00238 return 'user';
00239 }
00240
00241 return $this->_afterLogin( $oUser );
00242 }
00243
00261 protected function _afterLogin( $oUser )
00262 {
00263 $oSession = $this->getSession();
00264
00265
00266 if ( $this->getLoginStatus() === USER_LOGIN_SUCCESS ) {
00267 $oSession->regenerateSessionId();
00268 }
00269
00270 $myConfig = $this->getConfig();
00271
00272
00273 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00274 oxRegistry::getUtils()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl', true, 302 );
00275 }
00276
00277
00278 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00279
00280
00281 if ( $oBasket = $oSession->getBasket() ) {
00282 $oBasket->onUpdate();
00283 }
00284
00285
00286 return 'payment';
00287 }
00288
00295 public function login_noredirect()
00296 {
00297 $blAgb = oxConfig::getParameter( 'ord_agb' );
00298 $oConfig = $this->getConfig();
00299 if ( $this->getParent()->isEnabledPrivateSales() && $blAgb !== null && ( $oUser = $this->getUser() ) ) {
00300 if ( $blAgb ) {
00301 $oUser->acceptTerms();
00302 }
00303 } else {
00304 $this->login();
00305
00306 if ( !$this->isAdmin() && !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' )) {
00307
00308 try {
00309 if ( $oBasket = $this->getSession()->getBasket() ) {
00310 $oBasket->load();
00311 }
00312 } catch ( Exception $oE ) {
00313
00314 }
00315 }
00316
00317
00318 }
00319 }
00320
00327 public function login_updateFbId()
00328 {
00329 $this->login();
00330
00331 if ( $oUser = $this->getUser() ) {
00332
00333 if ( $oUser->updateFbId() ) {
00334 oxSession::setVar( '_blFbUserIdUpdated', true );
00335 }
00336 }
00337 }
00338
00347 protected function _afterLogout()
00348 {
00349 oxSession::deleteVar( 'paymentid' );
00350 oxSession::deleteVar( 'sShipSet' );
00351 oxSession::deleteVar( 'deladrid' );
00352 oxSession::deleteVar( 'dynvalue' );
00353
00354
00355 if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00356 $oBasket->resetUserInfo();
00357 $oBasket->onUpdate();
00358 }
00359 }
00360
00369 public function logout()
00370 {
00371 $myConfig = $this->getConfig();
00372 $oUser = oxNew( 'oxuser' );
00373
00374 if ( $oUser->logout() ) {
00375
00376 $this->setLoginStatus( USER_LOGOUT );
00377
00378
00379 $this->_afterLogout();
00380
00381
00382 if ( $this->getParent()->isEnabledPrivateSales() ) {
00383 return 'account';
00384 }
00385
00386
00387 if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00388 oxRegistry::getUtils()->redirect( $this->_getLogoutLink());
00389 }
00390 }
00391 }
00392
00402 public function changeUser( )
00403 {
00404 $blUserRegistered = $this->_changeUser_noRedirect();
00405
00406 if ( $blUserRegistered === true ) {
00407 return 'payment';
00408 } else {
00409 return $blUserRegistered;
00410 }
00411 }
00412
00419 public function changeuser_testvalues()
00420 {
00421
00422
00423
00424
00425 if ( $this->_changeUser_noRedirect() ) {
00426 return 'account_user';
00427 }
00428 }
00429
00451 public function createUser()
00452 {
00453 $blActiveLogin = $this->getParent()->isEnabledPrivateSales();
00454 $this->_setActiveLogin( $blActiveLogin );
00455
00456 $myConfig = $this->getConfig();
00457 if ( $blActiveLogin && !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00458 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'READ_AND_CONFIRM_TERMS', false, true );
00459 return;
00460 }
00461
00462 $myUtils = oxRegistry::getUtils();
00463
00464
00465 $sUser = oxConfig::getParameter( 'lgn_usr' );
00466
00467
00468 $sPassword = oxConfig::getParameter( 'lgn_pwd', true );
00469
00470
00471 $sPassword2 = oxConfig::getParameter( 'lgn_pwd2', true );
00472
00473 $aInvAdress = oxConfig::getParameter( 'invadr', true );
00474 $aDelAdress = $this->_getDelAddressData();
00475
00476 $oUser = oxNew( 'oxuser' );
00477
00478 try {
00479
00480 $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00481
00482 $iActState = $blActiveLogin ? 0 : 1;
00483
00484
00485 $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00486 $oUser->setPassword( $sPassword );
00487 $oUser->oxuser__oxactive = new oxField( $iActState, oxField::T_RAW);
00488
00489
00490 $iSubscriptionStatus = $oUser->getNewsSubscription()->getOptInStatus();
00491
00492 $oUser->createUser();
00493 $oUser->load($oUser->getId());
00494 $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00495
00496 if ( $blActiveLogin ) {
00497
00498 $oUser->acceptTerms();
00499 }
00500
00501 $sUserId = oxSession::getVar( "su" );
00502 $sRecEmail = oxSession::getVar( "re" );
00503 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) && $sUserId && $sRecEmail ) {
00504
00505 $oUser->setCreditPointsForRegistrant( $sUserId, $sRecEmail );
00506 }
00507
00508
00509 $blOptin = oxRegistry::getConfig()->getRequestParameter( 'blnewssubscribed' );
00510 if ( $blOptin && $iSubscriptionStatus == 1 ) {
00511
00512 $oUser->getNewsSubscription()->setOptInStatus(1);
00513 $oUser->addToGroup( 'oxidnewsletter' );
00514 $this->_blNewsSubscriptionStatus = 1;
00515 } else {
00516 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00517 }
00518
00519 $oUser->addToGroup( 'oxidnotyetordered' );
00520 $oUser->addDynGroup( oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ) );
00521 $oUser->logout();
00522
00523 } catch ( oxUserException $oEx ) {
00524 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true );
00525 return false;
00526 } catch( oxInputException $oEx ){
00527 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true );
00528 return false;
00529 } catch( oxConnectionException $oEx ){
00530 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true );
00531 return false;
00532 }
00533
00534 $this->_setOrderRemark( $oUser );
00535
00536
00537
00538 $this->_sendRegistrationEmail( $oUser );
00539
00540
00541 $this->_blIsNewUser = true;
00542
00543 $sAction = 'payment?new_user=1&success=1';
00544 if ($this->_blNewsSubscriptionStatus !== null && !$this->_blNewsSubscriptionStatus) {
00545 $sAction = 'payment?new_user=1&success=1&newslettererror=4';
00546 }
00547
00548 return $sAction;
00549 }
00550
00556 public function registerUser()
00557 {
00558
00559 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00560 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00561 return 'register?success=1';
00562 } else {
00563 return 'register?success=1&newslettererror=4';
00564 }
00565 } else {
00566
00567 $this->logout();
00568 }
00569 }
00570
00584 protected function _changeUser_noRedirect( )
00585 {
00586 if (!$this->getSession()->checkSessionChallenge()) {
00587 return;
00588 }
00589
00590
00591 $oUser = $this->getUser();
00592 if ( !$oUser ) {
00593 return;
00594 }
00595
00596
00597 $aDelAdress = $this->_getDelAddressData();
00598
00599
00600 $aInvAdress = oxConfig::getParameter( 'invadr', true );
00601
00602 $sUserName = $oUser->oxuser__oxusername->value;
00603 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00604
00605 try {
00606 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00607
00608 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00609 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00610 }
00611
00612 $blForceCheckOptIn = ( $aInvAdress['oxuser__oxusername'] !== null && $aInvAdress['oxuser__oxusername'] !== $sUserName );
00613 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ), $blForceCheckOptIn );
00614
00615 } catch ( oxUserException $oEx ) {
00616
00617
00618 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
00619 return;
00620 } catch(oxInputException $oEx) {
00621 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
00622 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'input_not_all_fields');
00623 return;
00624 } catch(oxConnectionException $oEx){
00625
00626 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
00627 return;
00628 }
00629
00630
00631
00632 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00633
00634 if ( $sOrderRemark ) {
00635 oxSession::setVar( 'ordrem', $sOrderRemark );
00636 } else {
00637 oxSession::deleteVar( 'ordrem' );
00638 }
00639
00640 if ( $oBasket = $this->getSession()->getBasket() ) {
00641 $oBasket->onUpdate();
00642 }
00643 return true;
00644 }
00645
00652 protected function _getDelAddressData()
00653 {
00654
00655 $aDelAdress = $aDeladr = (oxConfig::getParameter( 'blshowshipaddress' ) || oxSession::getVar( 'blshowshipaddress' )) ? oxConfig::getParameter( 'deladr', true ) : array();
00656
00657 if ( is_array( $aDeladr ) ) {
00658
00659 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00660 unset( $aDeladr['oxaddress__oxsal'] );
00661 }
00662 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00663
00664 $aDelAdress = array();
00665 }
00666 }
00667 return $aDelAdress;
00668 }
00669
00675 protected function _getLogoutLink()
00676 {
00677 $oConfig = $this->getConfig();
00678
00679 $sLogoutLink = $oConfig->isSsl()? $oConfig->getShopSecureHomeUrl() : $oConfig->getShopHomeUrl();
00680 $sLogoutLink .= 'cl='.$oConfig->getRequestParameter('cl').$this->getParent()->getDynUrlParams();
00681 if ( $sParam = $oConfig->getRequestParameter('anid') ) {
00682 $sLogoutLink .= '&anid='.$sParam;
00683 }
00684 if ( $sParam = $oConfig->getRequestParameter('cnid') ) {
00685 $sLogoutLink .= '&cnid='.$sParam;
00686 }
00687 if ( $sParam = $oConfig->getRequestParameter('mnid') ) {
00688 $sLogoutLink .= '&mnid='.$sParam;
00689 }
00690 if ( $sParam = $oConfig->getRequestParameter('tpl') ) {
00691 $sLogoutLink .= '&tpl='.$sParam;
00692 }
00693 if ( $sParam = $oConfig->getRequestParameter('oxloadid') ) {
00694 $sLogoutLink .= '&oxloadid='.$sParam;
00695 }
00696 if ( $sParam = $oConfig->getRequestParameter('recommid') ) {
00697 $sLogoutLink .= '&recommid='.$sParam;
00698 }
00699 return $sLogoutLink.'&fnc=logout';
00700 }
00701
00709 public function setLoginStatus( $iStatus )
00710 {
00711 $this->_iLoginStatus = $iStatus;
00712 }
00713
00722 public function getLoginStatus()
00723 {
00724 return $this->_iLoginStatus;
00725 }
00726
00732 public function getInvitor()
00733 {
00734 $sSu = oxSession::getVar( 'su' );
00735 if ( !$sSu && ( $sSuNew = oxConfig::getParameter( 'su' ) ) ) {
00736 oxSession::setVar( 'su', $sSuNew );
00737 }
00738 }
00739
00745 public function setRecipient()
00746 {
00747 $sRe = oxSession::getVar( 're' );
00748 if ( !$sRe && ( $sReNew = oxConfig::getParameter( 're' ) ) ) {
00749 oxSession::setVar( 're', $sReNew );
00750 }
00751 }
00752
00760 public function _setOrderRemark( $oUser )
00761 {
00762 $blActiveLogin = $this->_getActiveLogin();
00763 if ( !$blActiveLogin ) {
00764
00765 oxRegistry::getSession()->setVariable( 'usr', $oUser->getId() );
00766 $this->_afterLogin( $oUser );
00767
00768
00769
00770
00771 $sOrderRemark = oxRegistry::getConfig()->getRequestParameter( 'order_remark', true );
00772 if ( $sOrderRemark ) {
00773 oxRegistry::getSession()->setVariable( 'ordrem', $sOrderRemark );
00774 }
00775 }
00776 }
00777
00785 public function _sendRegistrationEmail( $oUser )
00786 {
00787 $blActiveLogin = $this->_getActiveLogin();
00788 if ( (int) oxRegistry::getConfig()->getRequestParameter( 'option' ) == 3 ) {
00789 $oxEMail = oxNew( 'oxemail' );
00790 if ( $blActiveLogin ) {
00791 $oxEMail->sendRegisterConfirmEmail( $oUser );
00792 } else {
00793 $oxEMail->sendRegisterEmail( $oUser );
00794 }
00795 }
00796 }
00797 }