Skip to content

Commit

Permalink
MDL-34901 fix user login times handling
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Aug 19, 2012
1 parent 7033316 commit cf1cb68
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 3 additions & 1 deletion auth/email/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ function user_confirm($username, $confirmsecret) {

} else if ($user->secret == $confirmsecret) { // They have provided the secret key to get in
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
if ($user->firstaccess == 0) {
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
}
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
4 changes: 3 additions & 1 deletion auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ function user_confirm($username, $confirmsecret) {
return AUTH_CONFIRM_FAIL;
}
$DB->set_field('user', 'confirmed', 1, array('id'=>$user->id));
$DB->set_field('user', 'firstaccess', time(), array('id'=>$user->id));
if ($user->firstaccess == 0) {
$DB->set_field('user', 'firstaccess', time(), array('id'=>$user->id));
}
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
4 changes: 3 additions & 1 deletion auth/manual/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ function user_confirm($username, $confirmsecret = null) {
return AUTH_CONFIRM_ALREADY;
} else {
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
if ($user->firstaccess == 0) {
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
}
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
21 changes: 15 additions & 6 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3283,11 +3283,24 @@ function get_user_key($script, $userid, $instance=null, $iprestriction=null, $va
function update_user_login_times() {
global $USER, $DB;

$now = time();

$user = new stdClass();
$user->id = $USER->id;

// Make sure all users that logged in have some firstaccess.
if ($USER->firstaccess == 0) {
$USER->firstaccess = $user->firstaccess = $now;
}

// Store the previous current as lastlogin.
$USER->lastlogin = $user->lastlogin = $USER->currentlogin;
$USER->currentlogin = $user->lastaccess = $user->currentlogin = time();

$user->id = $USER->id;
$USER->currentlogin = $user->currentlogin = $now;

// Function user_accesstime_log() may not update immediately, better do it here.
$USER->lastaccess = $user->lastaccess = $now;
$USER->lastip = $user->lastip = getremoteaddr();

$DB->update_record('user', $user);
return true;
Expand Down Expand Up @@ -4074,10 +4087,6 @@ function authenticate_user_login($username, $password) {
$DB->set_field('user', 'auth', $auth, array('username'=>$username));
$user->auth = $auth;
}
if (empty($user->firstaccess)) { //prevent firstaccess from remaining 0 for manual account that never required confirmation
$DB->set_field('user','firstaccess', $user->timemodified, array('id' => $user->id));
$user->firstaccess = $user->timemodified;
}

update_internal_user_password($user, $password); // just in case salt or encoding were changed (magic quotes too one day)

Expand Down

0 comments on commit cf1cb68

Please sign in to comment.