]> source.dussan.org Git - nextcloud-server.git/commitdiff
add Last Login column
authorArthur Schiwon <blizzz@owncloud.com>
Tue, 18 Feb 2014 17:37:10 +0000 (18:37 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Mon, 2 Jun 2014 10:53:51 +0000 (12:53 +0200)
core/js/js.js
lib/base.php
lib/private/user/user.php
settings/ajax/userlist.php
settings/js/users.js
settings/templates/users.php
settings/users.php

index 21a2d4c1b35c5317e29bfb91625c17585cae7d0e..096cc3ad7c137fe8ad1e4bc9ce525803975500e2 100644 (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
index 5f2131f388f4b790619e21ca79da39c20a72e829..5866c949b6ed02dcdf60fecfd5a6c30deda9d3fb 100644 (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();
                }
index 8aba7188e24feaed711b1710d6765afa91c28206..82f02e0f2b55be32de6cd1616d8335ff04218b50 100644 (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);
+       }
 }
index b73826393d972ce5b306bdc5ca6f011598f325be..b1c26429534f6ea5b2008de622e0e31b37517d43 100644 (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));
index f31367472a8f2d93adb8b22183b0040405bd90bf..0068cb3641422ee7603c8c324805f236da70940b 100644 (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);
                                        }
                                }
                        }
index 129f01282a5dda479950c2ac63abe78f989efc8a..204079977a83c8a4b86bdaa1db7af2f4c62af332 100644 (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'))?>">
index e1b3083ed3e3b2ca0e2fe00a7e8c2de6100fec2f..dd0fdd80eb4ea7960f7030d49398f89cc350a31e 100644 (file)
@@ -76,6 +76,7 @@ foreach($accessibleusers as $uid => $displayName) {
                'isQuotaUserDefined' => $isQuotaUserDefined,
                'subadmin' => OC_SubAdmin::getSubAdminsGroups($uid),
                'storageLocation' => $user->getHome(),
+               'lastLogin' => $user->getLastLogin(),
        );
 }