oxcmp_user.php

Go to the documentation of this file.
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         // load session user
00040         $this->_loadSessionUser();
00041 
00042         parent::init();
00043     }
00044 
00057     public function render()
00058     {
00059         parent::render();
00060 
00061         // dyn_group feature: if you specify a groupid in URL the user
00062         // will automatically be added to this group later
00063         if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00064             oxSession::setVar( 'dgr', $sDynGoup );
00065         }
00066 
00067         if ( $blNewsReg = oxConfig::getParameter( 'blnewssubscribed' )) {
00068             $this->_oParent->setNewsSubscribed( $blNewsReg );
00069             // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00070             $this->_oParent->addTplParam( 'blnewssubscribed', $this->_oParent->isNewsSubscribed() );
00071         }
00072 
00073         if ( $aInvAdress = oxConfig::getParameter( 'invadr') ) {
00074             $this->_oParent->addTplParam( 'invadr', $aInvAdress );
00075         }
00076 
00077         if ( $aDelAdress = oxConfig::getParameter( 'deladr') ) {
00078             $this->_oParent->addTplParam( 'deladr', $aDelAdress );
00079         }
00080 
00081         if ( $sUser = oxConfig::getParameter( 'lgn_usr' ) ) {
00082             $this->_oParent->addTplParam( 'lgn_usr', $sUser );
00083         }
00084 
00085         if ( $aDelAdressID = oxConfig::getParameter( 'deladrid' ) ) {
00086             $oAddress = oxNew( 'oxbase' );
00087             $oAddress->init( 'oxaddress' );
00088             $oAddress->load( $aDelAdressID );
00089             $this->_oParent->setDelAddress( $oAddress );
00090             $this->_oParent->addTplParam( 'delivadr', $this->_oParent->getDelAddress() );
00091         }
00092 
00093         // clicked on show address ?
00094         if ( $blShowAddress = oxSession::getVar( 'blshowshipaddress' ) ) {
00095             $this->_oParent->setShowShipAddress( 1 );
00096             // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00097             $this->_oParent->addTplParam( 'blshowshipaddress', 1 );
00098         }
00099 
00100         return $this->getUser();
00101     }
00102 
00108     public function _loadSessionUser()
00109     {
00110         $myConfig = $this->getConfig();
00111         $oUser = $this->getUser();
00112 
00113         // no session user
00114         if ( !$oUser ) {
00115             return;
00116         }
00117 
00118         // this user is blocked, deny him
00119         if ( $oUser->inGroup( 'oxidblocked' ) ) {
00120             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=info&tpl=user_blocked.tpl' );
00121         }
00122 
00123         // TODO: we need todo something with this !!!
00124         if ( $oUser->isLoadedFromCookie() ) {
00125 
00126                 // #1678 R
00127                 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00128                     $myConfig->setGlobalParameter( 'blUserChanged', 1 );
00129                 }
00130 
00131             if ( $oBasket = $this->getSession()->getBasket() ) {
00132                 $oBasket->onUpdate();
00133             }
00134         }
00135     }
00136 
00150     public function login()
00151     {
00152         $sUser     = oxConfig::getParameter( 'lgn_usr' );
00153         $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00154         $sCookie   = oxConfig::getParameter( 'lgn_cook' );
00155         $sOpenId   = oxConfig::getParameter( 'lgn_openid' );
00156 
00157         // trying to login user
00158         try {
00159             $oUser = oxNew( 'oxuser' );
00160             if ( $sOpenId ) {
00161                 $iOldErrorReproting = error_reporting();
00162                 error_reporting($iOldErrorReproting & ~E_STRICT);
00163                 $oOpenId = oxNew( "oxOpenID" );
00164                 $oOpenId->authenticateOid( $sOpenId, $this->_getReturnUrl() );
00165                 error_reporting($iOldErrorReproting);
00166             } else {
00167                 $oUser->login( $sUser, $sPassword, $sCookie );
00168             }
00169         } catch ( oxUserException $oEx ) {
00170             // for login component send excpetion text to a custom component (if defined)
00171             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00172             return 'user';
00173         } catch( oxCookieException $oEx ){
00174             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00175             return 'user';
00176         } catch( oxConnectionException $oEx ){
00177             //connection to external resource broken, change message and pass to the view
00178             $oEx->setMessage( 'EXCEPTION_ACTIONNOTPOSSIBLEATTHEMOMENT' );
00179             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00180             return 'user';
00181         }
00182         // finalizing ..
00183         $this->_afterLogin( $oUser );
00184     }
00185 
00203     protected function _afterLogin( $oUser )
00204     {
00205         $myConfig = $this->getConfig();
00206 
00207         // this user is blocked, deny him
00208         if ( $oUser->inGroup( 'oxidblocked' ) ) {
00209             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=info&tpl=user_blocked.tpl' );
00210         }
00211 
00212         // adding to dyn group
00213         $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00214 
00215         // recalc basket
00216         if ( $oBasket = $this->getSession()->getBasket() ) {
00217             $oBasket->onUpdate();
00218         }
00219 
00220             // #1678 R
00221             if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00222                 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00223             }
00224 
00225 
00226         return 'payment';
00227     }
00228 
00235     public function login_noredirect()
00236     {
00237         $this->login();
00238     }
00239 
00248     protected function _afterLogout()
00249     {
00250         oxSession::deleteVar( 'paymentid' );
00251         oxSession::deleteVar( 'sShipSet' );
00252         oxSession::deleteVar( 'deladrid' );
00253         oxSession::deleteVar( 'dynvalue' );
00254 
00255         // resetting & recalc basket
00256         if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00257             $oBasket->resetUserInfo();
00258             $oBasket->onUpdate();
00259         }
00260     }
00261 
00270     public function logout()
00271     {
00272         $myConfig  = $this->getConfig();
00273         $oUser = oxNew( 'oxuser' );
00274 
00275         if ( $oUser->logout() ) {
00276 
00277             // finalizing ..
00278             $this->_afterLogout();
00279 
00280 
00281             // redirecting if user logs out in SSL mode
00282             if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00283                 $sLogoutLink = $myConfig->getShopSecureHomeURL();
00284                 if ( $myConfig->isSsl() ) {
00285                     $sLogoutLink = $myConfig->getShopHomeURL();
00286                 }
00287                 oxUtils::getInstance()->redirect( $sLogoutLink.'cl='.oxConfig::getParameter('cl').'&amp;cnid='.oxConfig::getParameter('cnid').'&amp;fnc=logout&amp;tpl='.oxConfig::getParameter('tpl') );
00288             }
00289         }
00290     }
00291 
00301     public function changeUser( )
00302     {
00303         // checking if "open address area" button was clicked
00304         if ( $blSetup = $this->_setupDelAddress() ) {
00305             return;
00306         }
00307 
00308         $blUserRegistered = $this->_changeUser_noRedirect( );
00309 
00310         if ( $blUserRegistered === true ) {
00311             return 'payment';
00312         } else {
00313             return $blUserRegistered;
00314         }
00315     }
00316 
00322     public function changeuser_testvalues()
00323     {
00324         $this->_changeUser_noRedirect();
00325     }
00326 
00348     public function createUser()
00349     {
00350         // checking if "open address area" button was clicked
00351         if ( $blSetup = $this->_setupDelAddress() ) {
00352             return;
00353         }
00354 
00355         $myConfig = $this->getConfig();
00356         $myUtils  = oxUtils::getInstance();
00357 
00358         // collecting values to check
00359         $sUser = oxConfig::getParameter( 'lgn_usr' );
00360 
00361         // first pass
00362         $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00363 
00364         // second pass
00365         $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00366 
00367         $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00368         $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00369         $aDelAdress = $this->_getDelAddressData();
00370 
00371         $oUser = oxNew( 'oxuser' );
00372 
00373         try {
00374 
00375             $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00376 
00377             // setting values
00378             $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00379             $oUser->setPassword( $sPassword );
00380             $oUser->oxuser__oxactive   = new oxField(1, oxField::T_RAW);
00381 
00382             $oUser->createUser();
00383             $oUser->load( $oUser->getId() );
00384             $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00385 
00386             // assigning to newsletter
00387             $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00388             $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, true );
00389 
00390             $oUser->logout();
00391 
00392         } catch ( oxUserException $oEx ) {
00393             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00394             return false;
00395         } catch( oxInputException $oEx ){
00396             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00397             return false;
00398         } catch( oxConnectionException $oEx ){
00399             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00400             return false;
00401         }
00402 
00403         if ( !$sPassword ) {
00404             oxSession::setVar( 'usr', $oUser->getId() );
00405             $this->_afterLogin( $oUser );
00406         } elseif ( $this->login() == 'user' ) {
00407             return false;
00408         }
00409 
00410         // order remark
00411         //V #427: order remark for new users 
00412         $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00413         if ( $sOrd_Remark ) {
00414             oxSession::setVar( 'ordrem', $sOrd_Remark );
00415         }
00416 
00417         // send register eMail
00418         //TODO: move into user
00419         if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00420             $oxEMail = oxNew( 'oxemail' );
00421             $oxEMail->sendRegisterEmail( $oUser );
00422         }
00423 
00424         // new registered
00425         $this->_blIsNewUser = true;
00426 
00427         return 'payment';
00428     }
00429 
00435     public function registerUser()
00436     {
00437         // checking if "open address area" button was clicked
00438         if ( $blSetup = $this->_setupDelAddress() ) {
00439             return;
00440         }
00441 
00442         // registered new user ?
00443         if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00444                 // #1672 R
00445                 $this->getUser()->addToGroup( 'oxidnotyetordered' );
00446 
00447             if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00448                 return 'register?success=1';
00449             } else {
00450                 return 'register?success=1&newslettererror=4';
00451             }
00452         } else { // problems with registration ...
00453             $this->logout();
00454         }
00455     }
00456 
00470     protected function _changeUser_noRedirect( )
00471     {
00472         // no user ?
00473         $oUser = $this->getUser();
00474         if ( !$oUser ) {
00475             return;
00476         }
00477 
00478         // collecting values to check
00479         $aDelAdress = $this->_getDelAddressData();
00480         // if user company name, user name and additional info has special chars
00481         $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00482         $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00483 
00484         $sUserName  = $oUser->oxuser__oxusername->value;
00485         $sPassword  = $sPassword2 = $oUser->oxuser__oxpassword->value;
00486 
00487         try { // testing user input
00488             $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00489             // assigning to newsletter
00490             if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00491                 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00492             }
00493             $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, oxConfig::getInstance()->getConfigParam( 'blOrderOptInEmail' ) );
00494 
00495         } catch ( oxUserException $oEx ) { // errors in input
00496             // marking error code
00497             //TODO
00498             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00499             return;
00500         } catch(oxInputException $oEx) {
00501             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00502             return;
00503         } catch(oxConnectionException $oEx){
00504              //connection to external resource broken, change message and pass to the view
00505             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00506             return;
00507         }
00508 
00509 
00510         // order remark
00511         $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00512         if ( $sOrd_Remark ) {
00513             oxSession::setVar( 'ordrem', $sOrd_Remark );
00514         }
00515 
00516         if ( $oBasket = $this->getSession()->getBasket() ) {
00517             $oBasket->onUpdate();
00518         }
00519         return true;
00520     }
00521 
00528     protected function _getDelAddressData()
00529     {
00530         // if user company name, user name and additional info has special chars
00531         $aRawVal = array('oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00532         $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $aRawVal );
00533 
00534         if ( is_array( $aDeladr ) ) {
00535             // checking if data is filled
00536             if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00537                 unset( $aDeladr['oxaddress__oxsal'] );
00538             }
00539             if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00540                 // resetting to avoid empty records
00541                 $aDelAdress = array();
00542             }
00543         }
00544         return $aDelAdress;
00545     }
00546 
00556     protected function _setupDelAddress()
00557     {
00558         $blSetup = false;
00559         $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00560 
00561         // user clicked on button to hide
00562         if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00563             $blShowShipAddress = 0;
00564             $blSetup = true;
00565 
00566             // unsetting delivery address
00567             oxSession::deleteVar( 'deladdrid' );
00568         } else {
00569 
00570             $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00571             // user clicked on button to show
00572             if ( $blShowAddress != $blSessShowAddress ) {
00573                 $blShowShipAddress = 1;
00574                 $blSetup = true;
00575             }
00576         }
00577 
00578         oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00579         $this->_oParent->_aViewData['blshowshipaddress'] = $blShowShipAddress;
00580 
00581         return $blSetup;
00582     }
00583 
00590     public function loginOid()
00591     {
00592         $iOldErrorReproting = error_reporting();
00593         error_reporting($iOldErrorReproting & ~E_STRICT);
00594         try {
00595             $oOpenId = oxNew( "oxOpenID" );
00596             $aData = $oOpenId->getOidResponse( $this->_getReturnUrl() );
00597         } catch ( oxUserException $oEx ) {
00598                 // for login component send excpetion text to a custom component (if defined)
00599                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00600         }
00601         error_reporting($iOldErrorReproting);
00602         if ( $aData['email'] ) {
00603             $oUser = oxNew( 'oxuser' );
00604             $oUser->oxuser__oxusername = new oxField($aData['email'], oxField::T_RAW);
00605 
00606             // if such user does not exist - creating it
00607             if ( !$oUser->exists() ) {
00608                 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00609                 $oUser->oxuser__oxactive   = new oxField(1, oxField::T_RAW);
00610                 $oUser->oxuser__oxrights   = new oxField('user', oxField::T_RAW);
00611                 $oUser->oxuser__oxshopid   = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00612                 list ($sFName, $sLName)    = split(' ', $aData['fullname']);
00613                 $oUser->oxuser__oxfname    = new oxField($sFName, oxField::T_RAW);
00614                 $oUser->oxuser__oxlname    = new oxField($sLName, oxField::T_RAW);
00615                 
00616                 $oUser->oxuser__oxsal      = new oxField($this->_getUserTitle($aData['gender']), oxField::T_RAW);
00617                 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00618                 if ( $sCountryId = $oUser->getUserCountryId( $aData['country'] ) ) {
00619                     $oUser->oxuser__oxcountryid = new oxField( $sCountryId, oxField::T_RAW );
00620                 }
00621                 if ( $aData['postcode'] ) {
00622                     $oUser->oxuser__oxzip = new oxField( $aData['postcode'], oxField::T_RAW );
00623                 }
00624                 $oUser->save();
00625             } else {
00626                 $oUser->load( $oUser->getId() );
00627                 //if existing user loggins first time with openid
00628                 if ( $oUser->oxuser__oxisopenid->value == 0 ) {
00629                     if ( !$oUser->oxuser__oxpassword->value ) {
00630                         $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00631                         $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00632                     } else {
00633                         $oUser->oxuser__oxisopenid = new oxField(2, oxField::T_RAW);
00634                     }
00635                     $oUser->save();
00636                 }
00637             }
00638 
00639             try {
00640                 $oUser->openIdLogin( $oUser->oxuser__oxusername->value );
00641             } catch ( oxUserException $oEx ) {
00642                 // for login component send excpetion text to a custom component (if defined)
00643                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00644             } catch( oxConnectionException $oEx ) {
00645                 //connection to external resource broken, change message and pass to the view
00646                 $oEx->setMessage( 'EXCEPTION_ACTIONNOTPOSSIBLEATTHEMOMENT' );
00647                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00648             }
00649 
00650             // finalizing ..
00651             $this->_afterLogin( $oUser );
00652             $this->getParent()->setFncName( null );
00653             oxUtils::getInstance()->redirect($this->getParent()->getLink());
00654         }
00655     }
00656 
00664     protected function _getUserTitle( $sGender )
00665     {
00666         if ( $sGender == "F" ) {
00667             return oxLang::getInstance()->translateString( "ACCOUNT_USER_MRS" );
00668         } else {
00669             return oxLang::getInstance()->translateString( "ACCOUNT_USER_MR" );
00670         }
00671     }
00672 
00678     protected function _getReturnUrl()
00679     {
00680         $this->getParent()->setFncName( 'loginOid' );
00681         $sReturnUrl = str_replace( '&amp;', '&', $this->getParent()->getLink() );
00682         if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00683             if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00684                 $sReturnUrl = $sReturnUrl . "&fnc=loginOid";
00685             } else {
00686                 $sReturnUrl = $sReturnUrl . "?fnc=loginOid";
00687             }
00688         }
00689         return $sReturnUrl;
00690     }
00691 
00692 }

Generated on Thu Feb 19 15:02:22 2009 for OXID eShop CE by  doxygen 1.5.5