diff --git a/TODO b/TODO index 0f86cd51..608aefe7 100644 --- a/TODO +++ b/TODO @@ -145,8 +145,6 @@ miscellaneous: - I don't think browsing online logs is very necessary - add help, api documentation - add version on homepage that reads version from package.json and git hash - - make script faster, right now every request to backend takes 200ms - (current suspect: dependency injector and sqlite) - add tool for migrating szurubooru database - endless pager should include information about page number - add README - apache2 has good README: diff --git a/public_html/js/Auth.js b/public_html/js/Auth.js index e4fced09..a10598cd 100644 --- a/public_html/js/Auth.js +++ b/public_html/js/Auth.js @@ -44,9 +44,13 @@ App.Auth = function(_, jQuery, util, api, appState, promise) { }); } - function loginFromToken(token) { + function loginFromToken(token, isFromCookie) { return promise.make(function(resolve, reject) { - promise.wait(api.post('/login', {token: token})) + var fd = { + token: token, + isFromCookie: isFromCookie + }; + promise.wait(api.post('/login', fd)) .then(function(response) { updateAppState(response); resolve(response); @@ -89,7 +93,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) { return; } - promise.wait(loginFromToken(authCookie)) + promise.wait(loginFromToken(authCookie, true)) .then(function(response) { resolve(); }).fail(function(response) { diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index f3210681..cc8ca2a9 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -4,6 +4,7 @@ namespace Szurubooru\Controllers; final class AuthController extends AbstractController { private $authService; + private $userService; private $tokenService; private $privilegeService; private $inputReader; @@ -12,6 +13,7 @@ final class AuthController extends AbstractController public function __construct( \Szurubooru\Services\AuthService $authService, + \Szurubooru\Services\UserService $userService, \Szurubooru\Services\TokenService $tokenService, \Szurubooru\Services\PrivilegeService $privilegeService, \Szurubooru\Helpers\InputReader $inputReader, @@ -19,6 +21,7 @@ final class AuthController extends AbstractController \Szurubooru\Controllers\ViewProxies\TokenViewProxy $tokenViewProxy) { $this->authService = $authService; + $this->userService = $userService; $this->tokenService = $tokenService; $this->privilegeService = $privilegeService; $this->inputReader = $inputReader; @@ -38,21 +41,30 @@ final class AuthController extends AbstractController { $formData = new \Szurubooru\FormData\LoginFormData($this->inputReader); $this->authService->loginFromCredentials($formData); + + $user = $this->authService->getLoggedInUser(); + $this->userService->updateUserLastLoginTime($user); } elseif (isset($this->inputReader->token)) { $token = $this->tokenService->getByName($this->inputReader->token); $this->authService->loginFromToken($token); + + $user = $this->authService->getLoggedInUser(); + $isFromCookie = boolval($this->inputReader->isFromCookie); + if ($isFromCookie) + $this->userService->updateUserLastLoginTime($user); } else { $this->authService->loginAnonymous(); + $user = $this->authService->getLoggedInUser(); } return [ 'token' => $this->tokenViewProxy->fromEntity($this->authService->getLoginToken()), - 'user' => $this->userViewProxy->fromEntity($this->authService->getLoggedInUser()), + 'user' => $this->userViewProxy->fromEntity($user), 'privileges' => $this->privilegeService->getCurrentPrivileges(), ]; } diff --git a/src/Services/AuthService.php b/src/Services/AuthService.php index 21aa1a71..1bdc753e 100644 --- a/src/Services/AuthService.php +++ b/src/Services/AuthService.php @@ -54,7 +54,6 @@ class AuthService $this->loginToken = $this->createAndSaveLoginToken($user); $this->loggedInUser = $user; - $this->userService->updateUserLastLoginTime($user); } public function loginFromToken(\Szurubooru\Entities\Token $token) @@ -67,7 +66,6 @@ class AuthService $this->loginToken = $token; $this->loggedInUser = $user; - $this->userService->updateUserLastLoginTime($this->loggedInUser); } public function getAnonymousUser()