Skip to content

Commit

Permalink
Socket server (#3665)
Browse files Browse the repository at this point in the history
* NOT working

* Base server completed
- No message handling from MQ

* 0-ALPHA

* Fixed run script

* Improvements

* Checking bug on apache configuration

* Testable version

* Stable release

* Re-activated SocketListener Component

* Fixed not resolved path from outside server directory

* Updated submodule

* Fix api token

* Fixed comments delivery

* Fixed test-script

* Improvement on Languages class

* Updates internal

* Fixed broadcast logout on password change

* Update yarn lock

---------

Co-authored-by: riccio82 <[email protected]>
  • Loading branch information
Ostico and riccio82 authored Dec 9, 2024
1 parent cb36e93 commit dc692e9
Show file tree
Hide file tree
Showing 29 changed files with 1,251 additions and 471 deletions.
2 changes: 1 addition & 1 deletion docker
2 changes: 1 addition & 1 deletion internal_scripts
32 changes: 30 additions & 2 deletions lib/Controller/API/App/Authentication/LoginController.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/**
* Created by PhpStorm.
* User: fregini
* Date: 22/11/2016
* User: Domenico <[email protected]>, <[email protected]>
* Date: 19/09/2024
* Time: 09:38
*/

Expand Down Expand Up @@ -132,4 +132,32 @@ public function token() {
$this->response->code( 200 );
}

/**
* Signed Double-Submit Cookie
* @throws Exception
*/
public function socketToken() {

if ( empty( $_SESSION[ 'user' ] ) ) {
$this->response->code( 406 );
return;
}

$jwt = new SimpleJWT( [ "uid" => $_SESSION[ 'user' ]->uid ] );
$jwt->setTimeToLive( 60 );

CookieManager::setCookie( INIT::$XSRF_TOKEN, $jwt->jsonSerialize(),
[
'expires' => time() + 60, /* now + 60 seconds */
'path' => '/',
'domain' => INIT::$COOKIE_DOMAIN,
'secure' => true,
'httponly' => false,
'samesite' => 'Strict',
]
);

$this->response->code( 200 );
}

}
1 change: 1 addition & 0 deletions lib/Routes/utils_routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
route( '/login', 'POST', [ 'API\App\Authentication\LoginController', 'login' ] );
route( '/logout', 'POST', [ 'API\App\Authentication\LoginController', 'directLogout' ] );
route( '/login/token', 'GET', [ 'API\App\Authentication\LoginController', 'token' ] );
route( '/login/socket', 'GET', [ 'API\App\Authentication\LoginController', 'socketToken' ] );

route( '/metadata', 'POST', [ 'API\App\UserMetadataController', 'update' ] );

Expand Down
16 changes: 3 additions & 13 deletions lib/Utils/AsyncTasks/Workers/GlossaryWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,14 @@ private function getFeatureSetFromString( $featuresString ) {
/**
* @param FeatureSet $featureSet
*
* @return Engines_AbstractEngine
* @return Engines_MyMemory
* @throws Exception
*/
private function getEngine( FeatureSet $featureSet ) {
$_TMS = Engine::getInstance( 1 );
$_TMS->setFeatureSet( $featureSet );

/** @var Engines_MyMemory $_TMS */
return $_TMS;
}

Expand All @@ -532,17 +533,6 @@ private function getUser( $array ) {
* @throws Exception
*/
private function getMyMemoryClient() {
$engineDAO = new EnginesModel_EngineDAO( Database::obtain() );
$engineStruct = EnginesModel_EngineStruct::getStruct();
$engineStruct->id = 1;

$eng = $engineDAO->setCacheTTL( 60 * 5 )->read( $engineStruct );

/**
* @var $engineRecord EnginesModel_EngineStruct
*/
$engineRecord = @$eng[ 0 ];

return new Engines_MyMemory( $engineRecord );
return $this->getEngine( new FeatureSet() );
}
}
6 changes: 3 additions & 3 deletions lib/Utils/Langs/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static function getInstance(): Languages {
*/
public static function isRTL( string $code ): bool {
//convert ISO code in RFC
$code = ( new Languages )->normalizeLanguageCode( $code );
$code = self::getInstance()->normalizeLanguageCode( $code );

return self::$map_rfc2obj[ $code ][ 'rtl' ];
}
Expand Down Expand Up @@ -342,7 +342,7 @@ protected function normalizeLanguageCode( string $languageCode ): ?string {
* @return bool
*/
public static function isValidLanguage( string $language ): bool {
$language = ( new Languages )->normalizeLanguageCode( $language );
$language = self::getInstance()->normalizeLanguageCode( $language );

return array_key_exists( $language, self::$map_rfc2obj );
}
Expand Down Expand Up @@ -374,7 +374,7 @@ public static function getLocalizedLanguage( string $rfc3066code ): ?string {
* @return string|null
*/
public static function convertLanguageToIsoCode( string $code ): ?string {
$code = ( new Languages )->normalizeLanguageCode( $code );
$code = self::getInstance()->normalizeLanguageCode( $code );

return self::$map_rfc2obj[ $code ][ 'isocode' ] ?? null;
}
Expand Down
6 changes: 3 additions & 3 deletions nodejs/enqueue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ stompit.connect(connectOptions, function(error, client) {
}

var sendHeaders = {
'destination': '/queue/matecat_sse_comments',
'destination': '/topic/matecat_sse_notifications',
'content-type': 'text/plain'
};

var frame = client.send(sendHeaders);
var response = {
_type : 'comment',
data : {
id_job : '2',
id_job : '638',
password : '3494ab77e7d7',
payload: {
_type: 'comment',
id_segment : Math.random(),
id_segment : 377916,
message : _.sample(['hello', 'hi', 'help', 'sorry'])
}
}
Expand Down
Loading

0 comments on commit dc692e9

Please sign in to comment.