add Last Login column

This commit is contained in:
Arthur Schiwon 2014-02-18 18:37:10 +01:00
parent 970f899726
commit 57ffaddf26
7 changed files with 53 additions and 5 deletions

View File

@ -1087,6 +1087,7 @@ function initCore() {
$('a.action.delete').tipsy({gravity:'e', fade:true, live:true});
$('a.action').tipsy({gravity:'s', fade:true, live:true});
$('td .modified').tipsy({gravity:'s', fade:true, live:true});
$('td.lastLogin').tipsy({gravity:'s', fade:true, html:true});
$('input').tipsy({gravity:'w', fade:true});
// toggle for menus

View File

@ -882,6 +882,7 @@ class OC {
// if return is true we are logged in -> redirect to the default page
if ($return === true) {
OC_User::getManager()->get(OC_User::getUser())->updateLastLogin();
$_REQUEST['redirect_url'] = \OC_Request::requestUri();
OC_Util::redirectToDefaultPage();
exit;
@ -915,6 +916,7 @@ class OC {
$granted = OC_User::loginWithCookie(
$_COOKIE['oc_username'], $_COOKIE['oc_token']);
if($granted === true) {
OC_User::getManager()->get(OC_User::getUser())->updateLastLogin();
OC_Util::redirectToDefaultPage();
// doesn't return
}
@ -952,6 +954,7 @@ class OC {
}
$userid = OC_User::getUser();
OC_User::getManager()->get($userid)->updateLastLogin();
self::cleanupLoginTokens($userid);
if (!empty($_POST["remember_login"])) {
if (defined("DEBUG") && DEBUG) {
@ -983,6 +986,7 @@ class OC {
if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
//OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG);
OC_User::getManager()->get(OC_User::getUser())->updateLastLogin();
OC_User::unsetMagicInCookie();
$_SERVER['HTTP_REQUESTTOKEN'] = OC_Util::callRegister();
}

View File

@ -52,6 +52,11 @@ class User {
*/
private $config;
/**
* @var int $home
*/
private $lastLogin;
/**
* @param string $uid
* @param \OC_User_Interface $backend
@ -243,4 +248,19 @@ class User {
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled);
}
}
/**
* returns the timestamp of the user's last login or 0 if the user did never
* login
*
* @return int
*/
public function getLastLogin() {
return $this->lastLogin;
}
public function updateLastLogin() {
$this->lastLogin = time();
\OC_Preferences::setValue($this->uid, 'login', 'lastLogin', $this->lastLogin);
}
}

View File

@ -44,7 +44,9 @@ if (OC_User::isAdminUser(OC_User::getUser())) {
'groups' => join(', ', OC_Group::getUserGroups($uid)),
'subadmin' => join(', ', OC_SubAdmin::getSubAdminsGroups($uid)),
'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'),
'storageLocation' => $user->getHome());
'storageLocation' => $user->getHome(),
'lastLogin' => $user->getLastLogin(),
);
}
} else {
$groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
@ -56,7 +58,9 @@ if (OC_User::isAdminUser(OC_User::getUser())) {
'displayname' => $user->getDisplayName(),
'groups' => join(', ', OC_Group::getUserGroups($uid)),
'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'),
'storageLocation' => $user->getHome());
'storageLocation' => $user->getHome(),
'lastLogin' => $user->getLastLogin(),
);
}
}
OC_JSON::success(array('data' => $users));

View File

@ -125,7 +125,7 @@ var UserList = {
}
},
add: function (username, displayname, groups, subadmin, quota, storageLocation, sort) {
add: function (username, displayname, groups, subadmin, quota, storageLocation, lastLogin, sort) {
var tr = $('tbody tr').first().clone();
var subadminsEl;
var subadminSelect;
@ -185,6 +185,13 @@ var UserList = {
}
}
tr.find('td.storageLocation').text(storageLocation);
if(lastLogin == 0) {
lastLogin = t('settings', 'never');
} else {
lastLogin = new Date(lastLogin);
lastLogin = relative_modified_date(lastLogin.getTime() / 1000);
}
tr.find('td.lastLogin').text(lastLogin);
$(tr).appendTo('tbody');
if (sort) {
@ -280,7 +287,7 @@ var UserList = {
if($('tr[data-uid="' + user.name + '"]').length > 0) {
return true;
}
alert(user.storageLocation);
var tr = UserList.add(user.name, user.displayname, user.groups, user.subadmin, user.quota, user.storageLocation, user.lastLogin, false);
tr.addClass('appear transparent');
trs.push(tr);
loadedUsers++;
@ -575,7 +582,7 @@ $(document).ready(function () {
}, 10000);
}
if($('tr[data-uid="' + username + '"]').length === 0) {
UserList.add(username, username, result.data.groups, null, 'default', result.data.storageLocation, true);
UserList.add(username, username, result.data.groups, null, 'default', result.data.storageLocation, 0, true);
}
}
}

View File

@ -141,6 +141,7 @@ $_['subadmingroups'] = array_flip($items);
<?php endif;?>
<th id="headerQuota"><?php p($l->t('Quota')); ?></th>
<th id="headerStorageLocation"><?php p($l->t('Storage Location')); ?></th>
<th id="headerLastLogin"><?php p($l->t('Last Login')); ?></th>
<th id="headerRemove">&nbsp;</th>
</tr>
</thead>
@ -218,6 +219,16 @@ $_['subadmingroups'] = array_flip($items);
</select>
</td>
<td class="storageLocation"><?php p($user["storageLocation"]); ?></td>
<?php
if($user["lastLogin"] === 0) {
$lastLogin = 'never';
$lastLoginDate = '';
} else {
$lastLogin = relative_modified_date($user["lastLogin"]);
$lastLoginDate = \OC_Util::formatDate($user["lastLogin"]);
}
?>
<td class="lastLogin" title="<?php p('<span style="white-space: nowrap;">').p($lastLoginDate).p('</span>'); ?>"><?php p($lastLogin); ?></td>
<td class="remove">
<?php if($user['name']!=OC_User::getUser()):?>
<a href="#" class="action delete" original-title="<?php p($l->t('Delete'))?>">

View File

@ -76,6 +76,7 @@ foreach($accessibleusers as $uid => $displayName) {
'isQuotaUserDefined' => $isQuotaUserDefined,
'subadmin' => OC_SubAdmin::getSubAdminsGroups($uid),
'storageLocation' => $user->getHome(),
'lastLogin' => $user->getLastLogin(),
);
}