AuthController: Use configured home_site

This commit is contained in:
Igor Scheller 2020-03-01 03:22:52 +01:00
parent ba1c658b92
commit b9bb68c8ac
2 changed files with 20 additions and 8 deletions

View File

@ -3,6 +3,7 @@
namespace Engelsystem\Controllers; namespace Engelsystem\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use Engelsystem\Config\Config;
use Engelsystem\Helpers\Authenticator; use Engelsystem\Helpers\Authenticator;
use Engelsystem\Http\Request; use Engelsystem\Http\Request;
use Engelsystem\Http\Response; use Engelsystem\Http\Response;
@ -23,6 +24,9 @@ class AuthController extends BaseController
/** @var UrlGeneratorInterface */ /** @var UrlGeneratorInterface */
protected $url; protected $url;
/** @var Config */
protected $config;
/** @var Authenticator */ /** @var Authenticator */
protected $auth; protected $auth;
@ -36,17 +40,20 @@ class AuthController extends BaseController
* @param Response $response * @param Response $response
* @param SessionInterface $session * @param SessionInterface $session
* @param UrlGeneratorInterface $url * @param UrlGeneratorInterface $url
* @param Config $config
* @param Authenticator $auth * @param Authenticator $auth
*/ */
public function __construct( public function __construct(
Response $response, Response $response,
SessionInterface $session, SessionInterface $session,
UrlGeneratorInterface $url, UrlGeneratorInterface $url,
Config $config,
Authenticator $auth Authenticator $auth
) { ) {
$this->response = $response; $this->response = $response;
$this->session = $session; $this->session = $session;
$this->url = $url; $this->url = $url;
$this->config = $config;
$this->auth = $auth; $this->auth = $auth;
} }
@ -100,7 +107,7 @@ class AuthController extends BaseController
$user->last_login_at = new Carbon(); $user->last_login_at = new Carbon();
$user->save(['touch' => false]); $user->save(['touch' => false]);
return $this->response->redirectTo('news'); return $this->response->redirectTo($this->config->get('home_site'));
} }
/** /**

View File

@ -2,6 +2,7 @@
namespace Engelsystem\Test\Unit\Controllers; namespace Engelsystem\Test\Unit\Controllers;
use Engelsystem\Config\Config;
use Engelsystem\Controllers\AuthController; use Engelsystem\Controllers\AuthController;
use Engelsystem\Helpers\Authenticator; use Engelsystem\Helpers\Authenticator;
use Engelsystem\Http\Exceptions\ValidationException; use Engelsystem\Http\Exceptions\ValidationException;
@ -33,8 +34,9 @@ class AuthControllerTest extends TestCase
$response = $this->createMock(Response::class); $response = $this->createMock(Response::class);
/** @var SessionInterface|MockObject $session */ /** @var SessionInterface|MockObject $session */
/** @var UrlGeneratorInterface|MockObject $url */ /** @var UrlGeneratorInterface|MockObject $url */
/** @var Config $config */
/** @var Authenticator|MockObject $auth */ /** @var Authenticator|MockObject $auth */
list(, $session, $url, $auth) = $this->getMocks(); list(, $session, $url, $config, $auth) = $this->getMocks();
$session->expects($this->once()) $session->expects($this->once())
->method('get') ->method('get')
@ -45,7 +47,7 @@ class AuthControllerTest extends TestCase
->with('pages/login') ->with('pages/login')
->willReturn($response); ->willReturn($response);
$controller = new AuthController($response, $session, $url, $auth); $controller = new AuthController($response, $session, $url, $config, $auth);
$controller->login(); $controller->login();
} }
@ -60,8 +62,9 @@ class AuthControllerTest extends TestCase
/** @var Response|MockObject $response */ /** @var Response|MockObject $response */
$response = $this->createMock(Response::class); $response = $this->createMock(Response::class);
/** @var UrlGeneratorInterface|MockObject $url */ /** @var UrlGeneratorInterface|MockObject $url */
/** @var Config $config */
/** @var Authenticator|MockObject $auth */ /** @var Authenticator|MockObject $auth */
list(, , $url, $auth) = $this->getMocks(); list(, , $url, $config, $auth) = $this->getMocks();
$session = new Session(new MockArraySessionStorage()); $session = new Session(new MockArraySessionStorage());
/** @var Validator|MockObject $validator */ /** @var Validator|MockObject $validator */
$validator = new Validator(); $validator = new Validator();
@ -97,7 +100,7 @@ class AuthControllerTest extends TestCase
->willReturn($response); ->willReturn($response);
// No credentials // No credentials
$controller = new AuthController($response, $session, $url, $auth); $controller = new AuthController($response, $session, $url, $config, $auth);
$controller->setValidator($validator); $controller->setValidator($validator);
try { try {
$controller->postLogin($request); $controller->postLogin($request);
@ -133,8 +136,9 @@ class AuthControllerTest extends TestCase
/** @var Response $response */ /** @var Response $response */
/** @var SessionInterface|MockObject $session */ /** @var SessionInterface|MockObject $session */
/** @var UrlGeneratorInterface|MockObject $url */ /** @var UrlGeneratorInterface|MockObject $url */
/** @var Config $config */
/** @var Authenticator|MockObject $auth */ /** @var Authenticator|MockObject $auth */
list($response, $session, $url, $auth) = $this->getMocks(); list($response, $session, $url, $config, $auth) = $this->getMocks();
$session->expects($this->once()) $session->expects($this->once())
->method('invalidate'); ->method('invalidate');
@ -144,7 +148,7 @@ class AuthControllerTest extends TestCase
->with('/') ->with('/')
->willReturn('https://foo.bar/'); ->willReturn('https://foo.bar/');
$controller = new AuthController($response, $session, $url, $auth); $controller = new AuthController($response, $session, $url, $config, $auth);
$return = $controller->logout(); $return = $controller->logout();
$this->assertEquals(['https://foo.bar/'], $return->getHeader('location')); $this->assertEquals(['https://foo.bar/'], $return->getHeader('location'));
@ -160,9 +164,10 @@ class AuthControllerTest extends TestCase
$session = $this->getMockForAbstractClass(SessionInterface::class); $session = $this->getMockForAbstractClass(SessionInterface::class);
/** @var UrlGeneratorInterface|MockObject $url */ /** @var UrlGeneratorInterface|MockObject $url */
$url = $this->getMockForAbstractClass(UrlGeneratorInterface::class); $url = $this->getMockForAbstractClass(UrlGeneratorInterface::class);
$config = new Config(['home_site' => 'news']);
/** @var Authenticator|MockObject $auth */ /** @var Authenticator|MockObject $auth */
$auth = $this->createMock(Authenticator::class); $auth = $this->createMock(Authenticator::class);
return [$response, $session, $url, $auth]; return [$response, $session, $url, $config, $auth];
} }
} }