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;
$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)