This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Controllers/AuthController.php

52 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Szurubooru\Controllers;
final class AuthController extends AbstractController
{
private $authService;
2014-08-31 14:07:46 +02:00
private $userService;
private $passwordService;
private $inputReader;
public function __construct(
\Szurubooru\Services\AuthService $authService,
2014-08-31 14:07:46 +02:00
\Szurubooru\Services\UserService $userService,
\Szurubooru\Services\PasswordService $passwordService,
\Szurubooru\Helpers\InputReader $inputReader)
{
$this->authService = $authService;
2014-08-31 14:07:46 +02:00
$this->userService = $userService;
$this->passwordService = $passwordService;
$this->inputReader = $inputReader;
}
2014-08-30 15:04:33 +02:00
public function registerRoutes(\Szurubooru\Router $router)
{
$router->post('/api/login', [$this, 'login']);
2014-08-30 23:17:54 +02:00
$router->put('/api/login', [$this, 'login']);
}
public function login()
{
if (isset($this->inputReader->userName) and isset($this->inputReader->password))
{
$this->authService->loginFromCredentials($this->inputReader->userName, $this->inputReader->password);
}
elseif (isset($this->inputReader->token))
{
$this->authService->loginFromToken($this->inputReader->token);
}
2014-08-30 23:17:54 +02:00
else
{
$this->authService->loginAnonymous();
}
2014-08-30 23:17:54 +02:00
return
[
2014-08-31 09:09:17 +02:00
'token' => new \Szurubooru\ViewProxies\Token($this->authService->getLoginToken()),
'user' => new \Szurubooru\ViewProxies\User($this->authService->getLoggedInUser()),
2014-09-04 19:57:06 +02:00
'privileges' => $this->authService->getCurrentPrivileges(),
2014-08-30 23:17:54 +02:00
];
}
}