/** * Update profile data * * @param array $parameters * @return array */ public function write( $parameters = null ) { $result = array(); //TODO find another placement ? //if Token (CSRF) if(!isset($_POST['Token']) || !SecurityTool::isUserTokenValid($_POST['Token'])) { $result = array( 'Data' => array( 'Status' => 'Error', 'ErrorCode' => 10, 'Msg' => "Invalid Token" ) ); } else { $result = $this->callEsbWrite($parameters); } // ESB update $uuid = MMUsers::getCurrentUserId(); $ticketParams = array( $this->getBusinessNameMapping('userName') => $uuid ); foreach ( $this->getBusinessNamesForWrite() as $name ) { $ticketParams[$name] = isset( $_POST[$name] ) ? $_POST[$name] : ''; } // Front user update $userUpdateParams = array( 'uuid' => $uuid, 'customerType' => $_POST[$this->getBusinessNameMapping( 'customerType' )], 'userSpeciality' => $_POST[$this->getBusinessNameMapping( 'userSpecialty' )], 'state' => isset( $_POST['state'] ) ? $_POST['state'] : null, 'country' => $this->getCountryOfRegistration(), 'language' => "" ); // quick fix for retrieve the real main spe $userSpe = $this->getUserSpecialty($uuid); if ( $userSpe != $ticketParams['User_speciality'] ) { $userUpdateParams['userSpeciality'] = $userSpe; } $user = MMUserLogin::createOrUpdateMMUser( $userUpdateParams ); $user->setCookie(); $businessNames = $this->getBusinessNamesForTicket(); $ticketBackendParams = array(); foreach ( $businessNames as $ticketParam => $businessName ) { if ( isset( $userUpdateParams[$businessName] ) ) { $ticketBackendParams[$ticketParam] = $userUpdateParams[$businessName]; } elseif ( isset( $ticketParams[$businessName] ) ) { $ticketBackendParams[$ticketParam] = $ticketParams[$businessName]; } elseif ( $businessName == $this->getBusinessNameMapping( 'countryOfRegistration' ) ) { $ticketBackendParams[$ticketParam] = $this->getCountryOfRegistration(); } else { eZDebug::writeError( 'Could not get registration param: ' . $businessName ); } } $ticketBackendParams[MMUsers::COOKIE_KEY] = $user->getMMSettings(); $result['User'] = $user; $result['Ticket'] = MMUserLogin::encryptText( json_encode( $ticketBackendParams ) ); return $result; }