summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-02-18 18:37:10 +0100
committerArthur Schiwon <blizzz@owncloud.com>2014-06-02 12:53:51 +0200
commit57ffaddf26b47a381c6b920608900dd710178323 (patch)
tree1b55d40fd1cd5ef9e939f674ab41968afbccab53
parent970f8997260606d805880192dbb389e8b196371a (diff)
downloadnextcloud-server-57ffaddf26b47a381c6b920608900dd710178323.tar.gz
nextcloud-server-57ffaddf26b47a381c6b920608900dd710178323.zip
add Last Login column
-rw-r--r--core/js/js.js1
-rw-r--r--lib/base.php4
-rw-r--r--lib/private/user/user.php20
-rw-r--r--settings/ajax/userlist.php8
-rw-r--r--settings/js/users.js13
-rw-r--r--settings/templates/users.php11
-rw-r--r--settings/users.php1
7 files changed, 53 insertions, 5 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 21a2d4c1b35..096cc3ad7c1 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -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
diff --git a/lib/base.php b/lib/base.php
index 5f2131f388f..5866c949b6e 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -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();
}
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index 8aba7188e24..82f02e0f2b5 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -53,6 +53,11 @@ class User {
private $config;
/**
+ * @var int $home
+ */
+ private $lastLogin;
+
+ /**
* @param string $uid
* @param \OC_User_Interface $backend
* @param \OC\Hooks\Emitter $emitter
@@ -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);
+ }
}
diff --git a/settings/ajax/userlist.php b/settings/ajax/userlist.php
index b73826393d9..b1c26429534 100644
--- a/settings/ajax/userlist.php
+++ b/settings/ajax/userlist.php
@@ -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));
diff --git a/settings/js/users.js b/settings/js/users.js
index f31367472a8..0068cb36414 100644
--- a/settings/js/users.js
+++ b/settings/js/users.js
@@ -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);
}
}
}
diff --git a/settings/templates/users.php b/settings/templates/users.php
index 129f01282a5..204079977a8 100644
--- a/settings/templates/users.php
+++ b/settings/templates/users.php
@@ -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'))?>">
diff --git a/settings/users.php b/settings/users.php
index e1b3083ed3e..dd0fdd80eb4 100644
--- a/settings/users.php
+++ b/settings/users.php
@@ -76,6 +76,7 @@ foreach($accessibleusers as $uid => $displayName) {
'isQuotaUserDefined' => $isQuotaUserDefined,
'subadmin' => OC_SubAdmin::getSubAdminsGroups($uid),
'storageLocation' => $user->getHome(),
+ 'lastLogin' => $user->getLastLogin(),
);
}