50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace OCA\Agency\AppInfo;
|
|
|
|
use OCP\User\Events\BeforeUserLoggedOutEvent;
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
|
use OCP\AppFramework\App;
|
|
use OCP\IUserSession;
|
|
use OCP\AppFramework\Controller;
|
|
use OCP\IRequest;
|
|
|
|
class Application extends App {
|
|
|
|
protected $appName = 'Agency';
|
|
|
|
public function __construct() {
|
|
parent::__construct($this->appName);
|
|
$dispatcher = $this->getContainer()->query(IEventDispatcher::class);
|
|
|
|
# ADding the Pre-Logout-Event for logging a User out of Django when user is atempt to logout from the cloud
|
|
$dispatcher->addServiceListener(BeforeUserLoggedOutEvent::class, LogoutByNC::class);
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
LOGOUT DJANGO BY NC
|
|
Diese Klasse wird erzeugt, wenn das Evenet BeforeUserLoggedOutEvent getriggert wird. Dann wird
|
|
der User über die Django-API ausgeloggt!
|
|
*/
|
|
class LogoutByNC extends Controller {
|
|
|
|
protected $session;
|
|
|
|
public function __construct(string $AppName, IRequest $request, IUserSession $session) {
|
|
parent::__construct($AppName, $request);
|
|
$this->session = $session;
|
|
}
|
|
# Logout the user!
|
|
public function handle(BeforeUserLoggedOutEvent $event): void {
|
|
$opts = [
|
|
"http" => [
|
|
"method" => "GET",
|
|
"header" => ""
|
|
]
|
|
];
|
|
$context = stream_context_create($opts);
|
|
$file = file_get_contents('http://host.docker.internal:8000/api/logout/'.$this->session->getUser()->getUID(), false, $context);
|
|
}
|
|
} |