-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First login event #26206
Merged
Merged
First login event #26206
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
baaaec7
Introduce an event for first time login based on the last login time …
DeepDiver1975 6c8d3ce
Use firstLogin event to trigger creation of default calendar and defa…
DeepDiver1975 8b064e1
Delay login of admin user after setup so that firstLogin event can pr…
DeepDiver1975 12b00a2
Fixing tests ...
DeepDiver1975 7652e66
Skeleton files are not copied over -> only 3 cache entries are remaining
DeepDiver1975 a68d631
Use updateLastLoginTimestamp to properly setup lastLogin value for a …
DeepDiver1975 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
use OCP\IUserSession; | ||
use OCP\Session\Exceptions\SessionNotAvailableException; | ||
use OCP\Util; | ||
use Symfony\Component\EventDispatcher\GenericEvent; | ||
|
||
/** | ||
* Class Session | ||
|
@@ -371,15 +372,25 @@ public function isTokenPassword($password) { | |
} | ||
} | ||
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose we can also leverage this to avoid syncing the whole LDAP profile every time a LDAP user logs in ? (something to discuss separately) CC @butonic |
||
// 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 @@ private function loginWithPassword($uid, $password) { | |
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 @@ public function loginWithCookie($uid, $currentToken) { | |
|
||
//login | ||
$this->setUser($user); | ||
$user->updateLastLoginTimestamp(); | ||
$this->manager->emit('\OC\User', 'postRememberedLogin', [$user]); | ||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉