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 );
00059
00065 protected $_aRawBillingFields = array( 'oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname',
00066 'oxuser__oxlname', 'oxuser__oxstreet', 'oxuser__oxstreetnr',
00067 'oxuser__oxcity', 'oxuser__oxfon', 'oxuser__oxfax',
00068 'oxuser__oxmobfon', 'oxuser__oxprivfon' );
00069
00075 protected $_aRawShippingFields = array( 'oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxaddress__oxfname',
00076 'oxaddress__oxlname', 'oxaddress__oxcity', 'oxaddress__oxstreet',
00077 'oxaddress__oxstreetnr', 'oxaddress__oxzip', 'oxaddress__oxfon',
00078 'oxaddress__oxfax' );
00088 public function init()
00089 {
00090
00091 $this->_loadSessionUser();
00092
00093 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) ) {
00094
00095 $this->getInvitor();
00096 }
00097
00098 parent::init();
00099 }
00100
00113 public function render()
00114 {
00115
00116 $this->_checkPsState();
00117
00118 parent::render();
00119
00120
00121
00122 if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00123 oxSession::setVar( 'dgr', $sDynGoup );
00124 }
00125
00126 $oParentView = $this->getParent();
00127
00128
00129
00130
00131
00132
00133
00134 if ( $aInvAdress = oxConfig::getParameter( 'invadr') ) {
00135 $oParentView->addTplParam( 'invadr', $aInvAdress );
00136 }
00137
00138 if ( ( $aDelAdress = oxConfig::getParameter( 'deladr') ) && !oxConfig::getParameter( 'reloadaddress' ) ) {
00139 $oParentView->addTplParam( 'deladr', $aDelAdress );
00140 }
00141
00142 if ( $sUser = oxConfig::getParameter( 'lgn_usr' ) ) {
00143 $oParentView->addTplParam( 'lgn_usr', $sUser );
00144 }
00145
00146 return $this->getUser();
00147 }
00148
00159 protected function _checkPsState()
00160 {
00161 $oConfig = $this->getConfig();
00162 if ( $oConfig->getConfigParam( 'blPsLoginEnabled' ) ) {
00163
00164 $oUser = $this->getUser();
00165 $sClass = $this->getParent()->getClassName();
00166
00167
00168 if ( !$oUser && !in_array( $sClass, $this->_aAllowedClasses ) ) {
00169 oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account' );
00170 }
00171
00172 if ( $oUser && !$oUser->isTermsAccepted() &&
00173 $oConfig->getConfigParam( 'blConfirmAGB' ) &&
00174 !in_array( $sClass, $this->_aAllowedClasses ) ) {
00175 oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account&term=1' );
00176 }
00177 }
00178 }
00179
00185 protected function _loadSessionUser()
00186 {
00187 $myConfig = $this->getConfig();
00188 $oUser = $this->getUser();
00189
00190
00191 if ( !$oUser ) {
00192 return;
00193 }
00194
00195
00196 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00197 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=content&tpl=user_blocked.tpl' );
00198 }
00199
00200
00201 if ( $oUser->isLoadedFromCookie() ) {
00202
00203
00204 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00205 $myConfig->setGlobalParameter( 'blUserChanged', 1 );
00206 }
00207
00208 if ( $oBasket = $this->getSession()->getBasket() ) {
00209 $oBasket->onUpdate();
00210 }
00211 }
00212 }
00213
00227 public function login()
00228 {
00229 $sUser = oxConfig::getParameter( 'lgn_usr' );
00230 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00231 $sCookie = oxConfig::getParameter( 'lgn_cook' );
00232 $sOpenId = oxConfig::getParameter( 'lgn_openid' );
00233
00234
00235 $this->setLoginStatus( USER_LOGIN_FAIL );
00236
00237
00238 try {
00239 $oUser = oxNew( 'oxuser' );
00240 if ( $this->getViewConfig()->getShowOpenIdLogin() && $sOpenId ) {
00241 $iOldErrorReproting = error_reporting();
00242 error_reporting($iOldErrorReproting & ~E_STRICT);
00243 $oOpenId = oxNew( "oxOpenID" );
00244 $oOpenId->authenticateOid( $sOpenId, $this->_getReturnUrl() );
00245 error_reporting($iOldErrorReproting);
00246 } else {
00247 $oUser->login( $sUser, $sPassword, $sCookie );
00248 }
00249 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00250 } catch ( oxUserException $oEx ) {
00251
00252 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00253 return 'user';
00254 } catch( oxCookieException $oEx ){
00255 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00256 return 'user';
00257 }
00258
00259 return $this->_afterLogin( $oUser );
00260 }
00261
00279 protected function _afterLogin( $oUser )
00280 {
00281 $myConfig = $this->getConfig();
00282
00283
00284 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00285 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl' );
00286 }
00287
00288
00289 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00290
00291
00292 if ( $oBasket = $this->getSession()->getBasket() ) {
00293 $oBasket->onUpdate();
00294 }
00295
00296
00297 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00298 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00299 }
00300
00301
00302 return 'payment';
00303 }
00304
00311 public function login_noredirect()
00312 {
00313 if ( $this->getConfig()->getConfigParam( 'blPsLoginEnabled' ) && oxConfig::getParameter( 'ord_agb' ) &&
00314 $this->getConfig()->getConfigParam( 'blConfirmAGB' ) && ( $oUser = $this->getUser() ) ) {
00315 $oUser->acceptTerms();
00316 } else {
00317 $this->login();
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->getConfig()->getConfigParam( 'blPsLoginEnabled' ) ) {
00383 return 'account';
00384 }
00385
00386
00387 if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00388
00389 oxUtils::getInstance()->redirect( $this->_getLogoutLink());
00390 }
00391 }
00392 }
00393
00403 public function changeUser( )
00404 {
00405
00406
00407 if ( $this->_setupDelAddress() ) {
00408 return;
00409 }
00410
00411 $blUserRegistered = $this->_changeUser_noRedirect( );
00412
00413 if ( $blUserRegistered === true ) {
00414 return 'payment';
00415 } else {
00416 return $blUserRegistered;
00417 }
00418 }
00419
00425 public function changeuser_testvalues()
00426 {
00427
00428
00429
00430 $this->_changeUser_noRedirect();
00431 }
00432
00454 public function createUser()
00455 {
00456
00457 if ( $blSetup = $this->_setupDelAddress() ) {
00458 return;
00459 }
00460
00461 $blActiveLogin = $this->getConfig()->getConfigParam( 'blPsLoginEnabled' );
00462
00463 $myConfig = $this->getConfig();
00464 if ( $blActiveLogin && !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00465 oxUtilsView::getInstance()->addErrorToDisplay( 'ORDER_READANDCONFIRMTERMS', false, true );
00466 return;
00467 }
00468
00469 $myUtils = oxUtils::getInstance();
00470
00471
00472 $sUser = oxConfig::getParameter( 'lgn_usr' );
00473
00474
00475 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00476
00477
00478 $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00479
00480 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00481 $aDelAdress = $this->_getDelAddressData();
00482
00483 $oUser = oxNew( 'oxuser' );
00484
00485 try {
00486
00487 $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00488
00489 $iActState = $blActiveLogin ? 0 : 1;
00490
00491
00492 $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00493 $oUser->setPassword( $sPassword );
00494 $oUser->oxuser__oxactive = new oxField( $iActState, oxField::T_RAW);
00495
00496 $oUser->createUser();
00497 $oUser->load( $oUser->getId() );
00498 $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00499
00500 if ( $blActiveLogin ) {
00501
00502 $oUser->acceptTerms();
00503 }
00504
00505 if ( $this->getConfig()->getConfigParam( 'blInvitationsEnabled' ) && $sUserId = oxConfig::getParameter( "su" ) ) {
00506
00507 $oUser->setCreditPointsForRegistrant( $sUserId );
00508 }
00509
00510
00511 $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00512 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00513
00514 $oUser->addToGroup( 'oxidnotyetordered' );
00515 $oUser->addDynGroup( oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ) );
00516 $oUser->logout();
00517
00518 } catch ( oxUserException $oEx ) {
00519 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00520 return false;
00521 } catch( oxInputException $oEx ){
00522 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00523 return false;
00524 } catch( oxConnectionException $oEx ){
00525 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00526 return false;
00527 }
00528
00529 if ( !$blActiveLogin ) {
00530 if ( !$sPassword ) {
00531 oxSession::setVar( 'usr', $oUser->getId() );
00532 $this->_afterLogin( $oUser );
00533 } elseif ( $this->login() == 'user' ) {
00534 return false;
00535 }
00536
00537
00538
00539 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00540 if ( $sOrderRemark ) {
00541 oxSession::setVar( 'ordrem', $sOrderRemark );
00542 }
00543 }
00544
00545
00546
00547 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00548 $oxEMail = oxNew( 'oxemail' );
00549 if ( $blActiveLogin ) {
00550 $oxEMail->sendRegisterConfirmEmail( $oUser );
00551 } else {
00552 $oxEMail->sendRegisterEmail( $oUser );
00553 }
00554 }
00555
00556
00557 $this->_blIsNewUser = true;
00558
00559 return 'payment';
00560 }
00561
00567 public function registerUser()
00568 {
00569
00570 if ( $blSetup = $this->_setupDelAddress() ) {
00571 return;
00572 }
00573
00574
00575 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00576 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00577 return 'register?success=1';
00578 } else {
00579 return 'register?success=1&newslettererror=4';
00580 }
00581 } else {
00582
00583 $this->logout();
00584 }
00585 }
00586
00600 protected function _changeUser_noRedirect( )
00601 {
00602 if (!$this->getSession()->checkSessionChallenge()) {
00603 return;
00604 }
00605
00606
00607 $oUser = $this->getUser();
00608 if ( !$oUser ) {
00609 return;
00610 }
00611
00612
00613 $aDelAdress = $this->_getDelAddressData();
00614
00615
00616 $aInvAdress = oxConfig::getParameter( 'invadr', $this->_aRawBillingFields );
00617
00618 $sUserName = $oUser->oxuser__oxusername->value;
00619 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00620
00621 try {
00622 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00623
00624 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00625 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00626 }
00627 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00628
00629 } catch ( oxUserException $oEx ) {
00630
00631
00632 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00633 return;
00634 } catch(oxInputException $oEx) {
00635 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00636 return;
00637 } catch(oxConnectionException $oEx){
00638
00639 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00640 return;
00641 }
00642
00643
00644
00645 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00646 if ( $sOrderRemark ) {
00647 oxSession::setVar( 'ordrem', $sOrderRemark );
00648 }
00649
00650 if ( $oBasket = $this->getSession()->getBasket() ) {
00651 $oBasket->onUpdate();
00652 }
00653 return true;
00654 }
00655
00662 protected function _getDelAddressData()
00663 {
00664
00665 $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $this->_aRawShippingFields );
00666
00667 if ( is_array( $aDeladr ) ) {
00668
00669 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00670 unset( $aDeladr['oxaddress__oxsal'] );
00671 }
00672 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00673
00674 $aDelAdress = array();
00675 }
00676 }
00677 return $aDelAdress;
00678 }
00679
00685 protected function _getLogoutLink()
00686 {
00687 $myConfig = $this->getConfig();
00688 $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00689 if ( $myConfig->isSsl() ) {
00690 $sLogoutLink = $myConfig->getShopHomeUrl();
00691 }
00692 $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->getParent()->getDynUrlParams();
00693 if ( $sParam = oxConfig::getParameter('anid') ) {
00694 $sLogoutLink .= '&anid='.$sParam;
00695 }
00696 if ( $sParam = oxConfig::getParameter('cnid') ) {
00697 $sLogoutLink .= '&cnid='.$sParam;
00698 }
00699 if ( $sParam = oxConfig::getParameter('mnid') ) {
00700 $sLogoutLink .= '&mnid='.$sParam;
00701 }
00702 if ( $sParam = oxConfig::getParameter('tpl') ) {
00703 $sLogoutLink .= '&tpl='.$sParam;
00704 }
00705 return $sLogoutLink.'&fnc=logout';
00706 }
00707
00717 protected function _setupDelAddress()
00718 {
00719 $blShowIt = false;
00720 $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00721
00722
00723 if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00724 $blShowShipAddress = 0;
00725 $blShowIt = true;
00726 } else {
00727
00728 $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00729
00730 if ( $blShowAddress != $blSessShowAddress ) {
00731 $blShowShipAddress = 1;
00732 $blShowIt = true;
00733 }
00734 }
00735
00736 oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00737 if ($this->getParent()) {
00738 $this->getParent()->addTplParam( 'blshowshipaddress', $blShowShipAddress );
00739 }
00740
00741 return $blShowIt;
00742 }
00743
00750 public function loginOid()
00751 {
00752 if (!$this->getViewConfig()->getShowOpenIdLogin()) {
00753 return;
00754 }
00755 $this->setLoginStatus( USER_LOGIN_FAIL );
00756
00757 $iOldErrorReproting = error_reporting();
00758
00759 error_reporting($iOldErrorReproting & ~E_STRICT);
00760 try {
00761 $oOpenId = $this->getOpenId();
00762 $aData = $oOpenId->getOidResponse( $this->_getReturnUrl() );
00763 } catch ( oxUserException $oEx ) {
00764
00765 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00766 }
00767 error_reporting($iOldErrorReproting);
00768 if ( count( $aData ) < 1 ) {
00769 oxUtils::getInstance()->redirect($this->getConfig()->getShopHomeURL().'cl=register');
00770 }
00771 if ( $aData['email'] ) {
00772 $oUser = oxNew( 'oxuser' );
00773 $oUser->oxuser__oxusername = new oxField($aData['email'], oxField::T_RAW);
00774
00775
00776 if ( !$oUser->exists() ) {
00777 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00778 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00779 $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
00780 $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00781 list ($sFName, $sLName) = explode(' ', $aData['fullname']);
00782 $oUser->oxuser__oxfname = new oxField($sFName, oxField::T_RAW);
00783 $oUser->oxuser__oxlname = new oxField($sLName, oxField::T_RAW);
00784
00785 $oUser->oxuser__oxsal = new oxField($this->_getUserTitle($aData['gender']), oxField::T_RAW);
00786 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00787 if ( $sCountryId = $oUser->getUserCountryId( $aData['country'] ) ) {
00788 $oUser->oxuser__oxcountryid = new oxField( $sCountryId, oxField::T_RAW );
00789 }
00790 if ( $aData['postcode'] ) {
00791 $oUser->oxuser__oxzip = new oxField( $aData['postcode'], oxField::T_RAW );
00792 }
00793 $oUser->save();
00794 } else {
00795 $oUser->load( $oUser->getId() );
00796
00797 if ( $oUser->oxuser__oxisopenid->value == 0 ) {
00798 if ( !$oUser->oxuser__oxpassword->value ) {
00799 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00800 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00801 } else {
00802 $oUser->oxuser__oxisopenid = new oxField(2, oxField::T_RAW);
00803 }
00804 $oUser->save();
00805 }
00806 }
00807
00808 try {
00809 $oUser->openIdLogin( $oUser->oxuser__oxusername->value );
00810 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00811 } catch ( oxUserException $oEx ) {
00812
00813 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00814 }
00815
00816
00817 $this->_afterLogin( $oUser );
00818 $this->getParent()->setFncName( null );
00819 oxUtils::getInstance()->redirect($this->getParent()->getLink());
00820 }
00821 }
00822
00830 protected function _getUserTitle( $sGender )
00831 {
00832 if ( $sGender == "F" ) {
00833 return 'MRS';
00834 } else {
00835 return 'MR';
00836 }
00837 }
00838
00844 protected function _getReturnUrl()
00845 {
00846 $this->getParent()->setFncName( 'loginOid' );
00847 $sReturnUrl = str_replace( '&', '&', $this->getParent()->getLink() );
00848 if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00849 if ( strpos( $sReturnUrl, '?' ) ) {
00850 $sReturnUrl = $sReturnUrl . "&fnc=loginOid";
00851 } else {
00852 $sReturnUrl = $sReturnUrl . "?fnc=loginOid";
00853 }
00854 }
00855 return $sReturnUrl;
00856 }
00857
00865 public function setLoginStatus( $iStatus )
00866 {
00867 $this->_iLoginStatus = $iStatus;
00868 }
00869
00878 public function getLoginStatus()
00879 {
00880 return $this->_iLoginStatus;
00881 }
00882
00888 public function getOpenId()
00889 {
00890 return oxNew( "oxOpenID" );
00891 }
00892
00898 public function getInvitor()
00899 {
00900 $sSu = oxSession::getVar( 'su' );
00901 if ( !$sSu && ( $sSuNew = oxConfig::getParameter( 'su' ) ) ) {
00902 oxSession::setVar( 'su', $sSuNew );
00903 }
00904 }
00905 }