diff options
author | David Guillot <david@guillot.me> | 2018-06-29 22:28:12 +0200 |
---|---|---|
committer | David Guillot <david@guillot.me> | 2018-07-01 23:01:54 +0200 |
commit | a84e80131a891184e234ddeee1ba0606ea898d7b (patch) | |
tree | 493d7a609192c86cb3c5b79a5e2ab8d193386f90 /lib/Controller/ApiController.php | |
parent | ec3cc602f1bd363efe776ce4914319034d35c18e (diff) |
feat(api): support new OC core login flow
* Base ApiController now needs IUserSession and extracts/serves IUser from it
* All other API controllers now inherit from ApiController
Diffstat (limited to 'lib/Controller/ApiController.php')
-rw-r--r-- | lib/Controller/ApiController.php | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index f5052b49a..d2a787a28 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -7,14 +7,17 @@ * * @author Alessandro Cosentino <cosenal@gmail.com> * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author David Guillot <david@guillot.me> * @copyright 2012 Alessandro Cosentino * @copyright 2012-2014 Bernhard Posselt + * @copyright 2018 David Guillot */ namespace OCA\News\Controller; -use OCP\IRequest; -use OCP\AppFramework\ApiController as BaseApiController; +use \OCP\IRequest; +use \OCP\IUserSession; +use \OCP\AppFramework\ApiController as BaseApiController; /** * Class ApiController @@ -24,14 +27,36 @@ use OCP\AppFramework\ApiController as BaseApiController; class ApiController extends BaseApiController { /** + * @var IUserSession + */ + private $userSession; + + /** * ApiController constructor. * - * @param string $appName The name of the app - * @param IRequest $request The request + * Stores the user session to be able to leverage the user in further methods + * + * @param string $appName The name of the app + * @param IRequest $request The request + * @param IUserSession $userSession The user session */ - public function __construct($appName, IRequest $request) - { + public function __construct($appName, IRequest $request, IUserSession $userSession) { parent::__construct($appName, $request); + $this->userSession = $userSession; + } + + /** + * @return IUser + */ + protected function getUser() { + return $this->userSession->getUser(); + } + + /** + * @return string + */ + protected function getUserId() { + return $this->getUser()->getUID(); } /** |