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     protected 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=content&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         }
00177         // finalizing ..
00178         $this->_afterLogin( $oUser );
00179     }
00180 
00198     protected function _afterLogin( $oUser )
00199     {
00200         $myConfig = $this->getConfig();
00201 
00202         // this user is blocked, deny him
00203         if ( $oUser->inGroup( 'oxidblocked' ) ) {
00204             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=content&tpl=user_blocked.tpl' );
00205         }
00206 
00207         // adding to dyn group
00208         $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00209 
00210         // recalc basket
00211         if ( $oBasket = $this->getSession()->getBasket() ) {
00212             $oBasket->onUpdate();
00213         }
00214 
00215             // #1678 R
00216             if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00217                 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00218             }
00219 
00220 
00221         return 'payment';
00222     }
00223 
00230     public function login_noredirect()
00231     {
00232         $this->login();
00233     }
00234 
00243     protected function _afterLogout()
00244     {
00245         oxSession::deleteVar( 'paymentid' );
00246         oxSession::deleteVar( 'sShipSet' );
00247         oxSession::deleteVar( 'deladrid' );
00248         oxSession::deleteVar( 'dynvalue' );
00249 
00250         // resetting & recalc basket
00251         if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00252             $oBasket->resetUserInfo();
00253             $oBasket->onUpdate();
00254         }
00255     }
00256 
00265     public function logout()
00266     {
00267         $myConfig  = $this->getConfig();
00268         $oUser = oxNew( 'oxuser' );
00269 
00270         if ( $oUser->logout() ) {
00271 
00272             // finalizing ..
00273             $this->_afterLogout();
00274 
00275 
00276             // redirecting if user logs out in SSL mode
00277             if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00278 
00279                 oxUtils::getInstance()->redirect( $this->_getLogoutLink());
00280             }
00281         }
00282     }
00283 
00293     public function changeUser( )
00294     {
00295         // checking if "open address area" button was clicked
00296         if ( $blSetup = $this->_setupDelAddress() ) {
00297             return;
00298         }
00299 
00300         $blUserRegistered = $this->_changeUser_noRedirect( );
00301 
00302         if ( $blUserRegistered === true ) {
00303             return 'payment';
00304         } else {
00305             return $blUserRegistered;
00306         }
00307     }
00308 
00314     public function changeuser_testvalues()
00315     {
00316         $this->_changeUser_noRedirect();
00317     }
00318 
00340     public function createUser()
00341     {
00342         // checking if "open address area" button was clicked
00343         if ( $blSetup = $this->_setupDelAddress() ) {
00344             return;
00345         }
00346 
00347         $myConfig = $this->getConfig();
00348         $myUtils  = oxUtils::getInstance();
00349 
00350         // collecting values to check
00351         $sUser = oxConfig::getParameter( 'lgn_usr' );
00352 
00353         // first pass
00354         $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00355 
00356         // second pass
00357         $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00358 
00359         $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00360         $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00361         $aDelAdress = $this->_getDelAddressData();
00362 
00363         $oUser = oxNew( 'oxuser' );
00364 
00365         try {
00366 
00367             $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00368 
00369             // setting values
00370             $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00371             $oUser->setPassword( $sPassword );
00372             $oUser->oxuser__oxactive   = new oxField(1, oxField::T_RAW);
00373 
00374             $oUser->createUser();
00375             $oUser->load( $oUser->getId() );
00376             $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00377 
00378             // assigning to newsletter
00379             $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00380             $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, true );
00381 
00382             $oUser->logout();
00383 
00384         } catch ( oxUserException $oEx ) {
00385             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00386             return false;
00387         } catch( oxInputException $oEx ){
00388             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00389             return false;
00390         } catch( oxConnectionException $oEx ){
00391             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00392             return false;
00393         }
00394 
00395         if ( !$sPassword ) {
00396             oxSession::setVar( 'usr', $oUser->getId() );
00397             $this->_afterLogin( $oUser );
00398         } elseif ( $this->login() == 'user' ) {
00399             return false;
00400         }
00401 
00402         // order remark
00403         //V #427: order remark for new users
00404         $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00405         if ( $sOrd_Remark ) {
00406             oxSession::setVar( 'ordrem', $sOrd_Remark );
00407         }
00408 
00409         // send register eMail
00410         //TODO: move into user
00411         if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00412             $oxEMail = oxNew( 'oxemail' );
00413             $oxEMail->sendRegisterEmail( $oUser );
00414         }
00415 
00416         // new registered
00417         $this->_blIsNewUser = true;
00418 
00419         return 'payment';
00420     }
00421 
00427     public function registerUser()
00428     {
00429         // checking if "open address area" button was clicked
00430         if ( $blSetup = $this->_setupDelAddress() ) {
00431             return;
00432         }
00433 
00434         // registered new user ?
00435         if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00436                 // #1672 R
00437                 $this->getUser()->addToGroup( 'oxidnotyetordered' );
00438 
00439             if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00440                 return 'register?success=1';
00441             } else {
00442                 return 'register?success=1&newslettererror=4';
00443             }
00444         } else { // problems with registration ...
00445             $this->logout();
00446         }
00447     }
00448 
00462     protected function _changeUser_noRedirect( )
00463     {
00464         // no user ?
00465         $oUser = $this->getUser();
00466         if ( !$oUser ) {
00467             return;
00468         }
00469 
00470         // collecting values to check
00471         $aDelAdress = $this->_getDelAddressData();
00472         // if user company name, user name and additional info has special chars
00473         $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname',
00474                             'oxuser__oxlname', 'oxuser__oxstreet', 'oxuser__oxstreetnr',
00475                             'oxuser__oxcity', 'oxuser__oxfon', 'oxuser__oxfax',
00476                             'oxuser__oxmobfon', 'oxuser__oxprivfon');
00477 
00478         $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00479 
00480         $sUserName  = $oUser->oxuser__oxusername->value;
00481         $sPassword  = $sPassword2 = $oUser->oxuser__oxpassword->value;
00482 
00483         try { // testing user input
00484             $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00485             // assigning to newsletter
00486             if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00487                 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00488             }
00489             $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00490 
00491         } catch ( oxUserException $oEx ) { // errors in input
00492             // marking error code
00493             //TODO
00494             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00495             return;
00496         } catch(oxInputException $oEx) {
00497             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00498             return;
00499         } catch(oxConnectionException $oEx){
00500              //connection to external resource broken, change message and pass to the view
00501             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00502             return;
00503         }
00504 
00505 
00506         // order remark
00507         $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00508         if ( $sOrd_Remark ) {
00509             oxSession::setVar( 'ordrem', $sOrd_Remark );
00510         }
00511 
00512         if ( $oBasket = $this->getSession()->getBasket() ) {
00513             $oBasket->onUpdate();
00514         }
00515         return true;
00516     }
00517 
00524     protected function _getDelAddressData()
00525     {
00526         // if user company name, user name and additional info has special chars
00527         $aRawVal = array('oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00528         $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $aRawVal );
00529 
00530         if ( is_array( $aDeladr ) ) {
00531             // checking if data is filled
00532             if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00533                 unset( $aDeladr['oxaddress__oxsal'] );
00534             }
00535             if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00536                 // resetting to avoid empty records
00537                 $aDelAdress = array();
00538             }
00539         }
00540         return $aDelAdress;
00541     }
00542 
00548     protected function _getLogoutLink()
00549     {
00550         $myConfig = $this->getConfig();
00551         $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00552         if ( $myConfig->isSsl() ) {
00553             $sLogoutLink = $myConfig->getShopHomeUrl();
00554         }
00555         $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->_oParent->getDynUrlParams();
00556         if ( $sParam = oxConfig::getParameter('anid') ) {
00557             $sLogoutLink .= '&amp;anid='.$sParam;
00558         }
00559         if ( $sParam = oxConfig::getParameter('cnid') ) {
00560             $sLogoutLink .= '&amp;cnid='.$sParam;
00561         }
00562         if ( $sParam = oxConfig::getParameter('mnid') ) {
00563             $sLogoutLink .= '&amp;mnid='.$sParam;
00564         }
00565         if ( $sParam = oxConfig::getParameter('tpl') ) {
00566             $sLogoutLink .= '&amp;tpl='.$sParam;
00567         }
00568         return $sLogoutLink.'&amp;fnc=logout';
00569     }
00570 
00580     protected function _setupDelAddress()
00581     {
00582         $blSetup = false;
00583         $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00584 
00585         // user clicked on button to hide
00586         if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00587             $blShowShipAddress = 0;
00588             $blSetup = true;
00589 
00590             // unsetting delivery address
00591             oxSession::deleteVar( 'deladdrid' );
00592         } else {
00593 
00594             $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00595             // user clicked on button to show
00596             if ( $blShowAddress != $blSessShowAddress ) {
00597                 $blShowShipAddress = 1;
00598                 $blSetup = true;
00599             }
00600         }
00601 
00602         oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00603         $this->_oParent->_aViewData['blshowshipaddress'] = $blShowShipAddress;
00604 
00605         return $blSetup;
00606     }
00607 
00614     public function loginOid()
00615     {
00616         $iOldErrorReproting = error_reporting();
00617         error_reporting($iOldErrorReproting & ~E_STRICT);
00618         try {
00619             $oOpenId = oxNew( "oxOpenID" );
00620             $aData = $oOpenId->getOidResponse( $this->_getReturnUrl() );
00621         } catch ( oxUserException $oEx ) {
00622                 // for login component send excpetion text to a custom component (if defined)
00623                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00624         }
00625         error_reporting($iOldErrorReproting);
00626         if ( count( $aData ) < 1 ) {
00627             oxUtils::getInstance()->redirect($this->getConfig()->getShopHomeURL().'cl=register');
00628         }
00629         if ( $aData['email'] ) {
00630             $oUser = oxNew( 'oxuser' );
00631             $oUser->oxuser__oxusername = new oxField($aData['email'], oxField::T_RAW);
00632 
00633             // if such user does not exist - creating it
00634             if ( !$oUser->exists() ) {
00635                 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00636                 $oUser->oxuser__oxactive   = new oxField(1, oxField::T_RAW);
00637                 $oUser->oxuser__oxrights   = new oxField('user', oxField::T_RAW);
00638                 $oUser->oxuser__oxshopid   = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00639                 list ($sFName, $sLName)    = explode(' ', $aData['fullname']);
00640                 $oUser->oxuser__oxfname    = new oxField($sFName, oxField::T_RAW);
00641                 $oUser->oxuser__oxlname    = new oxField($sLName, oxField::T_RAW);
00642 
00643                 $oUser->oxuser__oxsal      = new oxField($this->_getUserTitle($aData['gender']), oxField::T_RAW);
00644                 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00645                 if ( $sCountryId = $oUser->getUserCountryId( $aData['country'] ) ) {
00646                     $oUser->oxuser__oxcountryid = new oxField( $sCountryId, oxField::T_RAW );
00647                 }
00648                 if ( $aData['postcode'] ) {
00649                     $oUser->oxuser__oxzip = new oxField( $aData['postcode'], oxField::T_RAW );
00650                 }
00651                 $oUser->save();
00652             } else {
00653                 $oUser->load( $oUser->getId() );
00654                 //if existing user loggins first time with openid
00655                 if ( $oUser->oxuser__oxisopenid->value == 0 ) {
00656                     if ( !$oUser->oxuser__oxpassword->value ) {
00657                         $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00658                         $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00659                     } else {
00660                         $oUser->oxuser__oxisopenid = new oxField(2, oxField::T_RAW);
00661                     }
00662                     $oUser->save();
00663                 }
00664             }
00665 
00666             try {
00667                 $oUser->openIdLogin( $oUser->oxuser__oxusername->value );
00668             } catch ( oxUserException $oEx ) {
00669                 // for login component send excpetion text to a custom component (if defined)
00670                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00671             }
00672 
00673             // finalizing ..
00674             $this->_afterLogin( $oUser );
00675             $this->getParent()->setFncName( null );
00676             oxUtils::getInstance()->redirect($this->getParent()->getLink());
00677         }
00678     }
00679 
00687     protected function _getUserTitle( $sGender )
00688     {
00689         if ( $sGender == "F" ) {
00690             return oxLang::getInstance()->translateString( "ACCOUNT_USER_MRS" );
00691         } else {
00692             return oxLang::getInstance()->translateString( "ACCOUNT_USER_MR" );
00693         }
00694     }
00695 
00701     protected function _getReturnUrl()
00702     {
00703         $this->getParent()->setFncName( 'loginOid' );
00704         $sReturnUrl = str_replace( '&amp;', '&', $this->getParent()->getLink() );
00705         if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00706             if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00707                 $sReturnUrl = $sReturnUrl . "&fnc=loginOid";
00708             } else {
00709                 $sReturnUrl = $sReturnUrl . "?fnc=loginOid";
00710             }
00711         }
00712         return $sReturnUrl;
00713     }
00714 
00715 }

Generated on Tue Aug 18 09:21:08 2009 for OXID eShop CE by  doxygen 1.5.5