diff options
Diffstat (limited to 'core/Controller')
-rw-r--r-- | core/Controller/AppPasswordController.php | 37 | ||||
-rw-r--r-- | core/Controller/ClientFlowLoginController.php | 37 |
2 files changed, 18 insertions, 56 deletions
diff --git a/core/Controller/AppPasswordController.php b/core/Controller/AppPasswordController.php index b7cbc65e8c0..a858bb025d9 100644 --- a/core/Controller/AppPasswordController.php +++ b/core/Controller/AppPasswordController.php @@ -24,20 +24,18 @@ declare(strict_types=1); namespace OC\Core\Controller; -use BadMethodCallException; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; -use OC\Settings\Activity\Provider; -use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\Authentication\Exceptions\CredentialsUnavailableException; use OCP\Authentication\Exceptions\PasswordUnavailableException; use OCP\Authentication\LoginCredentials\IStore; -use OCP\ILogger; use OCP\IRequest; use OCP\ISession; use OCP\Security\ISecureRandom; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; class AppPasswordController extends \OCP\AppFramework\OCSController { @@ -50,31 +48,26 @@ class AppPasswordController extends \OCP\AppFramework\OCSController { /** @var IProvider */ private $tokenProvider; - /** @var IActivityManager */ - private $activityManager; - - /** @var ILogger */ - private $logger; - /** @var IStore */ private $credentialStore; + /** @var EventDispatcherInterface */ + private $eventDispatcher; + public function __construct(string $appName, IRequest $request, ISession $session, ISecureRandom $random, IProvider $tokenProvider, IStore $credentialStore, - IActivityManager $activityManager, - ILogger $logger) { + EventDispatcherInterface $eventDispatcher) { parent::__construct($appName, $request); $this->session = $session; $this->random = $random; $this->tokenProvider = $tokenProvider; $this->credentialStore = $credentialStore; - $this->activityManager = $activityManager; - $this->logger = $logger; + $this->eventDispatcher = $eventDispatcher; } /** @@ -115,20 +108,8 @@ class AppPasswordController extends \OCP\AppFramework\OCSController { IToken::DO_NOT_REMEMBER ); - $event = $this->activityManager->generateEvent(); - $event->setApp('settings') - ->setType('security') - ->setAffectedUser($credentials->getUID()) - ->setAuthor($credentials->getUID()) - ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $generatedToken->getName()]) - ->setObject('app_token', $generatedToken->getId(), 'App Password'); - - try { - $this->activityManager->publish($event); - } catch (BadMethodCallException $e) { - $this->logger->warning('could not publish activity'); - $this->logger->logException($e); - } + $event = new GenericEvent($generatedToken); + $this->eventDispatcher->dispatch('app_password_created', $event); return new DataResponse([ 'apppassword' => $token diff --git a/core/Controller/ClientFlowLoginController.php b/core/Controller/ClientFlowLoginController.php index 9ca530184af..748139fe832 100644 --- a/core/Controller/ClientFlowLoginController.php +++ b/core/Controller/ClientFlowLoginController.php @@ -26,23 +26,19 @@ namespace OC\Core\Controller; -use BadMethodCallException; use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Exceptions\PasswordlessTokenException; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; -use OC\Settings\Activity\Provider; use OCA\OAuth2\Db\AccessToken; use OCA\OAuth2\Db\AccessTokenMapper; use OCA\OAuth2\Db\ClientMapper; -use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\StandaloneTemplateResponse; use OCP\Defaults; use OCP\IL10N; -use OCP\ILogger; use OCP\IRequest; use OCP\ISession; use OCP\IURLGenerator; @@ -50,6 +46,8 @@ use OCP\IUserSession; use OCP\Security\ICrypto; use OCP\Security\ISecureRandom; use OCP\Session\Exceptions\SessionNotAvailableException; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; class ClientFlowLoginController extends Controller { /** @var IUserSession */ @@ -72,10 +70,8 @@ class ClientFlowLoginController extends Controller { private $accessTokenMapper; /** @var ICrypto */ private $crypto; - /** @var IActivityManager */ - private $activityManager; - /** @var ILogger */ - private $logger; + /** @var EventDispatcherInterface */ + private $eventDispatcher; const stateName = 'client.flow.state.token'; @@ -92,8 +88,7 @@ class ClientFlowLoginController extends Controller { * @param ClientMapper $clientMapper * @param AccessTokenMapper $accessTokenMapper * @param ICrypto $crypto - * @param IActivityManager $activityManager - * @param ILogger $logger + * @param EventDispatcherInterface $eventDispatcher */ public function __construct($appName, IRequest $request, @@ -107,8 +102,7 @@ class ClientFlowLoginController extends Controller { ClientMapper $clientMapper, AccessTokenMapper $accessTokenMapper, ICrypto $crypto, - IActivityManager $activityManager, - ILogger $logger) { + EventDispatcherInterface $eventDispatcher) { parent::__construct($appName, $request); $this->userSession = $userSession; $this->l10n = $l10n; @@ -120,8 +114,7 @@ class ClientFlowLoginController extends Controller { $this->clientMapper = $clientMapper; $this->accessTokenMapper = $accessTokenMapper; $this->crypto = $crypto; - $this->activityManager = $activityManager; - $this->logger = $logger; + $this->eventDispatcher = $eventDispatcher; } /** @@ -338,20 +331,8 @@ class ClientFlowLoginController extends Controller { $this->tokenProvider->invalidateToken($sessionId); } - $event = $this->activityManager->generateEvent(); - $event->setApp('settings') - ->setType('security') - ->setAffectedUser($uid) - ->setAuthor($uid) - ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $generatedToken->getName()]) - ->setObject('app_token', $generatedToken->getId(), 'App Password'); - - try { - $this->activityManager->publish($event); - } catch (BadMethodCallException $e) { - $this->logger->warning('could not publish activity'); - $this->logger->logException($e); - } + $event = new GenericEvent($generatedToken); + $this->eventDispatcher->dispatch('app_password_created', $event); return new Http\RedirectResponse($redirectUri); } |