Namensaenderung durch NC in Django

This commit is contained in:
holger.trampe 2021-07-26 12:32:35 +02:00
parent 8ee73d4f77
commit 252b357eb7
1 changed files with 40 additions and 4 deletions

View File

@ -2,6 +2,7 @@
namespace OCA\Agency\AppInfo; namespace OCA\Agency\AppInfo;
use OCP\User\Events\UserChangedEvent;
use OCP\User\Events\BeforeUserLoggedOutEvent; use OCP\User\Events\BeforeUserLoggedOutEvent;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\AppFramework\App; use OCP\AppFramework\App;
@ -9,20 +10,54 @@ use OCP\IUserSession;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\IRequest; use OCP\IRequest;
class Application extends App { class Application extends App {
protected $appName = 'Agency'; protected $AppName = 'Agency';
public function __construct() { public function __construct() {
parent::__construct($this->appName); parent::__construct($this->AppName);
$dispatcher = $this->getContainer()->query(IEventDispatcher::class); $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 # 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); $dispatcher->addServiceListener(BeforeUserLoggedOutEvent::class, LogoutByNC::class);
# ADding the Event, that User has Changed - update the logged User by Django. Works only by personal informations of the User!
$dispatcher->addServiceListener(UserChangedEvent::class, UserChangedByNC::class);
} }
} }
/*
CHANGED USER IN DJANGO BY NC
*/
class UserChangedByNC extends Controller {
protected $session;
protected $request;
private $nclink = 'http://host.docker.internal:8000';
public function __construct(string $AppName, IRequest $request, IUserSession $session) {
$this->request = $request;
parent::__construct($AppName, $request);
$this->session = $session;
}
# Trigger in Django that the User changed
public function handle(UserChangedEvent $event): void {
$opts = [
"http" => [
"method" => "GET",
"header" => ""
]
];
$context = stream_context_create($opts);
#$file = file_get_contents($this->nclink.'/api/uschanged/'.$this->session->getUser()->getUID(), false, $context);
$file = file_get_contents($this->nclink.'/api/uschanged/'.$this->session->getUser()->getUID().'/'.$this->request->getCookie('nc_session_id'), false, $context);
}
}
/* /*
LOGOUT DJANGO BY NC LOGOUT DJANGO BY NC
Diese Klasse wird erzeugt, wenn das Evenet BeforeUserLoggedOutEvent getriggert wird. Dann wird Diese Klasse wird erzeugt, wenn das Evenet BeforeUserLoggedOutEvent getriggert wird. Dann wird
@ -31,6 +66,7 @@ class Application extends App {
class LogoutByNC extends Controller { class LogoutByNC extends Controller {
protected $session; protected $session;
private $nclink = 'http://host.docker.internal:8000';
public function __construct(string $AppName, IRequest $request, IUserSession $session) { public function __construct(string $AppName, IRequest $request, IUserSession $session) {
parent::__construct($AppName, $request); parent::__construct($AppName, $request);
@ -45,6 +81,6 @@ class LogoutByNC extends Controller {
] ]
]; ];
$context = stream_context_create($opts); $context = stream_context_create($opts);
$file = file_get_contents('http://host.docker.internal:8000/api/logout/'.$this->session->getUser()->getUID(), false, $context); $file = file_get_contents($this->nclink.'/api/logout/'.$this->session->getUser()->getUID(), false, $context);
} }
} }