00001 <?php
00002
00008 class oxcmp_user extends oxView
00009 {
00014 protected $_blIsNewUser = false;
00015
00020 protected $_blIsComponent = true;
00021
00026 protected $_blNewsSubscriptionStatus = null;
00027
00037 public function init()
00038 {
00039
00040 $this->_loadSessionUser();
00041
00042 parent::init();
00043 }
00044
00057 public function render()
00058 {
00059 parent::render();
00060
00061
00062
00063 if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00064 oxSession::setVar( 'dgr', $sDynGoup );
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074 if ( $aInvAdress = oxConfig::getParameter( 'invadr') ) {
00075 $this->_oParent->addTplParam( 'invadr', $aInvAdress );
00076 }
00077
00078
00079 if ( $aDelAdress = oxConfig::getParameter( 'deladr') ) {
00080 $this->_oParent->addTplParam( 'deladr', $aDelAdress );
00081 }
00082
00083 if ( $sUser = oxConfig::getParameter( 'lgn_usr' ) ) {
00084 $this->_oParent->addTplParam( 'lgn_usr', $sUser );
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 return $this->getUser();
00103 }
00104
00110 protected function _loadSessionUser()
00111 {
00112 $myConfig = $this->getConfig();
00113 $oUser = $this->getUser();
00114
00115
00116 if ( !$oUser ) {
00117 return;
00118 }
00119
00120
00121 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00122 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=content&tpl=user_blocked.tpl' );
00123 }
00124
00125
00126 if ( $oUser->isLoadedFromCookie() ) {
00127
00128
00129 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00130 $myConfig->setGlobalParameter( 'blUserChanged', 1 );
00131 }
00132
00133 if ( $oBasket = $this->getSession()->getBasket() ) {
00134 $oBasket->onUpdate();
00135 }
00136 }
00137 }
00138
00152 public function login()
00153 {
00154 $sUser = oxConfig::getParameter( 'lgn_usr' );
00155 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00156 $sCookie = oxConfig::getParameter( 'lgn_cook' );
00157 $sOpenId = oxConfig::getParameter( 'lgn_openid' );
00158
00159
00160 try {
00161 $oUser = oxNew( 'oxuser' );
00162 if ( $sOpenId ) {
00163 $iOldErrorReproting = error_reporting();
00164 error_reporting($iOldErrorReproting & ~E_STRICT);
00165 $oOpenId = oxNew( "oxOpenID" );
00166 $oOpenId->authenticateOid( $sOpenId, $this->_getReturnUrl() );
00167 error_reporting($iOldErrorReproting);
00168 } else {
00169 $oUser->login( $sUser, $sPassword, $sCookie );
00170 }
00171 } catch ( oxUserException $oEx ) {
00172
00173 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00174 return 'user';
00175 } catch( oxCookieException $oEx ){
00176 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00177 return 'user';
00178 }
00179
00180 $this->_afterLogin( $oUser );
00181 }
00182
00200 protected function _afterLogin( $oUser )
00201 {
00202 $myConfig = $this->getConfig();
00203
00204
00205 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00206 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl' );
00207 }
00208
00209
00210 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00211
00212
00213 if ( $oBasket = $this->getSession()->getBasket() ) {
00214 $oBasket->onUpdate();
00215 }
00216
00217
00218 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00219 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00220 }
00221
00222
00223 return 'payment';
00224 }
00225
00232 public function login_noredirect()
00233 {
00234 $this->login();
00235 }
00236
00245 protected function _afterLogout()
00246 {
00247 oxSession::deleteVar( 'paymentid' );
00248 oxSession::deleteVar( 'sShipSet' );
00249 oxSession::deleteVar( 'deladrid' );
00250 oxSession::deleteVar( 'dynvalue' );
00251
00252
00253 if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00254 $oBasket->resetUserInfo();
00255 $oBasket->onUpdate();
00256 }
00257 }
00258
00267 public function logout()
00268 {
00269 $myConfig = $this->getConfig();
00270 $oUser = oxNew( 'oxuser' );
00271
00272 if ( $oUser->logout() ) {
00273
00274
00275 $this->_afterLogout();
00276
00277
00278
00279 if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00280
00281 oxUtils::getInstance()->redirect( $this->_getLogoutLink());
00282 }
00283 }
00284 }
00285
00295 public function changeUser( )
00296 {
00297
00298 if ( $this->_setupDelAddress() ) {
00299 return;
00300 }
00301
00302 $blUserRegistered = $this->_changeUser_noRedirect( );
00303
00304 if ( $blUserRegistered === true ) {
00305 return 'payment';
00306 } else {
00307 return $blUserRegistered;
00308 }
00309 }
00310
00316 public function changeuser_testvalues()
00317 {
00318 $this->_changeUser_noRedirect();
00319 }
00320
00342 public function createUser()
00343 {
00344
00345 if ( $blSetup = $this->_setupDelAddress() ) {
00346 return;
00347 }
00348
00349 $myConfig = $this->getConfig();
00350 $myUtils = oxUtils::getInstance();
00351
00352
00353 $sUser = oxConfig::getParameter( 'lgn_usr' );
00354
00355
00356 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00357
00358
00359 $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00360
00361 $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname', 'oxuser__oxcity');
00362 $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00363 $aDelAdress = $this->_getDelAddressData();
00364
00365 $oUser = oxNew( 'oxuser' );
00366
00367 try {
00368
00369 $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00370
00371
00372 $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00373 $oUser->setPassword( $sPassword );
00374 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00375
00376 $oUser->createUser();
00377 $oUser->load( $oUser->getId() );
00378 $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00379
00380
00381 $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00382 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, true );
00383
00384 $oUser->logout();
00385
00386 } catch ( oxUserException $oEx ) {
00387 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00388 return false;
00389 } catch( oxInputException $oEx ){
00390 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00391 return false;
00392 } catch( oxConnectionException $oEx ){
00393 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00394 return false;
00395 }
00396
00397 if ( !$sPassword ) {
00398 oxSession::setVar( 'usr', $oUser->getId() );
00399 $this->_afterLogin( $oUser );
00400 } elseif ( $this->login() == 'user' ) {
00401 return false;
00402 }
00403
00404
00405
00406 $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00407 if ( $sOrd_Remark ) {
00408 oxSession::setVar( 'ordrem', $sOrd_Remark );
00409 }
00410
00411
00412
00413 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00414 $oxEMail = oxNew( 'oxemail' );
00415 $oxEMail->sendRegisterEmail( $oUser );
00416 }
00417
00418
00419 $this->_blIsNewUser = true;
00420
00421 return 'payment';
00422 }
00423
00429 public function registerUser()
00430 {
00431
00432 if ( $blSetup = $this->_setupDelAddress() ) {
00433 return;
00434 }
00435
00436
00437 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00438
00439 $this->getUser()->addToGroup( 'oxidnotyetordered' );
00440
00441 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00442 return 'register?success=1';
00443 } else {
00444 return 'register?success=1&newslettererror=4';
00445 }
00446 } else {
00447 $this->logout();
00448 }
00449 }
00450
00464 protected function _changeUser_noRedirect( )
00465 {
00466
00467 $oUser = $this->getUser();
00468 if ( !$oUser ) {
00469 return;
00470 }
00471
00472
00473 $aDelAdress = $this->_getDelAddressData();
00474
00475 $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname',
00476 'oxuser__oxlname', 'oxuser__oxstreet', 'oxuser__oxstreetnr',
00477 'oxuser__oxcity', 'oxuser__oxfon', 'oxuser__oxfax',
00478 'oxuser__oxmobfon', 'oxuser__oxprivfon');
00479
00480 $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00481
00482 $sUserName = $oUser->oxuser__oxusername->value;
00483 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00484
00485 try {
00486 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00487
00488 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00489 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00490 }
00491 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00492
00493 } catch ( oxUserException $oEx ) {
00494
00495
00496 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00497 return;
00498 } catch(oxInputException $oEx) {
00499 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00500 return;
00501 } catch(oxConnectionException $oEx){
00502
00503 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00504 return;
00505 }
00506
00507
00508
00509 $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00510 if ( $sOrd_Remark ) {
00511 oxSession::setVar( 'ordrem', $sOrd_Remark );
00512 }
00513
00514 if ( $oBasket = $this->getSession()->getBasket() ) {
00515 $oBasket->onUpdate();
00516 }
00517 return true;
00518 }
00519
00526 protected function _getDelAddressData()
00527 {
00528
00529 $aRawVal = array('oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxaddress__oxfname', 'oxaddress__oxlname', 'oxaddress__oxcity');
00530 $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $aRawVal );
00531
00532 if ( is_array( $aDeladr ) ) {
00533
00534 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00535 unset( $aDeladr['oxaddress__oxsal'] );
00536 }
00537 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00538
00539 $aDelAdress = array();
00540 }
00541 }
00542 return $aDelAdress;
00543 }
00544
00550 protected function _getLogoutLink()
00551 {
00552 $myConfig = $this->getConfig();
00553 $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00554 if ( $myConfig->isSsl() ) {
00555 $sLogoutLink = $myConfig->getShopHomeUrl();
00556 }
00557 $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->_oParent->getDynUrlParams();
00558 if ( $sParam = oxConfig::getParameter('anid') ) {
00559 $sLogoutLink .= '&anid='.$sParam;
00560 }
00561 if ( $sParam = oxConfig::getParameter('cnid') ) {
00562 $sLogoutLink .= '&cnid='.$sParam;
00563 }
00564 if ( $sParam = oxConfig::getParameter('mnid') ) {
00565 $sLogoutLink .= '&mnid='.$sParam;
00566 }
00567 if ( $sParam = oxConfig::getParameter('tpl') ) {
00568 $sLogoutLink .= '&tpl='.$sParam;
00569 }
00570 return $sLogoutLink.'&fnc=logout';
00571 }
00572
00582 protected function _setupDelAddress()
00583 {
00584 $blShowIt = false;
00585 $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00586
00587
00588 if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00589 $blShowShipAddress = 0;
00590 $blShowIt = true;
00591
00592
00593 oxSession::deleteVar( 'deladdrid' );
00594 } else {
00595
00596 $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00597
00598 if ( $blShowAddress != $blSessShowAddress ) {
00599 $blShowShipAddress = 1;
00600 $blShowIt = true;
00601 }
00602 }
00603
00604 oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00605 $this->_oParent->_aViewData['blshowshipaddress'] = $blShowShipAddress;
00606
00607 return $blShowIt;
00608 }
00609
00616 public function loginOid()
00617 {
00618 $iOldErrorReproting = error_reporting();
00619
00620 error_reporting($iOldErrorReproting & ~E_STRICT);
00621 try {
00622 $oOpenId = oxNew( "oxOpenID" );
00623 $aData = $oOpenId->getOidResponse( $this->_getReturnUrl() );
00624 } catch ( oxUserException $oEx ) {
00625
00626 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00627 }
00628 error_reporting($iOldErrorReproting);
00629 if ( count( $aData ) < 1 ) {
00630 oxUtils::getInstance()->redirect($this->getConfig()->getShopHomeURL().'cl=register');
00631 }
00632 if ( $aData['email'] ) {
00633 $oUser = oxNew( 'oxuser' );
00634 $oUser->oxuser__oxusername = new oxField($aData['email'], oxField::T_RAW);
00635
00636
00637 if ( !$oUser->exists() ) {
00638 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00639 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00640 $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
00641 $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00642 list ($sFName, $sLName) = explode(' ', $aData['fullname']);
00643 $oUser->oxuser__oxfname = new oxField($sFName, oxField::T_RAW);
00644 $oUser->oxuser__oxlname = new oxField($sLName, oxField::T_RAW);
00645
00646 $oUser->oxuser__oxsal = new oxField($this->_getUserTitle($aData['gender']), oxField::T_RAW);
00647 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00648 if ( $sCountryId = $oUser->getUserCountryId( $aData['country'] ) ) {
00649 $oUser->oxuser__oxcountryid = new oxField( $sCountryId, oxField::T_RAW );
00650 }
00651 if ( $aData['postcode'] ) {
00652 $oUser->oxuser__oxzip = new oxField( $aData['postcode'], oxField::T_RAW );
00653 }
00654 $oUser->save();
00655 } else {
00656 $oUser->load( $oUser->getId() );
00657
00658 if ( $oUser->oxuser__oxisopenid->value == 0 ) {
00659 if ( !$oUser->oxuser__oxpassword->value ) {
00660 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00661 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00662 } else {
00663 $oUser->oxuser__oxisopenid = new oxField(2, oxField::T_RAW);
00664 }
00665 $oUser->save();
00666 }
00667 }
00668
00669 try {
00670 $oUser->openIdLogin( $oUser->oxuser__oxusername->value );
00671 } catch ( oxUserException $oEx ) {
00672
00673 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00674 }
00675
00676
00677 $this->_afterLogin( $oUser );
00678 $this->getParent()->setFncName( null );
00679 oxUtils::getInstance()->redirect($this->getParent()->getLink());
00680 }
00681 }
00682
00690 protected function _getUserTitle( $sGender )
00691 {
00692 if ( $sGender == "F" ) {
00693 return oxLang::getInstance()->translateString( "ACCOUNT_USER_MRS" );
00694 } else {
00695 return oxLang::getInstance()->translateString( "ACCOUNT_USER_MR" );
00696 }
00697 }
00698
00704 protected function _getReturnUrl()
00705 {
00706 $this->getParent()->setFncName( 'loginOid' );
00707 $sReturnUrl = str_replace( '&', '&', $this->getParent()->getLink() );
00708 if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00709 if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00710 $sReturnUrl = $sReturnUrl . "&fnc=loginOid";
00711 } else {
00712 $sReturnUrl = $sReturnUrl . "?fnc=loginOid";
00713 }
00714 }
00715 return $sReturnUrl;
00716 }
00717
00718 }