Links angepasst usw.
This commit is contained in:
parent
aa1aaab607
commit
f33aed1243
|
|
@ -10,6 +10,10 @@ use OCP\IUserSession;
|
|||
use OCP\AppFramework\Controller;
|
||||
use OCP\IRequest;
|
||||
|
||||
use OCP\User\Events\PostLoginEvent;
|
||||
|
||||
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
||||
|
||||
class Application extends App {
|
||||
|
||||
protected $AppName = 'Agency';
|
||||
|
|
@ -23,6 +27,55 @@ class Application extends App {
|
|||
|
||||
# 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);
|
||||
|
||||
$dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LoginByNC::class);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
CHANGED USER IN DJANGO BY NC
|
||||
*/
|
||||
class LoginByNC extends Controller {
|
||||
|
||||
protected $session;
|
||||
protected $request;
|
||||
private $nclink = 'https://test.app.digitale-agentur.com';
|
||||
//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;
|
||||
}
|
||||
|
||||
private function generateRandomString($length = 10) {
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
# Trigger in Django that the User changed
|
||||
public function handle(BeforeTemplateRenderedEvent $event): void {
|
||||
$postdata = http_build_query(
|
||||
array(
|
||||
'uid' => $this->request->getCookie('nc_username'),
|
||||
'sid' => $this->request->getCookie('nc_session_id')
|
||||
)
|
||||
);
|
||||
|
||||
$opts = [
|
||||
"http" => [
|
||||
"method" => "POST",
|
||||
"header" => "",
|
||||
"content" => $postdata
|
||||
]
|
||||
];
|
||||
$context = stream_context_create($opts);
|
||||
$file = file_get_contents($this->nclink.'/api/setlog/', false, $context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue