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
00106 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) ) {
00107
00108 $this->getInvitor();
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 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) && $sUserId = oxConfig::getParameter( "su" ) ) {
00498
00499 $oUser->setCreditPointsForRegistrant( $sUserId );
00500 }
00501
00502
00503 $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00504 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00505
00506 $oUser->addToGroup( 'oxidnotyetordered' );
00507 $oUser->addDynGroup( oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ) );
00508 $oUser->logout();
00509
00510 } catch ( oxUserException $oEx ) {
00511 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00512 return false;
00513 } catch( oxInputException $oEx ){
00514 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00515 return false;
00516 } catch( oxConnectionException $oEx ){
00517 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00518 return false;
00519 }
00520
00521 if ( !$blActiveLogin ) {
00522 if ( !$sPassword ) {
00523 oxSession::setVar( 'usr', $oUser->getId() );
00524 $this->_afterLogin( $oUser );
00525 } elseif ( $this->login() == 'user' ) {
00526 return false;
00527 }
00528
00529
00530
00531 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00532 if ( $sOrderRemark ) {
00533 oxSession::setVar( 'ordrem', $sOrderRemark );
00534 }
00535 }
00536
00537
00538
00539 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00540 $oxEMail = oxNew( 'oxemail' );
00541 if ( $blActiveLogin ) {
00542 $oxEMail->sendRegisterConfirmEmail( $oUser );
00543 } else {
00544 $oxEMail->sendRegisterEmail( $oUser );
00545 }
00546 }
00547
00548
00549 $this->_blIsNewUser = true;
00550
00551 return 'payment';
00552 }
00553
00559 public function registerUser()
00560 {
00561
00562 if ( $blSetup = $this->_setupDelAddress() ) {
00563 return;
00564 }
00565
00566
00567 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00568 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00569 return 'register?success=1';
00570 } else {
00571 return 'register?success=1&newslettererror=4';
00572 }
00573 } else {
00574
00575 $this->logout();
00576 }
00577 }
00578
00592 protected function _changeUser_noRedirect( )
00593 {
00594 if (!$this->getSession()->checkSessionChallenge()) {
00595 return;
00596 }
00597
00598
00599 $oUser = $this->getUser();
00600 if ( !$oUser ) {
00601 return;
00602 }
00603
00604
00605 $aDelAdress = $this->_getDelAddressData();
00606
00607
00608 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00609
00610 $sUserName = $oUser->oxuser__oxusername->value;
00611 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00612
00613 try {
00614 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00615
00616 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00617 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00618 }
00619 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00620
00621 } catch ( oxUserException $oEx ) {
00622
00623
00624 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00625 return;
00626 } catch(oxInputException $oEx) {
00627 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00628 return;
00629 } catch(oxConnectionException $oEx){
00630
00631 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00632 return;
00633 }
00634
00635
00636
00637 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00638 if ( $sOrderRemark ) {
00639 oxSession::setVar( 'ordrem', $sOrderRemark );
00640 }
00641
00642 if ( $oBasket = $this->getSession()->getBasket() ) {
00643 $oBasket->onUpdate();
00644 }
00645 return true;
00646 }
00647
00654 protected function _getDelAddressData()
00655 {
00656
00657 $aDelAdress = $aDeladr = (oxConfig::getParameter( 'blshowshipaddress' ) || oxSession::getVar( 'blshowshipaddress' )) ? oxConfig::getParameter( 'deladr', $this->_aRawShippingFields ) : array();
00658
00659 if ( is_array( $aDeladr ) ) {
00660
00661 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00662 unset( $aDeladr['oxaddress__oxsal'] );
00663 }
00664 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00665
00666 $aDelAdress = array();
00667 }
00668 }
00669 return $aDelAdress;
00670 }
00671
00677 protected function _getLogoutLink()
00678 {
00679 $myConfig = $this->getConfig();
00680 $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00681 if ( $myConfig->isSsl() ) {
00682 $sLogoutLink = $myConfig->getShopHomeUrl();
00683 }
00684 $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->getParent()->getDynUrlParams();
00685 if ( $sParam = oxConfig::getParameter('anid') ) {
00686 $sLogoutLink .= '&anid='.$sParam;
00687 }
00688 if ( $sParam = oxConfig::getParameter('cnid') ) {
00689 $sLogoutLink .= '&cnid='.$sParam;
00690 }
00691 if ( $sParam = oxConfig::getParameter('mnid') ) {
00692 $sLogoutLink .= '&mnid='.$sParam;
00693 }
00694 if ( $sParam = oxConfig::getParameter('tpl') ) {
00695 $sLogoutLink .= '&tpl='.$sParam;
00696 }
00697 return $sLogoutLink.'&fnc=logout';
00698 }
00699
00710 protected function _setupDelAddress()
00711 {
00712 return (oxConfig::getParameter( 'blshowshipaddress' ) !== null || oxConfig::getParameter( 'blhideshipaddress' ) !== null) && oxConfig::getParameter( 'userform' ) === null;
00713 }
00714
00722 public function setLoginStatus( $iStatus )
00723 {
00724 $this->_iLoginStatus = $iStatus;
00725 }
00726
00735 public function getLoginStatus()
00736 {
00737 return $this->_iLoginStatus;
00738 }
00739
00745 public function getInvitor()
00746 {
00747 $sSu = oxSession::getVar( 'su' );
00748 if ( !$sSu && ( $sSuNew = oxConfig::getParameter( 'su' ) ) ) {
00749 oxSession::setVar( 'su', $sSuNew );
00750 }
00751 }
00752 }