Unverified Commit baaaec77 authored by Thomas Müller's avatar Thomas Müller
Browse files

Introduce an event for first time login based on the last login time stamp

parent 11c30fce
......@@ -349,7 +349,6 @@ class Root extends Folder implements IRootFolder {
$folder = $folder->get($dir);
} catch (NotFoundException $e) {
$folder = $folder->newFolder($dir);
\OC_Util::copySkeleton($userId, $folder);
}
return $folder;
......
......@@ -78,14 +78,6 @@ class Manager extends PublicEmitter implements IUserManager {
/** @var \OC\User\User $user */
unset($cachedUsers[$user->getUID()]);
});
$this->listen('\OC\User', 'postLogin', function ($user) {
/** @var \OC\User\User $user */
$user->updateLastLoginTimestamp();
});
$this->listen('\OC\User', 'postRememberedLogin', function ($user) {
/** @var \OC\User\User $user */
$user->updateLastLoginTimestamp();
});
}
/**
......
......@@ -49,6 +49,7 @@ use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Session\Exceptions\SessionNotAvailableException;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class Session
......@@ -371,15 +372,25 @@ class Session implements IUserSession, Emitter {
}
}
protected function prepareUserLogin() {
protected function prepareUserLogin($firstTimeLogin) {
// TODO: mock/inject/use non-static
// Refresh the token
\OC::$server->getCsrfTokenManager()->refreshToken();
//we need to pass the user name, which may differ from login name
$user = $this->getUser()->getUID();
OC_Util::setupFS($user);
//trigger creation of user home and /files folder
\OC::$server->getUserFolder($user);
if ($firstTimeLogin) {
// TODO: lock necessary?
//trigger creation of user home and /files folder
$userFolder = \OC::$server->getUserFolder($user);
// copy skeleton
\OC_Util::copySkeleton($user, $userFolder);
// trigger any other initialization
\OC::$server->getEventDispatcher()->dispatch(IUser::class . '::firstLogin', new GenericEvent($this->getUser()));
}
}
/**
......@@ -431,9 +442,10 @@ class Session implements IUserSession, Emitter {
if ($user->isEnabled()) {
$this->setUser($user);
$this->setLoginName($uid);
$firstTimeLogin = $user->updateLastLoginTimestamp();
$this->manager->emit('\OC\User', 'postLogin', [$user, $password]);
if ($this->isLoggedIn()) {
$this->prepareUserLogin();
$this->prepareUserLogin($firstTimeLogin);
return true;
} else {
// injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
......@@ -688,6 +700,7 @@ class Session implements IUserSession, Emitter {
//login
$this->setUser($user);
$user->updateLastLoginTimestamp();
$this->manager->emit('\OC\User', 'postRememberedLogin', [$user]);
return true;
}
......
......@@ -180,9 +180,12 @@ class User implements IUser {
* updates the timestamp of the most recent login of this user
*/
public function updateLastLoginTimestamp() {
$firstTimeLogin = ($this->lastLogin === 0);
$this->lastLogin = time();
\OC::$server->getConfig()->setUserValue(
$this->config->setUserValue(
$this->uid, 'login', 'lastLogin', $this->lastLogin);
return $firstTimeLogin;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment