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         } 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=content&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 
00284                 oxUtils::getInstance()->redirect( $this->_getLogoutLink());
00285             }
00286         }
00287     }
00288 
00298     public function changeUser( )
00299     {
00300         // checking if "open address area" button was clicked
00301         if ( $blSetup = $this->_setupDelAddress() ) {
00302             return;
00303         }
00304 
00305         $blUserRegistered = $this->_changeUser_noRedirect( );
00306 
00307         if ( $blUserRegistered === true ) {
00308             return 'payment';
00309         } else {
00310             return $blUserRegistered;
00311         }
00312     }
00313 
00319     public function changeuser_testvalues()
00320     {
00321         $this->_changeUser_noRedirect();
00322     }
00323 
00345     public function createUser()
00346     {
00347         // checking if "open address area" button was clicked
00348         if ( $blSetup = $this->_setupDelAddress() ) {
00349             return;
00350         }
00351 
00352         $myConfig = $this->getConfig();
00353         $myUtils  = oxUtils::getInstance();
00354 
00355         // collecting values to check
00356         $sUser = oxConfig::getParameter( 'lgn_usr' );
00357 
00358         // first pass
00359         $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00360 
00361         // second pass
00362         $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00363 
00364         $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00365         $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00366         $aDelAdress = $this->_getDelAddressData();
00367 
00368         $oUser = oxNew( 'oxuser' );
00369 
00370         try {
00371 
00372             $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00373 
00374             // setting values
00375             $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00376             $oUser->setPassword( $sPassword );
00377             $oUser->oxuser__oxactive   = new oxField(1, oxField::T_RAW);
00378 
00379             $oUser->createUser();
00380             $oUser->load( $oUser->getId() );
00381             $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00382 
00383             // assigning to newsletter
00384             $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00385             $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, true );
00386 
00387             $oUser->logout();
00388 
00389         } catch ( oxUserException $oEx ) {
00390             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00391             return false;
00392         } catch( oxInputException $oEx ){
00393             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00394             return false;
00395         } catch( oxConnectionException $oEx ){
00396             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00397             return false;
00398         }
00399 
00400         if ( !$sPassword ) {
00401             oxSession::setVar( 'usr', $oUser->getId() );
00402             $this->_afterLogin( $oUser );
00403         } elseif ( $this->login() == 'user' ) {
00404             return false;
00405         }
00406 
00407         // order remark
00408         //V #427: order remark for new users
00409         $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00410         if ( $sOrd_Remark ) {
00411             oxSession::setVar( 'ordrem', $sOrd_Remark );
00412         }
00413 
00414         // send register eMail
00415         //TODO: move into user
00416         if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00417             $oxEMail = oxNew( 'oxemail' );
00418             $oxEMail->sendRegisterEmail( $oUser );
00419         }
00420 
00421         // new registered
00422         $this->_blIsNewUser = true;
00423 
00424         return 'payment';
00425     }
00426 
00432     public function registerUser()
00433     {
00434         // checking if "open address area" button was clicked
00435         if ( $blSetup = $this->_setupDelAddress() ) {
00436             return;
00437         }
00438 
00439         // registered new user ?
00440         if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00441                 // #1672 R
00442                 $this->getUser()->addToGroup( 'oxidnotyetordered' );
00443 
00444             if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00445                 return 'register?success=1';
00446             } else {
00447                 return 'register?success=1&newslettererror=4';
00448             }
00449         } else { // problems with registration ...
00450             $this->logout();
00451         }
00452     }
00453 
00467     protected function _changeUser_noRedirect( )
00468     {
00469         // no user ?
00470         $oUser = $this->getUser();
00471         if ( !$oUser ) {
00472             return;
00473         }
00474 
00475         // collecting values to check
00476         $aDelAdress = $this->_getDelAddressData();
00477         // if user company name, user name and additional info has special chars
00478         $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00479         $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00480 
00481         $sUserName  = $oUser->oxuser__oxusername->value;
00482         $sPassword  = $sPassword2 = $oUser->oxuser__oxpassword->value;
00483 
00484         try { // testing user input
00485             $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00486             // assigning to newsletter
00487             if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00488                 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00489             }
00490             $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, $this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) );
00491 
00492         } catch ( oxUserException $oEx ) { // errors in input
00493             // marking error code
00494             //TODO
00495             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00496             return;
00497         } catch(oxInputException $oEx) {
00498             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00499             return;
00500         } catch(oxConnectionException $oEx){
00501              //connection to external resource broken, change message and pass to the view
00502             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00503             return;
00504         }
00505 
00506 
00507         // order remark
00508         $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00509         if ( $sOrd_Remark ) {
00510             oxSession::setVar( 'ordrem', $sOrd_Remark );
00511         }
00512 
00513         if ( $oBasket = $this->getSession()->getBasket() ) {
00514             $oBasket->onUpdate();
00515         }
00516         return true;
00517     }
00518 
00525     protected function _getDelAddressData()
00526     {
00527         // if user company name, user name and additional info has special chars
00528         $aRawVal = array('oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00529         $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $aRawVal );
00530 
00531         if ( is_array( $aDeladr ) ) {
00532             // checking if data is filled
00533             if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00534                 unset( $aDeladr['oxaddress__oxsal'] );
00535             }
00536             if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00537                 // resetting to avoid empty records
00538                 $aDelAdress = array();
00539             }
00540         }
00541         return $aDelAdress;
00542     }
00543 
00549     protected function _getLogoutLink()
00550     {
00551         $myConfig = $this->getConfig();
00552         $sLogoutLink = $myConfig->getShopSecureHomeUrl();
00553         if ( $myConfig->isSsl() ) {
00554             $sLogoutLink = $myConfig->getShopHomeUrl();
00555         }
00556         $sLogoutLink .= 'cl='.oxConfig::getParameter('cl').$this->_oParent->getDynUrlParams();
00557         if ( $sParam = oxConfig::getParameter('anid') ) {
00558             $sLogoutLink .= '&amp;anid='.$sParam;
00559         }
00560         if ( $sParam = oxConfig::getParameter('cnid') ) {
00561             $sLogoutLink .= '&amp;cnid='.$sParam;
00562         }
00563         if ( $sParam = oxConfig::getParameter('mnid') ) {
00564             $sLogoutLink .= '&amp;mnid='.$sParam;
00565         }
00566         if ( $sParam = oxConfig::getParameter('tpl') ) {
00567             $sLogoutLink .= '&amp;tpl='.$sParam;
00568         }
00569         return $sLogoutLink.'&amp;fnc=logout';
00570     }
00571 
00581     protected function _setupDelAddress()
00582     {
00583         $blSetup = false;
00584         $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00585 
00586         // user clicked on button to hide
00587         if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00588             $blShowShipAddress = 0;
00589             $blSetup = true;
00590 
00591             // unsetting delivery address
00592             oxSession::deleteVar( 'deladdrid' );
00593         } else {
00594 
00595             $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00596             // user clicked on button to show
00597             if ( $blShowAddress != $blSessShowAddress ) {
00598                 $blShowShipAddress = 1;
00599                 $blSetup = true;
00600             }
00601         }
00602 
00603         oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00604         $this->_oParent->_aViewData['blshowshipaddress'] = $blShowShipAddress;
00605 
00606         return $blSetup;
00607     }
00608 
00615     public function loginOid()
00616     {
00617         $iOldErrorReproting = error_reporting();
00618         error_reporting($iOldErrorReproting & ~E_STRICT);
00619         try {
00620             $oOpenId = oxNew( "oxOpenID" );
00621             $aData = $oOpenId->getOidResponse( $this->_getReturnUrl() );
00622         } catch ( oxUserException $oEx ) {
00623                 // for login component send excpetion text to a custom component (if defined)
00624                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00625         }
00626         error_reporting($iOldErrorReproting);
00627         if ( count( $aData ) < 1 ) {
00628             oxUtils::getInstance()->redirect($this->getConfig()->getShopHomeURL().'cl=register');
00629         }
00630         if ( $aData['email'] ) {
00631             $oUser = oxNew( 'oxuser' );
00632             $oUser->oxuser__oxusername = new oxField($aData['email'], oxField::T_RAW);
00633 
00634             // if such user does not exist - creating it
00635             if ( !$oUser->exists() ) {
00636                 $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00637                 $oUser->oxuser__oxactive   = new oxField(1, oxField::T_RAW);
00638                 $oUser->oxuser__oxrights   = new oxField('user', oxField::T_RAW);
00639                 $oUser->oxuser__oxshopid   = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00640                 list ($sFName, $sLName)    = split(' ', $aData['fullname']);
00641                 $oUser->oxuser__oxfname    = new oxField($sFName, oxField::T_RAW);
00642                 $oUser->oxuser__oxlname    = new oxField($sLName, oxField::T_RAW);
00643 
00644                 $oUser->oxuser__oxsal      = new oxField($this->_getUserTitle($aData['gender']), oxField::T_RAW);
00645                 $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00646                 if ( $sCountryId = $oUser->getUserCountryId( $aData['country'] ) ) {
00647                     $oUser->oxuser__oxcountryid = new oxField( $sCountryId, oxField::T_RAW );
00648                 }
00649                 if ( $aData['postcode'] ) {
00650                     $oUser->oxuser__oxzip = new oxField( $aData['postcode'], oxField::T_RAW );
00651                 }
00652                 $oUser->save();
00653             } else {
00654                 $oUser->load( $oUser->getId() );
00655                 //if existing user loggins first time with openid
00656                 if ( $oUser->oxuser__oxisopenid->value == 0 ) {
00657                     if ( !$oUser->oxuser__oxpassword->value ) {
00658                         $oUser->oxuser__oxisopenid = new oxField(1, oxField::T_RAW);
00659                         $oUser->oxuser__oxpassword = new oxField($oUser->getOpenIdPassword(), oxField::T_RAW);
00660                     } else {
00661                         $oUser->oxuser__oxisopenid = new oxField(2, oxField::T_RAW);
00662                     }
00663                     $oUser->save();
00664                 }
00665             }
00666 
00667             try {
00668                 $oUser->openIdLogin( $oUser->oxuser__oxusername->value );
00669             } catch ( oxUserException $oEx ) {
00670                 // for login component send excpetion text to a custom component (if defined)
00671                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00672             } catch( oxConnectionException $oEx ) {
00673                 //connection to external resource broken, change message and pass to the view
00674                 $oEx->setMessage( 'EXCEPTION_ACTIONNOTPOSSIBLEATTHEMOMENT' );
00675                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00676             }
00677 
00678             // finalizing ..
00679             $this->_afterLogin( $oUser );
00680             $this->getParent()->setFncName( null );
00681             oxUtils::getInstance()->redirect($this->getParent()->getLink());
00682         }
00683     }
00684 
00692     protected function _getUserTitle( $sGender )
00693     {
00694         if ( $sGender == "F" ) {
00695             return oxLang::getInstance()->translateString( "ACCOUNT_USER_MRS" );
00696         } else {
00697             return oxLang::getInstance()->translateString( "ACCOUNT_USER_MR" );
00698         }
00699     }
00700 
00706     protected function _getReturnUrl()
00707     {
00708         $this->getParent()->setFncName( 'loginOid' );
00709         $sReturnUrl = str_replace( '&amp;', '&', $this->getParent()->getLink() );
00710         if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00711             if ( !strpos( $sReturnUrl, 'loginOid' ) ) {
00712                 $sReturnUrl = $sReturnUrl . "&fnc=loginOid";
00713             } else {
00714                 $sReturnUrl = $sReturnUrl . "?fnc=loginOid";
00715             }
00716         }
00717         return $sReturnUrl;
00718     }
00719 
00720 }

Generated on Wed Apr 22 12:26:32 2009 for OXID eShop CE by  doxygen 1.5.5