Skip to content

Commit

Permalink
Merge pull request #31963 from owncloud/symfony-events-for-login
Browse files Browse the repository at this point in the history
Add symfony events for login action
  • Loading branch information
sharidas authored Jul 5, 2018
2 parents 615ba79 + 7d7ced3 commit dc0d8a6
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 105 deletions.
12 changes: 10 additions & 2 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public function tryBasicAuthLogin(IRequest $request) {
* compatibility.
*/
private function loginWithPassword($login, $password) {
$beforeEvent = new GenericEvent(null, ['login' => $login, 'uid' => $login, '_uid' => 'deprecated: please use \'login\', the real uid is not yet known', 'password' => $password]);
$beforeEvent = new GenericEvent(null, ['loginType' => 'password', 'login' => $login, 'uid' => $login, '_uid' => 'deprecated: please use \'login\', the real uid is not yet known', 'password' => $password]);
$this->eventDispatcher->dispatch('user.beforelogin', $beforeEvent);
$this->manager->emit('\OC\User', 'preLogin', [$login, $password]);

Expand All @@ -520,7 +520,7 @@ private function loginWithPassword($login, $password) {
if ($this->isLoggedIn()) {
$this->prepareUserLogin($firstTimeLogin);

$afterEvent = new GenericEvent(null, ['user' => $user, 'uid' => $user->getUID(), 'password' => $password]);
$afterEvent = new GenericEvent(null, ['loginType' => 'password', 'user' => $user, 'uid' => $user->getUID(), 'password' => $password]);
$this->eventDispatcher->dispatch('user.afterlogin', $afterEvent);

return true;
Expand Down Expand Up @@ -561,6 +561,8 @@ private function loginWithToken($token) {
}

$this->manager->emit('\OC\User', 'preLogin', [$uid, $password]);
$beforeEvent = new GenericEvent(null, ['loginType' => 'token', 'login' => $uid, 'password' => $password]);
$this->eventDispatcher->dispatch('user.beforelogin', $beforeEvent);

$user = $this->manager->get($uid);
if ($user === null) {
Expand All @@ -579,6 +581,8 @@ private function loginWithToken($token) {
$this->setUser($user);
$this->setLoginName($dbToken->getLoginName());
$this->manager->emit('\OC\User', 'postLogin', [$user, $password]);
$afterEvent = new GenericEvent(null, ['loginType' => 'token', 'user' => $user, 'login' => $user->getUID(), 'password' => $password]);
$this->eventDispatcher->dispatch('user.afterlogin', $afterEvent);

if ($this->isLoggedIn()) {
$this->prepareUserLogin();
Expand Down Expand Up @@ -632,6 +636,8 @@ public function loginWithApache(IApacheBackend $apacheBackend) {
$this->session->regenerateId();

$this->manager->emit('\OC\User', 'preLogin', [$uid, '']);
$beforeEvent = new GenericEvent(null, ['loginType' => 'apache', 'login' => $uid, 'password' => '']);
$this->eventDispatcher->dispatch('user.beforelogin', $beforeEvent);

// Die here if not valid
if (!$apacheBackend->isSessionActive()) {
Expand Down Expand Up @@ -663,6 +669,8 @@ public function loginWithApache(IApacheBackend $apacheBackend) {

$firstTimeLogin = $user->updateLastLoginTimestamp();
$this->manager->emit('\OC\User', 'postLogin', [$user, '']);
$afterEvent = new GenericEvent(null, ['loginType' => 'apache', 'user' => $user, 'login' => $user->getUID(), 'password' => '']);
$this->eventDispatcher->dispatch('user.afterlogin', $afterEvent);
if ($this->isLoggedIn()) {
$this->prepareUserLogin($firstTimeLogin);
return true;
Expand Down
Loading

0 comments on commit dc0d8a6

Please sign in to comment.