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
00129
00130
00131
00132
00133
00134
00135 if ( $aInvAdress = oxConfig::getParameter( 'invadr') ) {
00136 $oParentView->addTplParam( 'invadr', $aInvAdress );
00137 }
00138
00139 if ( ( $aDelAdress = oxConfig::getParameter( 'deladr') ) && !oxConfig::getParameter( 'reloadaddress' ) ) {
00140 $oParentView->addTplParam( 'deladr', $aDelAdress );
00141 }
00142
00143 if ( $sUser = oxConfig::getParameter( 'lgn_usr' ) ) {
00144 $oParentView->addTplParam( 'lgn_usr', $sUser );
00145 }
00146
00147 return $this->getUser();
00148 }
00149
00160 protected function _checkPsState()
00161 {
00162 $oConfig = $this->getConfig();
00163 if ( $oConfig->getConfigParam( 'blPsLoginEnabled' ) ) {
00164
00165 $oUser = $this->getUser();
00166 $sClass = $this->getParent()->getClassName();
00167
00168
00169 if ( !$oUser && !in_array( $sClass, $this->_aAllowedClasses ) ) {
00170 oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account', false );
00171 }
00172
00173 if ( $oUser && !$oUser->isTermsAccepted() &&
00174 $oConfig->getConfigParam( 'blConfirmAGB' ) &&
00175 !in_array( $sClass, $this->_aAllowedClasses ) ) {
00176 oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account&term=1', false );
00177 }
00178 }
00179 }
00180
00186 protected function _loadSessionUser()
00187 {
00188 $myConfig = $this->getConfig();
00189 $oUser = $this->getUser();
00190
00191
00192 if ( !$oUser ) {
00193 return;
00194 }
00195
00196
00197 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00198 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=content&tpl=user_blocked.tpl' );
00199 }
00200
00201
00202 if ( $oUser->isLoadedFromCookie() ) {
00203
00204
00205 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00206 $myConfig->setGlobalParameter( 'blUserChanged', 1 );
00207 }
00208
00209 if ( $oBasket = $this->getSession()->getBasket() ) {
00210 $oBasket->onUpdate();
00211 }
00212 }
00213 }
00214
00228 public function login()
00229 {
00230 $sUser = oxConfig::getParameter( 'lgn_usr' );
00231 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00232 $sCookie = oxConfig::getParameter( 'lgn_cook' );
00233 $sOpenId = oxConfig::getParameter( 'lgn_openid' );
00234
00235
00236 $this->setLoginStatus( USER_LOGIN_FAIL );
00237
00238
00239 try {
00240 $oUser = oxNew( 'oxuser' );
00241 if ( $this->getViewConfig()->getShowOpenIdLogin() && $sOpenId ) {
00242 $iOldErrorReproting = error_reporting();
00243 error_reporting($iOldErrorReproting & ~E_STRICT);
00244 $oOpenId = oxNew( "oxOpenID" );
00245 $oOpenId->authenticateOid( $sOpenId, $this->_getReturnUrl() );
00246 error_reporting($iOldErrorReproting);
00247 } else {
00248 $oUser->login( $sUser, $sPassword, $sCookie );
00249 }
00250 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00251 } catch ( oxUserException $oEx ) {
00252
00253 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00254 return 'user';
00255 } catch( oxCookieException $oEx ){
00256 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00257 return 'user';
00258 }
00259
00260 return $this->_afterLogin( $oUser );
00261 }
00262
00280 protected function _afterLogin( $oUser )
00281 {
00282 $myConfig = $this->getConfig();
00283
00284
00285 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00286 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl' );
00287 }
00288
00289
00290 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00291
00292
00293 if ( $oBasket = $this->getSession()->getBasket() ) {
00294 $oBasket->onUpdate();
00295 }
00296
00297
00298 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00299 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00300 }
00301
00302
00303 return 'payment';
00304 }
00305
00312 public function login_noredirect()
00313 {
00314 $blAgb = oxConfig::getParameter( 'ord_agb' );
00315 $oConfig = $this->getConfig();
00316 if ( $oConfig->getConfigParam( 'blPsLoginEnabled' ) && $blAgb !== null &&
00317 $oConfig->getConfigParam( 'blConfirmAGB' ) && ( $oUser = $this->getUser() ) ) {
00318 if ( $blAgb ) {
00319 $oUser->acceptTerms();
00320 }
00321 } else {
00322 $this->login();
00323 }
00324 }
00325
00332 public function login_updateFbId()
00333 {
00334 $this->login();
00335
00336 if ( $oUser = $this->getUser() ) {
00337
00338 if ( $oUser->updateFbId() ) {
00339 oxSession::setVar( '_blFbUserIdUpdated', true );
00340 }
00341 }
00342 }
00343
00352 protected function _afterLogout()
00353 {
00354 oxSession::deleteVar( 'paymentid' );
00355 oxSession::deleteVar( 'sShipSet' );
00356 oxSession::deleteVar( 'deladrid' );
00357 oxSession::deleteVar( 'dynvalue' );
00358
00359
00360 if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00361 $oBasket->resetUserInfo();
00362 $oBasket->onUpdate();
00363 }
00364 }
00365
00374 public function logout()
00375 {
00376 $myConfig = $this->getConfig();
00377 $oUser = oxNew( 'oxuser' );
00378
00379 if ( $oUser->logout() ) {
00380
00381 $this->setLoginStatus( USER_LOGOUT );
00382
00383
00384 $this->_afterLogout();
00385
00386
00387 if ( $this->getConfig()->getConfigParam( 'blPsLoginEnabled' ) ) {
00388 return 'account';
00389 }
00390
00391
00392 if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00393
00394 oxUtils::getInstance()->redirect( $this->_getLogoutLink());
00395 }
00396 }
00397 }
00398
00408 public function changeUser( )
00409 {
00410
00411
00412 if ( $this->_setupDelAddress() ) {
00413 return;
00414 }
00415
00416 $blUserRegistered = $this->_changeUser_noRedirect( );
00417
00418 if ( $blUserRegistered === true ) {
00419 return 'payment';
00420 } else {
00421 return $blUserRegistered;
00422 }
00423 }
00424
00430 public function changeuser_testvalues()
00431 {
00432
00433
00434
00435 $this->_changeUser_noRedirect();
00436 }
00437
00459 public function createUser()
00460 {
00461
00462 if ( $blSetup = $this->_setupDelAddress() ) {
00463 return;
00464 }
00465
00466 $blActiveLogin = $this->getConfig()->getConfigParam( 'blPsLoginEnabled' );
00467
00468 $myConfig = $this->getConfig();
00469 if ( $blActiveLogin && !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00470 oxUtilsView::getInstance()->addErrorToDisplay( 'ORDER_READANDCONFIRMTERMS', false, true );
00471 return;
00472 }
00473
00474 $myUtils = oxUtils::getInstance();
00475
00476
00477 $sUser = oxConfig::getParameter( 'lgn_usr' );
00478
00479
00480 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00481
00482
00483 $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00484
00485 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00486 $aDelAdress = $this->_getDelAddressData();
00487
00488 $oUser = oxNew( 'oxuser' );
00489
00490 try {
00491
00492 $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00493
00494 $iActState = $blActiveLogin ? 0 : 1;
00495
00496
00497 $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00498 $oUser->setPassword( $sPassword );
00499 $oUser->oxuser__oxactive = new oxField( $iActState, oxField::T_RAW);
00500
00501 $oUser->createUser();
00502 $oUser->load( $oUser->getId() );
00503 $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00504
00505 if ( $blActiveLogin ) {
00506
00507 $oUser->acceptTerms();
00508 }
00509
00510 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) && $sUserId = oxConfig::getParameter( "su" ) ) {
00511
00512 $oUser->setCreditPointsForRegistrant( $sUserId );
00513 }
00514
00515
00516 $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00517 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00518
00519 $oUser->addToGroup( 'oxidnotyetordered' );
00520 $oUser->addDynGroup( oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ) );
00521 $oUser->logout();
00522
00523 } catch ( oxUserException $oEx ) {
00524 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00525 return false;
00526 } catch( oxInputException $oEx ){
00527 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00528 return false;
00529 } catch( oxConnectionException $oEx ){
00530 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00531 return false;
00532 }
00533
00534 if ( !$blActiveLogin ) {
00535 if ( !$sPassword ) {
00536 oxSession::setVar( 'usr', $oUser->getId() );
00537 $this->_afterLogin( $oUser );
00538 } elseif ( $this->login() == 'user' ) {
00539 return false;
00540 }
00541
00542
00543
00544 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00545 if ( $sOrderRemark ) {
00546 oxSession::setVar( 'ordrem', $sOrderRemark );
00547 }
00548 }
00549
00550
00551
00552 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00553 $oxEMail = oxNew( 'oxemail' );
00554 if ( $blActiveLogin ) {
00555 $oxEMail->sendRegisterConfirmEmail( $oUser );
00556 } else {
00557 $oxEMail->sendRegisterEmail( $oUser );
00558 }
00559 }
00560
00561
00562 $this->_blIsNewUser = true;
00563
00564 return 'payment';
00565 }
00566
00572 public function registerUser()
00573 {
00574
00575 if ( $blSetup = $this->_setupDelAddress() ) {
00576 return;
00577 }
00578
00579
00580 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00581 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00582 return 'register?success=1';
00583 } else {
00584 return 'register?success=1&newslettererror=4';
00585 }
00586 } else {
00587
00588 $this->logout();
00589 }
00590 }
00591
00605 protected function _changeUser_noRedirect( )
00606 {
00607 if (!$this->getSession()->checkSessionChallenge()) {
00608 return;
00609 }
00610
00611
00612 $oUser = $this->getUser();
00613 if ( !$oUser ) {
00614 return;
00615 }
00616
00617
00618 $aDelAdress = $this->_getDelAddressData();
00619
00620
00621 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00622
00623 $sUserName = $oUser->oxuser__oxusername->value;
00624 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00625
00626 try {
00627 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00628
00629 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00630 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00631 }
00632 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00633
00634 } catch ( oxUserException $oEx ) {
00635
00636
00637 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00638 return;
00639 } catch(oxInputException $oEx) {
00640 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00641 return;
00642 } catch(oxConnectionException $oEx){
00643
00644 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00645 return;
00646 }
00647
00648
00649
00650 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00651 if ( $sOrderRemark ) {
00652 oxSession::setVar( 'ordrem', $sOrderRemark );
00653 }
00654
00655 if ( $oBasket = $this->getSession()->getBasket() ) {
00656 $oBasket->onUpdate();
00657 }
00658 return true;
00659 }
00660
00667 protected function _getDelAddressData()
00668 {
00669
00670 $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $this->_aRawShippingFields );
00671
00672 if ( is_array( $aDeladr ) ) {
00673
00674 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00675 unset( $aDeladr['oxaddress__oxsal'] );
00676 }
00677 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00678
00679 $aDelAdress = array();
00680 }
00681 }
00682 return $aDelAdress;
00683 }
00684
00690 protected function _getLogoutLink()
00691 {
00692 $myConfig = $this->getConfig();
00693 $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00694 if ( $myConfig->isSsl() ) {
00695 $sLogoutLink = $myConfig->getShopHomeUrl();
00696 }
00697 $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->getParent()->getDynUrlParams();
00698 if ( $sParam = oxConfig::getParameter('anid') ) {
00699 $sLogoutLink .= '&anid='.$sParam;
00700 }
00701 if ( $sParam = oxConfig::getParameter('cnid') ) {
00702 $sLogoutLink .= '&cnid='.$sParam;
00703 }
00704 if ( $sParam = oxConfig::getParameter('mnid') ) {
00705 $sLogoutLink .= '&mnid='.$sParam;
00706 }
00707 if ( $sParam = oxConfig::getParameter('tpl') ) {
00708 $sLogoutLink .= '&tpl='.$sParam;
00709 }
00710 return $sLogoutLink.'&fnc=logout';
00711 }
00712
00722 protected function _setupDelAddress()
00723 {
00724 $blShowIt = false;
00725 $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00726
00727
00728 if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00729 $blShowShipAddress = 0;
00730 $blShowIt = true;
00731 } else {
00732
00733 $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00734
00735 if ( $blShowAddress != $blSessShowAddress ) {
00736 $blShowShipAddress = 1;
00737 $blShowIt = true;
00738 }
00739 }
00740
00741 oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00742 if ($this->getParent()) {
00743 $this->getParent()->addTplParam( 'blshowshipaddress', $blShowShipAddress );
00744 }
00745
00746 return $blShowIt;
00747 }
00748
00755 public function loginOid()
00756 {
00757 if (!$this->getViewConfig()->getShowOpenIdLogin()) {
00758 return;
00759 }
00760 $this->setLoginStatus( USER_LOGIN_FAIL );
00761
00762 $iOldErrorReproting = error_reporting();
00763
00764 error_reporting($iOldErrorReproting & ~E_STRICT);
00765 try {
00766 $oOpenId = $this->getOpenId();
00767 $aData = $oOpenId->getOidResponse( $this->_getReturnUrl() );
00768 } catch ( oxUserException $oEx ) {
00769
00770 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00771 }
00772 error_reporting($iOldErrorReproting);
00773 if ( count( $aData ) < 1 ) {
00774 oxUtils::getInstance()->redirect($this->getConfig()->getShopHomeURL().'cl=register');
00775 }
00776 if ( $aData['email'] ) {
00777 $oUser = oxNew( 'oxuser' );
00778 $oUser->oxuser__oxusername = new oxField($aData['email'], oxField::T_RAW);
00779
00780
00781 if ( !$oUser->exists() ) {
00782 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00783 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00784 $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
00785 $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00786 list ($sFName, $sLName) = explode(' ', $aData['fullname']);
00787 $oUser->oxuser__oxfname = new oxField($sFName, oxField::T_RAW);
00788 $oUser->oxuser__oxlname = new oxField($sLName, oxField::T_RAW);
00789
00790 $oUser->oxuser__oxsal = new oxField($this->_getUserTitle($aData['gender']), oxField::T_RAW);
00791 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00792 if ( $sCountryId = $oUser->getUserCountryId( $aData['country'] ) ) {
00793 $oUser->oxuser__oxcountryid = new oxField( $sCountryId, oxField::T_RAW );
00794 }
00795 if ( $aData['postcode'] ) {
00796 $oUser->oxuser__oxzip = new oxField( $aData['postcode'], oxField::T_RAW );
00797 }
00798 $oUser->save();
00799 } else {
00800 $oUser->load( $oUser->getId() );
00801
00802 if ( $oUser->oxuser__oxisopenid->value == 0 ) {
00803 if ( !$oUser->oxuser__oxpassword->value ) {
00804 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00805 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00806 } else {
00807 $oUser->oxuser__oxisopenid = new oxField(2, oxField::T_RAW);
00808 }
00809 $oUser->save();
00810 }
00811 }
00812
00813 try {
00814 $oUser->openIdLogin( $oUser->oxuser__oxusername->value );
00815 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00816 } catch ( oxUserException $oEx ) {
00817
00818 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00819 }
00820
00821
00822 $this->_afterLogin( $oUser );
00823 $this->getParent()->setFncName( null );
00824 oxUtils::getInstance()->redirect($this->getParent()->getLink());
00825 }
00826 }
00827
00835 protected function _getUserTitle( $sGender )
00836 {
00837 if ( $sGender == "F" ) {
00838 return 'MRS';
00839 } else {
00840 return 'MR';
00841 }
00842 }
00843
00849 protected function _getReturnUrl()
00850 {
00851 $this->getParent()->setFncName( 'loginOid' );
00852 $sReturnUrl = str_replace( '&', '&', $this->getParent()->getLink() );
00853 if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00854 if ( strpos( $sReturnUrl, '?' ) ) {
00855 $sReturnUrl = $sReturnUrl . "&fnc=loginOid";
00856 } else {
00857 $sReturnUrl = $sReturnUrl . "?fnc=loginOid";
00858 }
00859 }
00860 return $sReturnUrl;
00861 }
00862
00870 public function setLoginStatus( $iStatus )
00871 {
00872 $this->_iLoginStatus = $iStatus;
00873 }
00874
00883 public function getLoginStatus()
00884 {
00885 return $this->_iLoginStatus;
00886 }
00887
00893 public function getOpenId()
00894 {
00895 return oxNew( "oxOpenID" );
00896 }
00897
00903 public function getInvitor()
00904 {
00905 $sSu = oxSession::getVar( 'su' );
00906 if ( !$sSu && ( $sSuNew = oxConfig::getParameter( 'su' ) ) ) {
00907 oxSession::setVar( 'su', $sSuNew );
00908 }
00909 }
00910 }