mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-08 09:26:57 +01:00
* [ADD] Improved tracking handling.
* [MOD] Improved login process workflow.
This commit is contained in:
@@ -29,10 +29,11 @@ use SP\Core\Events\EventMessage;
|
||||
use SP\Core\SessionFactory;
|
||||
use SP\Core\SessionUtil;
|
||||
use SP\Html\Html;
|
||||
use SP\Http\Request;
|
||||
use SP\Http\Response;
|
||||
use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
|
||||
use SP\Modules\Web\Controllers\Traits\JsonTrait;
|
||||
use SP\Services\Auth\LoginService;
|
||||
use SP\Util\Json;
|
||||
|
||||
/**
|
||||
* Class LoginController
|
||||
@@ -41,17 +42,37 @@ use SP\Util\Json;
|
||||
*/
|
||||
class LoginController extends ControllerBase
|
||||
{
|
||||
use JsonTrait;
|
||||
|
||||
/**
|
||||
* Login action
|
||||
*
|
||||
* @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function loginAction()
|
||||
{
|
||||
$loginService = $this->dic->get(LoginService::class);
|
||||
Json::returnJson($loginService->doLogin());
|
||||
try {
|
||||
$loginService = $this->dic->get(LoginService::class);
|
||||
$loginResponmse = $loginService->doLogin();
|
||||
|
||||
$forward = Request::getRequestHeaders('X-Forwarded-For');
|
||||
|
||||
if ($forward) {
|
||||
$this->eventDispatcher->notifyEvent('login.info',
|
||||
new Event($this, EventMessage::factory()
|
||||
->addDetail('X-Forwarded-For', $this->configData->isDemoEnabled() ? '***' : $forward))
|
||||
);
|
||||
}
|
||||
|
||||
$this->returnJsonResponseData(['url' => $loginResponmse->getRedirect()]);
|
||||
} catch (\Exception $e) {
|
||||
processException($e);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('exception', new Event($e));
|
||||
|
||||
$this->returnJsonResponse($e->getCode(), $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,9 +38,9 @@ trait JsonTrait
|
||||
/**
|
||||
* Returns JSON response
|
||||
*
|
||||
* @param int $status Status code
|
||||
* @param string $description Untranslated description string
|
||||
* @param array|null $messages Untranslated massages array of strings
|
||||
* @param int $status Status code
|
||||
* @param string $description Untranslated description string
|
||||
* @param array|null $messages Untranslated massages array of strings
|
||||
*/
|
||||
protected function returnJsonResponse($status, $description, array $messages = null)
|
||||
{
|
||||
@@ -59,10 +59,10 @@ trait JsonTrait
|
||||
* Returns JSON response
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $status Status code
|
||||
* @param null $description Untranslated description string
|
||||
* @param int $status Status code
|
||||
* @param null $description Untranslated description string
|
||||
*/
|
||||
protected function returnJsonResponseData($data, $status = 0, $description = null)
|
||||
protected function returnJsonResponseData($data, $status = JsonResponse::JSON_SUCCESS, $description = null)
|
||||
{
|
||||
$jsonResponse = new JsonResponse();
|
||||
$jsonResponse->setStatus($status);
|
||||
@@ -80,7 +80,7 @@ trait JsonTrait
|
||||
* Returns JSON response
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @param int $status Status code
|
||||
* @param int $status Status code
|
||||
*/
|
||||
protected function returnJsonResponseException(\Exception $exception, $status = JsonResponse::JSON_ERROR)
|
||||
{
|
||||
@@ -88,7 +88,7 @@ trait JsonTrait
|
||||
$jsonResponse->setStatus($status);
|
||||
$jsonResponse->setDescription($exception->getMessage());
|
||||
|
||||
if ($exception instanceof SPException && $exception->getHint() !== null ) {
|
||||
if ($exception instanceof SPException && $exception->getHint() !== null) {
|
||||
$jsonResponse->setMessages([$exception->getHint()]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user