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 $this->_loadSessionUser();
00093
00094 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) ) {
00095
00096 $this->getInvitor();
00097 }
00098
00099 parent::init();
00100 }
00101
00114 public function render()
00115 {
00116
00117 $this->_checkPsState();
00118
00119 parent::render();
00120
00121
00122
00123 if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00124 oxSession::setVar( 'dgr', $sDynGoup );
00125 }
00126
00127 $oParentView = $this->getParent();
00128 if ( $aInvAdress = oxConfig::getParameter( 'invadr') ) {
00129 $oParentView->addTplParam( 'invadr', $aInvAdress );
00130 }
00131
00132 if ( ( $aDelAdress = oxConfig::getParameter( 'deladr') ) && !oxConfig::getParameter( 'reloadaddress' ) ) {
00133 $oParentView->addTplParam( 'deladr', $aDelAdress );
00134 }
00135
00136 if ( $sUser = oxConfig::getParameter( 'lgn_usr' ) ) {
00137 $oParentView->addTplParam( 'lgn_usr', $sUser );
00138 }
00139
00140 return $this->getUser();
00141 }
00142
00153 protected function _checkPsState()
00154 {
00155 $oConfig = $this->getConfig();
00156 if ( $this->getParent()->isEnabledPrivateSales() ) {
00157
00158 $oUser = $this->getUser();
00159 $sClass = $this->getParent()->getClassName();
00160
00161
00162 if ( !$oUser && !in_array( $sClass, $this->_aAllowedClasses ) ) {
00163 oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account', false );
00164 }
00165
00166 if ( $oUser && !$oUser->isTermsAccepted() &&
00167 $oConfig->getConfigParam( 'blConfirmAGB' ) &&
00168 !in_array( $sClass, $this->_aAllowedClasses ) ) {
00169 oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account&term=1', false );
00170 }
00171 }
00172 }
00173
00179 protected function _loadSessionUser()
00180 {
00181 $myConfig = $this->getConfig();
00182 $oUser = $this->getUser();
00183
00184
00185 if ( !$oUser ) {
00186 return;
00187 }
00188
00189
00190 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00191 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=content&tpl=user_blocked.tpl' );
00192 }
00193
00194
00195 if ( $oUser->isLoadedFromCookie() ) {
00196
00197
00198 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00199 $myConfig->setGlobalParameter( 'blUserChanged', 1 );
00200 }
00201
00202 if ( $oBasket = $this->getSession()->getBasket() ) {
00203 $oBasket->onUpdate();
00204 }
00205 }
00206 }
00207
00221 public function login()
00222 {
00223 $sUser = oxConfig::getParameter( 'lgn_usr' );
00224 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00225 $sCookie = oxConfig::getParameter( 'lgn_cook' );
00226 $sOpenId = oxConfig::getParameter( 'lgn_openid' );
00227
00228
00229 $this->setLoginStatus( USER_LOGIN_FAIL );
00230
00231
00232 try {
00233 $oUser = oxNew( 'oxuser' );
00234 if ( $this->getViewConfig()->getShowOpenIdLogin() && $sOpenId ) {
00235 $iOldErrorReproting = error_reporting();
00236 error_reporting($iOldErrorReproting & ~E_STRICT);
00237 $oOpenId = oxNew( "oxOpenID" );
00238 $oOpenId->authenticateOid( $sOpenId, $this->_getReturnUrl() );
00239 error_reporting($iOldErrorReproting);
00240 } else {
00241 $oUser->login( $sUser, $sPassword, $sCookie );
00242 }
00243 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00244 } catch ( oxUserException $oEx ) {
00245
00246 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00247 return 'user';
00248 } catch( oxCookieException $oEx ){
00249 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00250 return 'user';
00251 }
00252
00253 return $this->_afterLogin( $oUser );
00254 }
00255
00273 protected function _afterLogin( $oUser )
00274 {
00275 $myConfig = $this->getConfig();
00276
00277
00278 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00279 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl' );
00280 }
00281
00282
00283 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00284
00285
00286 if ( $oBasket = $this->getSession()->getBasket() ) {
00287 $oBasket->onUpdate();
00288 }
00289
00290
00291 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00292 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00293 }
00294
00295
00296 return 'payment';
00297 }
00298
00305 public function login_noredirect()
00306 {
00307 $blAgb = oxConfig::getParameter( 'ord_agb' );
00308 $oConfig = $this->getConfig();
00309 if ( $this->getParent()->isEnabledPrivateSales() && $blAgb !== null &&
00310 $oConfig->getConfigParam( 'blConfirmAGB' ) && ( $oUser = $this->getUser() ) ) {
00311 if ( $blAgb ) {
00312 $oUser->acceptTerms();
00313 }
00314 } else {
00315 $this->login();
00316 }
00317 }
00318
00325 public function login_updateFbId()
00326 {
00327 $this->login();
00328
00329 if ( $oUser = $this->getUser() ) {
00330
00331 if ( $oUser->updateFbId() ) {
00332 oxSession::setVar( '_blFbUserIdUpdated', true );
00333 }
00334 }
00335 }
00336
00345 protected function _afterLogout()
00346 {
00347 oxSession::deleteVar( 'paymentid' );
00348 oxSession::deleteVar( 'sShipSet' );
00349 oxSession::deleteVar( 'deladrid' );
00350 oxSession::deleteVar( 'dynvalue' );
00351
00352
00353 if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00354 $oBasket->resetUserInfo();
00355 $oBasket->onUpdate();
00356 }
00357 }
00358
00367 public function logout()
00368 {
00369 $myConfig = $this->getConfig();
00370 $oUser = oxNew( 'oxuser' );
00371
00372 if ( $oUser->logout() ) {
00373
00374 $this->setLoginStatus( USER_LOGOUT );
00375
00376
00377 $this->_afterLogout();
00378
00379
00380 if ( $this->getParent()->isEnabledPrivateSales() ) {
00381 return 'account';
00382 }
00383
00384
00385 if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00386
00387 oxUtils::getInstance()->redirect( $this->_getLogoutLink());
00388 }
00389 }
00390 }
00391
00401 public function changeUser( )
00402 {
00403
00404
00405 if ( $this->_setupDelAddress() ) {
00406 return;
00407 }
00408
00409 $blUserRegistered = $this->_changeUser_noRedirect( );
00410
00411 if ( $blUserRegistered === true ) {
00412 return 'payment';
00413 } else {
00414 return $blUserRegistered;
00415 }
00416 }
00417
00423 public function changeuser_testvalues()
00424 {
00425
00426
00427
00428 $this->_changeUser_noRedirect();
00429 }
00430
00452 public function createUser()
00453 {
00454
00455 if ( $blSetup = $this->_setupDelAddress() ) {
00456 return;
00457 }
00458
00459 $blActiveLogin = $this->getParent()->isEnabledPrivateSales();
00460
00461 $myConfig = $this->getConfig();
00462 if ( $blActiveLogin && !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00463 oxUtilsView::getInstance()->addErrorToDisplay( 'ORDER_READANDCONFIRMTERMS', false, true );
00464 return;
00465 }
00466
00467 $myUtils = oxUtils::getInstance();
00468
00469
00470 $sUser = oxConfig::getParameter( 'lgn_usr' );
00471
00472
00473 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00474
00475
00476 $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00477
00478 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00479 $aDelAdress = $this->_getDelAddressData();
00480
00481 $oUser = oxNew( 'oxuser' );
00482
00483 try {
00484
00485 $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00486
00487 $iActState = $blActiveLogin ? 0 : 1;
00488
00489
00490 $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00491 $oUser->setPassword( $sPassword );
00492 $oUser->oxuser__oxactive = new oxField( $iActState, oxField::T_RAW);
00493
00494 $oUser->createUser();
00495 $oUser->load( $oUser->getId() );
00496 $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00497
00498 if ( $blActiveLogin ) {
00499
00500 $oUser->acceptTerms();
00501 }
00502
00503 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) && $sUserId = oxConfig::getParameter( "su" ) ) {
00504
00505 $oUser->setCreditPointsForRegistrant( $sUserId );
00506 }
00507
00508
00509 $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00510 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00511
00512 $oUser->addToGroup( 'oxidnotyetordered' );
00513 $oUser->addDynGroup( oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ) );
00514 $oUser->logout();
00515
00516 } catch ( oxUserException $oEx ) {
00517 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00518 return false;
00519 } catch( oxInputException $oEx ){
00520 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00521 return false;
00522 } catch( oxConnectionException $oEx ){
00523 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00524 return false;
00525 }
00526
00527 if ( !$blActiveLogin ) {
00528 if ( !$sPassword ) {
00529 oxSession::setVar( 'usr', $oUser->getId() );
00530 $this->_afterLogin( $oUser );
00531 } elseif ( $this->login() == 'user' ) {
00532 return false;
00533 }
00534
00535
00536
00537 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00538 if ( $sOrderRemark ) {
00539 oxSession::setVar( 'ordrem', $sOrderRemark );
00540 }
00541 }
00542
00543
00544
00545 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00546 $oxEMail = oxNew( 'oxemail' );
00547 if ( $blActiveLogin ) {
00548 $oxEMail->sendRegisterConfirmEmail( $oUser );
00549 } else {
00550 $oxEMail->sendRegisterEmail( $oUser );
00551 }
00552 }
00553
00554
00555 $this->_blIsNewUser = true;
00556
00557 return 'payment';
00558 }
00559
00565 public function registerUser()
00566 {
00567
00568 if ( $blSetup = $this->_setupDelAddress() ) {
00569 return;
00570 }
00571
00572
00573 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00574 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00575 return 'register?success=1';
00576 } else {
00577 return 'register?success=1&newslettererror=4';
00578 }
00579 } else {
00580
00581 $this->logout();
00582 }
00583 }
00584
00598 protected function _changeUser_noRedirect( )
00599 {
00600 if (!$this->getSession()->checkSessionChallenge()) {
00601 return;
00602 }
00603
00604
00605 $oUser = $this->getUser();
00606 if ( !$oUser ) {
00607 return;
00608 }
00609
00610
00611 $aDelAdress = $this->_getDelAddressData();
00612
00613
00614 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00615
00616 $sUserName = $oUser->oxuser__oxusername->value;
00617 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00618
00619 try {
00620 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00621
00622 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00623 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00624 }
00625 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00626
00627 } catch ( oxUserException $oEx ) {
00628
00629
00630 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00631 return;
00632 } catch(oxInputException $oEx) {
00633 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00634 return;
00635 } catch(oxConnectionException $oEx){
00636
00637 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00638 return;
00639 }
00640
00641
00642
00643 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00644 if ( $sOrderRemark ) {
00645 oxSession::setVar( 'ordrem', $sOrderRemark );
00646 }
00647
00648 if ( $oBasket = $this->getSession()->getBasket() ) {
00649 $oBasket->onUpdate();
00650 }
00651 return true;
00652 }
00653
00660 protected function _getDelAddressData()
00661 {
00662
00663 $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $this->_aRawShippingFields );
00664
00665 if ( is_array( $aDeladr ) ) {
00666
00667 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00668 unset( $aDeladr['oxaddress__oxsal'] );
00669 }
00670 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00671
00672 $aDelAdress = array();
00673 }
00674 }
00675 return $aDelAdress;
00676 }
00677
00683 protected function _getLogoutLink()
00684 {
00685 $myConfig = $this->getConfig();
00686 $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00687 if ( $myConfig->isSsl() ) {
00688 $sLogoutLink = $myConfig->getShopHomeUrl();
00689 }
00690 $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->getParent()->getDynUrlParams();
00691 if ( $sParam = oxConfig::getParameter('anid') ) {
00692 $sLogoutLink .= '&anid='.$sParam;
00693 }
00694 if ( $sParam = oxConfig::getParameter('cnid') ) {
00695 $sLogoutLink .= '&cnid='.$sParam;
00696 }
00697 if ( $sParam = oxConfig::getParameter('mnid') ) {
00698 $sLogoutLink .= '&mnid='.$sParam;
00699 }
00700 if ( $sParam = oxConfig::getParameter('tpl') ) {
00701 $sLogoutLink .= '&tpl='.$sParam;
00702 }
00703 return $sLogoutLink.'&fnc=logout';
00704 }
00705
00715 protected function _setupDelAddress()
00716 {
00717 $blShowIt = false;
00718 $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00719
00720
00721 if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00722 $blShowShipAddress = 0;
00723 $blShowIt = true;
00724 } else {
00725
00726 $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00727
00728 if ( $blShowAddress != $blSessShowAddress ) {
00729 $blShowShipAddress = 1;
00730 $blShowIt = true;
00731 }
00732 }
00733
00734 oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00735 if ($this->getParent()) {
00736 $this->getParent()->addTplParam( 'blshowshipaddress', $blShowShipAddress );
00737 }
00738
00739 return $blShowIt;
00740 }
00741
00748 public function loginOid()
00749 {
00750 if (!$this->getViewConfig()->getShowOpenIdLogin()) {
00751 return;
00752 }
00753 $this->setLoginStatus( USER_LOGIN_FAIL );
00754
00755 $iOldErrorReproting = error_reporting();
00756
00757 error_reporting($iOldErrorReproting & ~E_STRICT);
00758 try {
00759 $oOpenId = $this->getOpenId();
00760 $aData = $oOpenId->getOidResponse( $this->_getReturnUrl() );
00761 } catch ( oxUserException $oEx ) {
00762
00763 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00764 }
00765 error_reporting($iOldErrorReproting);
00766 if ( count( $aData ) < 1 ) {
00767 oxUtils::getInstance()->redirect($this->getConfig()->getShopHomeURL().'cl=register');
00768 }
00769 if ( $aData['email'] ) {
00770 $oUser = oxNew( 'oxuser' );
00771 $oUser->oxuser__oxusername = new oxField($aData['email'], oxField::T_RAW);
00772
00773
00774 if ( !$oUser->exists() ) {
00775 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00776 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00777 $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
00778 $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00779 list ($sFName, $sLName) = explode(' ', $aData['fullname']);
00780 $oUser->oxuser__oxfname = new oxField($sFName, oxField::T_RAW);
00781 $oUser->oxuser__oxlname = new oxField($sLName, oxField::T_RAW);
00782
00783 $oUser->oxuser__oxsal = new oxField($this->_getUserTitle($aData['gender']), oxField::T_RAW);
00784 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00785 if ( $sCountryId = $oUser->getUserCountryId( $aData['country'] ) ) {
00786 $oUser->oxuser__oxcountryid = new oxField( $sCountryId, oxField::T_RAW );
00787 }
00788 if ( $aData['postcode'] ) {
00789 $oUser->oxuser__oxzip = new oxField( $aData['postcode'], oxField::T_RAW );
00790 }
00791 $oUser->save();
00792 } else {
00793 $oUser->load( $oUser->getId() );
00794
00795 if ( $oUser->oxuser__oxisopenid->value == 0 ) {
00796 if ( !$oUser->oxuser__oxpassword->value ) {
00797 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00798 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00799 } else {
00800 $oUser->oxuser__oxisopenid = new oxField(2, oxField::T_RAW);
00801 }
00802 $oUser->save();
00803 }
00804 }
00805
00806 try {
00807 $oUser->openIdLogin( $oUser->oxuser__oxusername->value );
00808 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00809 } catch ( oxUserException $oEx ) {
00810
00811 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00812 }
00813
00814
00815 $this->_afterLogin( $oUser );
00816 $this->getParent()->setFncName( null );
00817 oxUtils::getInstance()->redirect($this->getParent()->getLink());
00818 }
00819 }
00820
00828 protected function _getUserTitle( $sGender )
00829 {
00830 if ( $sGender == "F" ) {
00831 return 'MRS';
00832 } else {
00833 return 'MR';
00834 }
00835 }
00836
00842 protected function _getReturnUrl()
00843 {
00844 $this->getParent()->setFncName( 'loginOid' );
00845 $sReturnUrl = str_replace( '&', '&', $this->getParent()->getLink() );
00846 if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00847 if ( strpos( $sReturnUrl, '?' ) ) {
00848 $sReturnUrl = $sReturnUrl . "&fnc=loginOid";
00849 } else {
00850 $sReturnUrl = $sReturnUrl . "?fnc=loginOid";
00851 }
00852 }
00853 return $sReturnUrl;
00854 }
00855
00863 public function setLoginStatus( $iStatus )
00864 {
00865 $this->_iLoginStatus = $iStatus;
00866 }
00867
00876 public function getLoginStatus()
00877 {
00878 return $this->_iLoginStatus;
00879 }
00880
00886 public function getOpenId()
00887 {
00888 return oxNew( "oxOpenID" );
00889 }
00890
00896 public function getInvitor()
00897 {
00898 $sSu = oxSession::getVar( 'su' );
00899 if ( !$sSu && ( $sSuNew = oxConfig::getParameter( 'su' ) ) ) {
00900 oxSession::setVar( 'su', $sSuNew );
00901 }
00902 }
00903 }