Skip to content
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

Record login timestamp per user. Required for new user managament. #8681

Merged
merged 13 commits into from
May 28, 2014

Conversation

blizzz
Copy link
Contributor

@blizzz blizzz commented May 23, 2014

This PR cleans up the tryRememberLogin method first, moves the core part to the user session and also adds tests for it. This is necessary, because we need to record the timestamp as well, when a magic cookie (remember checkbox active) is used. The \OC\User\User object gets method to update and return the login timestamp. Updating the timestamp is triggered by postLogin and postRememberedLogin (new!) events. I tested it for login via web interface, remember cookie and desktop client.

There is also a command line tool to get the last login of a specific user. Example:

$ ./occ user:lastseen master
master`s last login: 23.05.2014 08:48

This PR is required for new user management in #7151.

Please test/review @LukasReschke @icewind1991 @DeepDiver1975

@karlitschek
Copy link
Contributor

👍

@blizzz
Copy link
Contributor Author

blizzz commented May 23, 2014

@DeepDiver1975 IIRC you wanted to check this with Apache or another way of auth'ing?

self::cleanupLoginTokens($_COOKIE['oc_username']);
// get stored tokens
$tokens = OC_Preferences::getKeys($_COOKIE['oc_username'], 'login_token');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did that code goto? OC_User::loginWithCookie?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to lib/private/user/session.php line 188 (invoked by OC_User::loginWithCookie)

@ghost
Copy link

ghost commented May 23, 2014

🚀 Test Passed. 🚀
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/4959/

@ghost
Copy link

ghost commented May 23, 2014

💣 Test Failed. 💣
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/4960/

@blizzz
Copy link
Contributor Author

blizzz commented May 23, 2014

»Test Result (no failures)«

@blizzz blizzz added this to the ownCloud 7 milestone May 23, 2014
@icewind1991
Copy link
Contributor

Tested, code looks good 👍

@blizzz
Copy link
Contributor Author

blizzz commented May 23, 2014

Oh, i found one minor thing. The hour was given in 12h format but without am/pm indicator. Now its 24h format. So last commit changed just the case of one letter :)

@ghost
Copy link

ghost commented May 23, 2014

💣 Test Failed. 💣
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/4986/

@blizzz
Copy link
Contributor Author

blizzz commented May 23, 2014

Still no failures, why the script dos not return 0 is

16:22:43 npm ERR! Failed to parse json
16:22:43 npm ERR! Unexpected end of input
16:22:43 npm ERR! File: /var/lib/jenkins/.npm/karma-phantomjs-launcher/0.1.4/package/package.json

tests are fine

@LukasReschke
Copy link
Member

Can we use this opportunity to rename the functions to something saner than magic cookie? - It's absolutely unusual named and hard to understand. (Remember me, Remember, whatever..)

$lastLogin = $user->getLastLogin();
if($lastLogin === 0) {
$output->writeln('User ' . $user->getUID() .
' has never logged in, yet.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That statement is not entirely correct as this could also be triggered if an user has only not logged in since this feature has been added.

It may give the administrator a plausible misbelieve that the user has never logged in while this is not the case. Can we adjust this somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"has never logged in, yet." → "has never logged in (since availability of ownCloud 7.0.0)."

OK?

/**
* updates the timestamp of the most recent login of this user
*
* @return null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this returns void and not null. Therefore the @return statement can be dropped.

See http://www.phpdoc.org/docs/latest/for-users/phpdoc/tags/return.html:

It is RECOMMENDED when documenting to use this tag with every function and method. Exceptions to this recommendation are:

  • constructors, the @return tag MAY be omitted here, in which case @return self is implied.
  • functions and methods without a return value, the @return tag MAY be omitted here, in which case @return void is implied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no specific return is done (→ void) null will be returned, anyway, but I get the point and will drop it.

@LukasReschke
Copy link
Member

I haven't properly tested this yet. Please don't merge.

@ghost
Copy link

ghost commented May 24, 2014

💣 Test Failed. 💣
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/4996/

@blizzz
Copy link
Contributor Author

blizzz commented May 26, 2014

Can we use this opportunity to rename the functions to something saner than magic cookie? - It's absolutely unusual named and hard to understand. (Remember me, Remember, whatever..)

It would effect other files as well (e.g. core/lostpassword/controller.php, tests/autotest-clover-sqlite.xml), while I have nothing against changing the name I would prefer not to do it in this PR.

@blizzz
Copy link
Contributor Author

blizzz commented May 26, 2014

Regarding the client: when launched the login timestamp will be updated, but as long as the client is running, even through days and suspending the laptop, the timestamp is not being updated.

How is the client keeping the authentication? @DeepDiver1975 @danimo

@DeepDiver1975
Copy link
Member

How is the client keeping the authentication? @DeepDiver1975 @danimo

Desktop clients use the same session mechanisms as the browser does.
But the mobile apps (as long as not authenticating via shibboleth) still use basic auth, which would trigger a login on every request

@scrutinizer-notifier
Copy link

The inspection completed: 6 new issues, 11 updated code elements

@ghost
Copy link

ghost commented May 26, 2014

🚀 Test Passed. 🚀
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/5022/

@blizzz
Copy link
Contributor Author

blizzz commented May 26, 2014

@DeepDiver1975 right, makes sense, i set back the session life time to default. In that case it probably make sense to check the timestamp on session regenerate too, and update it when the old one is > 24hrs (resp. session lifetime) ago.

@blizzz
Copy link
Contributor Author

blizzz commented May 28, 2014

@LukasReschke when you look into your crystal ball, can you see when you do proper testing?

@LukasReschke
Copy link
Member

@LukasReschke when you look into your crystal ball, can you see when you do proper testing?

My crystal ball says tomorrow 18:00 CET - at latest ;-)

@blizzz
Copy link
Contributor Author

blizzz commented May 28, 2014

k, cool, thx

@LukasReschke
Copy link
Member

🔮 said to me that I should 👍 this.

LukasReschke added a commit that referenced this pull request May 28, 2014
Record login timestamp per user. Required for new user managament.
@LukasReschke LukasReschke merged commit ce9d5df into master May 28, 2014
@LukasReschke LukasReschke deleted the logintimestamp branch May 28, 2014 17:06
@blizzz
Copy link
Contributor Author

blizzz commented May 28, 2014

thank you @:crystal_ball: and @LukasReschke

blizzz added a commit that referenced this pull request Jun 2, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Aug 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants