Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
baaaec77
Unverified
Commit
baaaec77
authored
Sep 23, 2016
by
Thomas Müller
Browse files
Introduce an event for first time login based on the last login time stamp
parent
11c30fce
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/private/Files/Node/Root.php
View file @
baaaec77
...
...
@@ -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
;
...
...
lib/private/User/Manager.php
View file @
baaaec77
...
...
@@ -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
();
});
}
/**
...
...
lib/private/User/Session.php
View file @
baaaec77
...
...
@@ -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
;
}
...
...
lib/private/User/User.php
View file @
baaaec77
...
...
@@ -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
->
getC
onfig
()
->
setUserValue
(
$this
->
c
onfig
->
setUserValue
(
$this
->
uid
,
'login'
,
'lastLogin'
,
$this
->
lastLogin
);
return
$firstTimeLogin
;
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment