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
00051 public function init()
00052 {
00053
00054 $this->_loadSessionUser();
00055
00056 parent::init();
00057 }
00058
00071 public function render()
00072 {
00073 parent::render();
00074
00075
00076
00077 if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00078 oxSession::setVar( 'dgr', $sDynGoup );
00079 }
00080
00081 $oParentView = $this->getParent();
00082
00083
00084
00085
00086
00087
00088
00089 if ( $aInvAdress = oxConfig::getParameter( 'invadr') ) {
00090 $oParentView->addTplParam( 'invadr', $aInvAdress );
00091 }
00092
00093 if ( ( $aDelAdress = oxConfig::getParameter( 'deladr') ) && !oxConfig::getParameter( 'reloadaddress' ) ) {
00094 $oParentView->addTplParam( 'deladr', $aDelAdress );
00095 }
00096
00097 if ( $sUser = oxConfig::getParameter( 'lgn_usr' ) ) {
00098 $oParentView->addTplParam( 'lgn_usr', $sUser );
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 return $this->getUser();
00117 }
00118
00124 protected function _loadSessionUser()
00125 {
00126 $myConfig = $this->getConfig();
00127 $oUser = $this->getUser();
00128
00129
00130 if ( !$oUser ) {
00131 return;
00132 }
00133
00134
00135 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00136 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=content&tpl=user_blocked.tpl' );
00137 }
00138
00139
00140 if ( $oUser->isLoadedFromCookie() ) {
00141
00142
00143 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00144 $myConfig->setGlobalParameter( 'blUserChanged', 1 );
00145 }
00146
00147 if ( $oBasket = $this->getSession()->getBasket() ) {
00148 $oBasket->onUpdate();
00149 }
00150 }
00151 }
00152
00166 public function login()
00167 {
00168 $sUser = oxConfig::getParameter( 'lgn_usr' );
00169 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00170 $sCookie = oxConfig::getParameter( 'lgn_cook' );
00171 $sOpenId = oxConfig::getParameter( 'lgn_openid' );
00172
00173 $this->setLoginStatus( USER_LOGIN_FAIL );
00174
00175
00176 try {
00177 $oUser = oxNew( 'oxuser' );
00178 if ( $this->getViewConfig()->getShowOpenIdLogin() && $sOpenId ) {
00179 $iOldErrorReproting = error_reporting();
00180 error_reporting($iOldErrorReproting & ~E_STRICT);
00181 $oOpenId = oxNew( "oxOpenID" );
00182 $oOpenId->authenticateOid( $sOpenId, $this->_getReturnUrl() );
00183 error_reporting($iOldErrorReproting);
00184 } else {
00185 $oUser->login( $sUser, $sPassword, $sCookie );
00186 }
00187 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00188 } catch ( oxUserException $oEx ) {
00189
00190 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00191 return 'user';
00192 } catch( oxCookieException $oEx ){
00193 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00194 return 'user';
00195 }
00196
00197 return $this->_afterLogin( $oUser );
00198 }
00199
00217 protected function _afterLogin( $oUser )
00218 {
00219 $myConfig = $this->getConfig();
00220
00221
00222 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00223 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl' );
00224 }
00225
00226
00227 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00228
00229
00230 if ( $oBasket = $this->getSession()->getBasket() ) {
00231 $oBasket->onUpdate();
00232 }
00233
00234
00235 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00236 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00237 }
00238
00239
00240 return 'payment';
00241 }
00242
00249 public function login_noredirect()
00250 {
00251 $this->login();
00252 }
00253
00262 protected function _afterLogout()
00263 {
00264 oxSession::deleteVar( 'paymentid' );
00265 oxSession::deleteVar( 'sShipSet' );
00266 oxSession::deleteVar( 'deladrid' );
00267 oxSession::deleteVar( 'dynvalue' );
00268
00269
00270 if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00271 $oBasket->resetUserInfo();
00272 $oBasket->onUpdate();
00273 }
00274 }
00275
00284 public function logout()
00285 {
00286 $myConfig = $this->getConfig();
00287 $oUser = oxNew( 'oxuser' );
00288
00289 if ( $oUser->logout() ) {
00290
00291 $this->setLoginStatus( USER_LOGOUT );
00292
00293
00294 $this->_afterLogout();
00295
00296
00297
00298 if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00299
00300 oxUtils::getInstance()->redirect( $this->_getLogoutLink());
00301 }
00302 }
00303 }
00304
00314 public function changeUser( )
00315 {
00316
00317
00318 if ( $this->_setupDelAddress() ) {
00319 return;
00320 }
00321
00322 $blUserRegistered = $this->_changeUser_noRedirect( );
00323
00324 if ( $blUserRegistered === true ) {
00325 return 'payment';
00326 } else {
00327 return $blUserRegistered;
00328 }
00329 }
00330
00336 public function changeuser_testvalues()
00337 {
00338
00339
00340
00341 $this->_changeUser_noRedirect();
00342 }
00343
00365 public function createUser()
00366 {
00367
00368 if ( $blSetup = $this->_setupDelAddress() ) {
00369 return;
00370 }
00371
00372 $myConfig = $this->getConfig();
00373 $myUtils = oxUtils::getInstance();
00374
00375
00376 $sUser = oxConfig::getParameter( 'lgn_usr' );
00377
00378
00379 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00380
00381
00382 $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00383
00384 $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname', 'oxuser__oxcity');
00385 $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00386 $aDelAdress = $this->_getDelAddressData();
00387
00388 $oUser = oxNew( 'oxuser' );
00389
00390 try {
00391
00392 $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00393
00394
00395 $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00396 $oUser->setPassword( $sPassword );
00397 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00398
00399 $oUser->createUser();
00400 $oUser->load( $oUser->getId() );
00401 $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00402
00403
00404 $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00405 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00406
00407 $oUser->addToGroup( 'oxidnotyetordered' );
00408 $oUser->addDynGroup( oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ) );
00409 $oUser->logout();
00410
00411 } catch ( oxUserException $oEx ) {
00412 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00413 return false;
00414 } catch( oxInputException $oEx ){
00415 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00416 return false;
00417 } catch( oxConnectionException $oEx ){
00418 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00419 return false;
00420 }
00421
00422 if ( !$sPassword ) {
00423 oxSession::setVar( 'usr', $oUser->getId() );
00424 $this->_afterLogin( $oUser );
00425 } elseif ( $this->login() == 'user' ) {
00426 return false;
00427 }
00428
00429
00430
00431 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00432 if ( $sOrderRemark ) {
00433 oxSession::setVar( 'ordrem', $sOrderRemark );
00434 }
00435
00436
00437
00438 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00439 $oxEMail = oxNew( 'oxemail' );
00440 $oxEMail->sendRegisterEmail( $oUser );
00441 }
00442
00443
00444 $this->_blIsNewUser = true;
00445
00446 return 'payment';
00447 }
00448
00454 public function registerUser()
00455 {
00456
00457 if ( $blSetup = $this->_setupDelAddress() ) {
00458 return;
00459 }
00460
00461
00462 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00463 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00464 return 'register?success=1';
00465 } else {
00466 return 'register?success=1&newslettererror=4';
00467 }
00468 } else {
00469
00470 $this->logout();
00471 }
00472 }
00473
00487 protected function _changeUser_noRedirect( )
00488 {
00489 if (!$this->getSession()->checkSessionChallenge()) {
00490 return;
00491 }
00492
00493
00494 $oUser = $this->getUser();
00495 if ( !$oUser ) {
00496 return;
00497 }
00498
00499
00500 $aDelAdress = $this->_getDelAddressData();
00501
00502 $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname',
00503 'oxuser__oxlname', 'oxuser__oxstreet', 'oxuser__oxstreetnr',
00504 'oxuser__oxcity', 'oxuser__oxfon', 'oxuser__oxfax',
00505 'oxuser__oxmobfon', 'oxuser__oxprivfon');
00506
00507 $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00508
00509 $sUserName = $oUser->oxuser__oxusername->value;
00510 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00511
00512 try {
00513 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00514
00515 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00516 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00517 }
00518 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00519
00520 } catch ( oxUserException $oEx ) {
00521
00522
00523 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00524 return;
00525 } catch(oxInputException $oEx) {
00526 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00527 return;
00528 } catch(oxConnectionException $oEx){
00529
00530 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00531 return;
00532 }
00533
00534
00535
00536 $sOrderRemark = oxConfig::getParameter( 'order_remark', true );
00537 if ( $sOrderRemark ) {
00538 oxSession::setVar( 'ordrem', $sOrderRemark );
00539 }
00540
00541 if ( $oBasket = $this->getSession()->getBasket() ) {
00542 $oBasket->onUpdate();
00543 }
00544 return true;
00545 }
00546
00553 protected function _getDelAddressData()
00554 {
00555
00556 $aRawVal = array('oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxaddress__oxfname',
00557 'oxaddress__oxlname', 'oxaddress__oxcity', 'oxaddress__oxstreet',
00558 'oxaddress__oxstreetnr', 'oxaddress__oxzip', 'oxaddress__oxfon',
00559 'oxaddress__oxfax');
00560
00561 $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $aRawVal );
00562
00563 if ( is_array( $aDeladr ) ) {
00564
00565 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00566 unset( $aDeladr['oxaddress__oxsal'] );
00567 }
00568 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00569
00570 $aDelAdress = array();
00571 }
00572 }
00573 return $aDelAdress;
00574 }
00575
00581 protected function _getLogoutLink()
00582 {
00583 $myConfig = $this->getConfig();
00584 $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00585 if ( $myConfig->isSsl() ) {
00586 $sLogoutLink = $myConfig->getShopHomeUrl();
00587 }
00588 $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->getParent()->getDynUrlParams();
00589 if ( $sParam = oxConfig::getParameter('anid') ) {
00590 $sLogoutLink .= '&anid='.$sParam;
00591 }
00592 if ( $sParam = oxConfig::getParameter('cnid') ) {
00593 $sLogoutLink .= '&cnid='.$sParam;
00594 }
00595 if ( $sParam = oxConfig::getParameter('mnid') ) {
00596 $sLogoutLink .= '&mnid='.$sParam;
00597 }
00598 if ( $sParam = oxConfig::getParameter('tpl') ) {
00599 $sLogoutLink .= '&tpl='.$sParam;
00600 }
00601 return $sLogoutLink.'&fnc=logout';
00602 }
00603
00613 protected function _setupDelAddress()
00614 {
00615 $blShowIt = false;
00616 $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00617
00618
00619 if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00620 $blShowShipAddress = 0;
00621 $blShowIt = true;
00622
00623
00624 oxSession::deleteVar( 'deladdrid' );
00625 } else {
00626
00627 $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00628
00629 if ( $blShowAddress != $blSessShowAddress ) {
00630 $blShowShipAddress = 1;
00631 $blShowIt = true;
00632 }
00633 }
00634
00635 oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00636 if ($this->getParent()) {
00637 $this->getParent()->addTplParam( 'blshowshipaddress', $blShowShipAddress );
00638 }
00639
00640 return $blShowIt;
00641 }
00642
00649 public function loginOid()
00650 {
00651 if (!$this->getViewConfig()->getShowOpenIdLogin()) {
00652 return;
00653 }
00654 $this->setLoginStatus( USER_LOGIN_FAIL );
00655
00656 $iOldErrorReproting = error_reporting();
00657
00658 error_reporting($iOldErrorReproting & ~E_STRICT);
00659 try {
00660 $oOpenId = $this->getOpenId();
00661 $aData = $oOpenId->getOidResponse( $this->_getReturnUrl() );
00662 } catch ( oxUserException $oEx ) {
00663
00664 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00665 }
00666 error_reporting($iOldErrorReproting);
00667 if ( count( $aData ) < 1 ) {
00668 oxUtils::getInstance()->redirect($this->getConfig()->getShopHomeURL().'cl=register');
00669 }
00670 if ( $aData['email'] ) {
00671 $oUser = oxNew( 'oxuser' );
00672 $oUser->oxuser__oxusername = new oxField($aData['email'], oxField::T_RAW);
00673
00674
00675 if ( !$oUser->exists() ) {
00676 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00677 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00678 $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
00679 $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00680 list ($sFName, $sLName) = explode(' ', $aData['fullname']);
00681 $oUser->oxuser__oxfname = new oxField($sFName, oxField::T_RAW);
00682 $oUser->oxuser__oxlname = new oxField($sLName, oxField::T_RAW);
00683
00684 $oUser->oxuser__oxsal = new oxField($this->_getUserTitle($aData['gender']), oxField::T_RAW);
00685 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00686 if ( $sCountryId = $oUser->getUserCountryId( $aData['country'] ) ) {
00687 $oUser->oxuser__oxcountryid = new oxField( $sCountryId, oxField::T_RAW );
00688 }
00689 if ( $aData['postcode'] ) {
00690 $oUser->oxuser__oxzip = new oxField( $aData['postcode'], oxField::T_RAW );
00691 }
00692 $oUser->save();
00693 } else {
00694 $oUser->load( $oUser->getId() );
00695
00696 if ( $oUser->oxuser__oxisopenid->value == 0 ) {
00697 if ( !$oUser->oxuser__oxpassword->value ) {
00698 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00699 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00700 } else {
00701 $oUser->oxuser__oxisopenid = new oxField(2, oxField::T_RAW);
00702 }
00703 $oUser->save();
00704 }
00705 }
00706
00707 try {
00708 $oUser->openIdLogin( $oUser->oxuser__oxusername->value );
00709 $this->setLoginStatus( USER_LOGIN_SUCCESS );
00710 } catch ( oxUserException $oEx ) {
00711
00712 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00713 }
00714
00715
00716 $this->_afterLogin( $oUser );
00717 $this->getParent()->setFncName( null );
00718 oxUtils::getInstance()->redirect($this->getParent()->getLink());
00719 }
00720 }
00721
00729 protected function _getUserTitle( $sGender )
00730 {
00731 if ( $sGender == "F" ) {
00732 return 'MRS';
00733 } else {
00734 return 'MR';
00735 }
00736 }
00737
00743 protected function _getReturnUrl()
00744 {
00745 $this->getParent()->setFncName( 'loginOid' );
00746 $sReturnUrl = str_replace( '&', '&', $this->getParent()->getLink() );
00747 if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00748 if ( strpos( $sReturnUrl, '?' ) ) {
00749 $sReturnUrl = $sReturnUrl . "&fnc=loginOid";
00750 } else {
00751 $sReturnUrl = $sReturnUrl . "?fnc=loginOid";
00752 }
00753 }
00754 return $sReturnUrl;
00755 }
00756
00764 public function setLoginStatus( $iStatus )
00765 {
00766 $this->_iLoginStatus = $iStatus;
00767 }
00768
00777 public function getLoginStatus()
00778 {
00779 return $this->_iLoginStatus;
00780 }
00781
00787 public function getOpenId()
00788 {
00789 return oxNew( "oxOpenID" );
00790 }
00791 }