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 );
00060
00066 protected $_aRawBillingFields = array( 'oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname',
00067 'oxuser__oxlname', 'oxuser__oxstreet', 'oxuser__oxstreetnr',
00068 'oxuser__oxcity', 'oxuser__oxfon', 'oxuser__oxfax',
00069 'oxuser__oxmobfon', 'oxuser__oxprivfon' );
00070
00076 protected $_aRawShippingFields = array( 'oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxaddress__oxfname',
00077 'oxaddress__oxlname', 'oxaddress__oxcity', 'oxaddress__oxstreet',
00078 'oxaddress__oxstreetnr', 'oxaddress__oxzip', 'oxaddress__oxfon',
00079 'oxaddress__oxfax' );
00089 public function init()
00090 {
00091
00092 $blShow = oxConfig::getParameter( 'blshowshipaddress' );
00093 if (!isset($blShow)) {
00094 $blShow = oxSession::getVar( 'blshowshipaddress' );
00095 }
00096
00097 if (oxConfig::getParameter( 'blhideshipaddress' ) || oxSession::getVar( 'blhideshipaddress' )) {
00098 $blShow = false;
00099 }
00100
00101 oxSession::setVar( 'blshowshipaddress', $blShow );
00102
00103
00104 $this->_loadSessionUser();
00105 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) ) {
00106
00107 $this->getInvitor();
00108 $this->setRecipient();
00109 }
00110
00111 parent::init();
00112 }
00113
00123 public function render()
00124 {
00125
00126 $this->_checkPsState();
00127
00128 parent::render();
00129
00130
00131
00132 if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00133 oxSession::setVar( 'dgr', $sDynGoup );
00134 }
00135
00136 return $this->getUser();
00137 }
00138
00149 protected function _checkPsState()
00150 {
00151 $oConfig = $this->getConfig();
00152 if ( $this->getParent()->isEnabledPrivateSales() ) {
00153
00154 $oUser = $this->getUser();
00155 $sClass = $this->getParent()->getClassName();
00156
00157
00158 if ( !$oUser && !in_array( $sClass, $this->_aAllowedClasses ) ) {
00159 oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account', false );
00160 }
00161
00162 if ( $oUser && !$oUser->isTermsAccepted() &&
00163 $oConfig->getConfigParam( 'blConfirmAGB' ) &&
00164 !in_array( $sClass, $this->_aAllowedClasses ) ) {
00165 oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account&term=1', false );
00166 }
00167 }
00168 }
00169
00175 protected function _loadSessionUser()
00176 {
00177 $myConfig = $this->getConfig();
00178 $oUser = $this->getUser();
00179
00180
00181 if ( !$oUser ) {
00182 return;
00183 }
00184
00185
00186 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00187 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=content&tpl=user_blocked.tpl' );
00188 }
00189
00190
00191 if ( $oUser->isLoadedFromCookie() ) {
00192
00193
00194 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00195 $myConfig->setGlobalParameter( 'blUserChanged', 1 );
00196 }
00197
00198 if ( $oBasket = $this->getSession()->getBasket() ) {
00199 $oBasket->onUpdate();
00200 }
00201 }
00202 }
00203
00217 public function login()
00218 {
00219 $sUser = oxConfig::getParameter( 'lgn_usr' );
00220 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00221 $sCookie = oxConfig::getParameter( 'lgn_cook' );
00222
00223
00224 $this->setLoginStatus( USER_LOGIN_FAIL );
00225
00226
00227 try {
00228 $oUser = oxNew( 'oxuser' );
00229 $oUser->login( $sUser, $sPassword, $sCookie );
00230 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00231 } catch ( oxUserException $oEx ) {
00232
00233 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00234 return 'user';
00235 } catch( oxCookieException $oEx ){
00236 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00237 return 'user';
00238 }
00239
00240 return $this->_afterLogin( $oUser );
00241 }
00242
00260 protected function _afterLogin( $oUser )
00261 {
00262 $oSession = $this->getSession();
00263
00264
00265 if ( $this->getLoginStatus() === USER_LOGIN_SUCCESS ) {
00266 $oSession->regenerateSessionId();
00267 }
00268
00269 $myConfig = $this->getConfig();
00270
00271
00272 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00273 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl' );
00274 }
00275
00276
00277 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00278
00279
00280 if ( $oBasket = $oSession->getBasket() ) {
00281 $oBasket->onUpdate();
00282 }
00283
00284
00285 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00286 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00287 }
00288
00289
00290 return 'payment';
00291 }
00292
00299 public function login_noredirect()
00300 {
00301 $blAgb = oxConfig::getParameter( 'ord_agb' );
00302 $oConfig = $this->getConfig();
00303 if ( $this->getParent()->isEnabledPrivateSales() && $blAgb !== null &&
00304 $oConfig->getConfigParam( 'blConfirmAGB' ) && ( $oUser = $this->getUser() ) ) {
00305 if ( $blAgb ) {
00306 $oUser->acceptTerms();
00307 }
00308 } else {
00309 $this->login();
00310 }
00311 }
00312
00319 public function login_updateFbId()
00320 {
00321 $this->login();
00322
00323 if ( $oUser = $this->getUser() ) {
00324
00325 if ( $oUser->updateFbId() ) {
00326 oxSession::setVar( '_blFbUserIdUpdated', true );
00327 }
00328 }
00329 }
00330
00339 protected function _afterLogout()
00340 {
00341 oxSession::deleteVar( 'paymentid' );
00342 oxSession::deleteVar( 'sShipSet' );
00343 oxSession::deleteVar( 'deladrid' );
00344 oxSession::deleteVar( 'dynvalue' );
00345
00346
00347 if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00348 $oBasket->resetUserInfo();
00349 $oBasket->onUpdate();
00350 }
00351 }
00352
00361 public function logout()
00362 {
00363 $myConfig = $this->getConfig();
00364 $oUser = oxNew( 'oxuser' );
00365
00366 if ( $oUser->logout() ) {
00367
00368 $this->setLoginStatus( USER_LOGOUT );
00369
00370
00371 $this->_afterLogout();
00372
00373
00374 if ( $this->getParent()->isEnabledPrivateSales() ) {
00375 return 'account';
00376 }
00377
00378
00379 if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00380
00381 oxUtils::getInstance()->redirect( $this->_getLogoutLink());
00382 }
00383 }
00384 }
00385
00395 public function changeUser( )
00396 {
00397
00398
00399 if ( $this->_setupDelAddress() ) {
00400 return;
00401 }
00402
00403 $blUserRegistered = $this->_changeUser_noRedirect();
00404
00405 if ( $blUserRegistered === true ) {
00406 return 'payment';
00407 } else {
00408 return $blUserRegistered;
00409 }
00410 }
00411
00417 public function changeuser_testvalues()
00418 {
00419
00420
00421
00422 $this->_changeUser_noRedirect();
00423 }
00424
00446 public function createUser()
00447 {
00448
00449 if ( $blSetup = $this->_setupDelAddress() ) {
00450 return;
00451 }
00452
00453 $blActiveLogin = $this->getParent()->isEnabledPrivateSales();
00454
00455 $myConfig = $this->getConfig();
00456 if ( $blActiveLogin && !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00457 oxUtilsView::getInstance()->addErrorToDisplay( 'ORDER_READANDCONFIRMTERMS', false, true );
00458 return;
00459 }
00460
00461 $myUtils = oxUtils::getInstance();
00462
00463
00464 $sUser = oxConfig::getParameter( 'lgn_usr' );
00465
00466
00467 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00468
00469
00470 $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00471
00472 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00473 $aDelAdress = $this->_getDelAddressData();
00474
00475 $oUser = oxNew( 'oxuser' );
00476
00477 try {
00478
00479 $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00480
00481 $iActState = $blActiveLogin ? 0 : 1;
00482
00483
00484 $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00485 $oUser->setPassword( $sPassword );
00486 $oUser->oxuser__oxactive = new oxField( $iActState, oxField::T_RAW);
00487
00488 $oUser->createUser();
00489 $oUser->load( $oUser->getId() );
00490 $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00491
00492 if ( $blActiveLogin ) {
00493
00494 $oUser->acceptTerms();
00495 }
00496
00497 $sUserId = oxSession::getVar( "su" );
00498 $sRecEmail = oxSession::getVar( "re" );
00499 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) && $sUserId && $sRecEmail ) {
00500
00501 $oUser->setCreditPointsForRegistrant( $sUserId, $sRecEmail );
00502 }
00503
00504
00505 $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00506 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00507
00508 $oUser->addToGroup( 'oxidnotyetordered' );
00509 $oUser->addDynGroup( oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ) );
00510 $oUser->logout();
00511
00512 } catch ( oxUserException $oEx ) {
00513 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00514 return false;
00515 } catch( oxInputException $oEx ){
00516 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00517 return false;
00518 } catch( oxConnectionException $oEx ){
00519 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00520 return false;
00521 }
00522
00523 if ( !$blActiveLogin ) {
00524 if ( !$sPassword ) {
00525 oxSession::setVar( 'usr', $oUser->getId() );
00526 $this->_afterLogin( $oUser );
00527 } elseif ( $this->login() == 'user' ) {
00528 return false;
00529 }
00530
00531
00532
00533 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00534 if ( $sOrderRemark ) {
00535 oxSession::setVar( 'ordrem', $sOrderRemark );
00536 }
00537 }
00538
00539
00540
00541 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00542 $oxEMail = oxNew( 'oxemail' );
00543 if ( $blActiveLogin ) {
00544 $oxEMail->sendRegisterConfirmEmail( $oUser );
00545 } else {
00546 $oxEMail->sendRegisterEmail( $oUser );
00547 }
00548 }
00549
00550
00551 $this->_blIsNewUser = true;
00552
00553 return 'payment';
00554 }
00555
00561 public function registerUser()
00562 {
00563
00564 if ( $blSetup = $this->_setupDelAddress() ) {
00565 return;
00566 }
00567
00568
00569 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00570 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00571 return 'register?success=1';
00572 } else {
00573 return 'register?success=1&newslettererror=4';
00574 }
00575 } else {
00576
00577 $this->logout();
00578 }
00579 }
00580
00594 protected function _changeUser_noRedirect( )
00595 {
00596 if (!$this->getSession()->checkSessionChallenge()) {
00597 return;
00598 }
00599
00600
00601 $oUser = $this->getUser();
00602 if ( !$oUser ) {
00603 return;
00604 }
00605
00606
00607 $aDelAdress = $this->_getDelAddressData();
00608
00609
00610 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00611
00612 $sUserName = $oUser->oxuser__oxusername->value;
00613 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00614
00615 try {
00616 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00617
00618 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00619 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00620 }
00621 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00622
00623 } catch ( oxUserException $oEx ) {
00624
00625
00626 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00627 return;
00628 } catch(oxInputException $oEx) {
00629 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00630 return;
00631 } catch(oxConnectionException $oEx){
00632
00633 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00634 return;
00635 }
00636
00637
00638
00639 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00640
00641 if ( $sOrderRemark ) {
00642 oxSession::setVar( 'ordrem', $sOrderRemark );
00643 } else {
00644 oxSession::deleteVar( 'ordrem' );
00645 }
00646
00647 if ( $oBasket = $this->getSession()->getBasket() ) {
00648 $oBasket->onUpdate();
00649 }
00650 return true;
00651 }
00652
00659 protected function _getDelAddressData()
00660 {
00661
00662 $aDelAdress = $aDeladr = (oxConfig::getParameter( 'blshowshipaddress' ) || oxSession::getVar( 'blshowshipaddress' )) ? oxConfig::getParameter( 'deladr', $this->_aRawShippingFields ) : array();
00663
00664 if ( is_array( $aDeladr ) ) {
00665
00666 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00667 unset( $aDeladr['oxaddress__oxsal'] );
00668 }
00669 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00670
00671 $aDelAdress = array();
00672 }
00673 }
00674 return $aDelAdress;
00675 }
00676
00682 protected function _getLogoutLink()
00683 {
00684 $myConfig = $this->getConfig();
00685 $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00686 if ( $myConfig->isSsl() ) {
00687 $sLogoutLink = $myConfig->getShopHomeUrl();
00688 }
00689 $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->getParent()->getDynUrlParams();
00690 if ( $sParam = oxConfig::getParameter('anid') ) {
00691 $sLogoutLink .= '&anid='.$sParam;
00692 }
00693 if ( $sParam = oxConfig::getParameter('cnid') ) {
00694 $sLogoutLink .= '&cnid='.$sParam;
00695 }
00696 if ( $sParam = oxConfig::getParameter('mnid') ) {
00697 $sLogoutLink .= '&mnid='.$sParam;
00698 }
00699 if ( $sParam = oxConfig::getParameter('tpl') ) {
00700 $sLogoutLink .= '&tpl='.$sParam;
00701 }
00702 return $sLogoutLink.'&fnc=logout';
00703 }
00704
00715 protected function _setupDelAddress()
00716 {
00717 return (oxConfig::getParameter( 'blshowshipaddress' ) !== null || oxConfig::getParameter( 'blhideshipaddress' ) !== null) && oxConfig::getParameter( 'userform' ) === null;
00718 }
00719
00727 public function setLoginStatus( $iStatus )
00728 {
00729 $this->_iLoginStatus = $iStatus;
00730 }
00731
00740 public function getLoginStatus()
00741 {
00742 return $this->_iLoginStatus;
00743 }
00744
00750 public function getInvitor()
00751 {
00752 $sSu = oxSession::getVar( 'su' );
00753 if ( !$sSu && ( $sSuNew = oxConfig::getParameter( 'su' ) ) ) {
00754 oxSession::setVar( 'su', $sSuNew );
00755 }
00756 }
00757
00763 public function setRecipient()
00764 {
00765 $sRe = oxSession::getVar( 're' );
00766 if ( !$sRe && ( $sReNew = oxConfig::getParameter( 're' ) ) ) {
00767 oxSession::setVar( 're', $sReNew );
00768 }
00769 }
00770 }