From 09bb8e0e3a9ba2213f3c2bd9774bbfb1502b7be5 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 23 May 2014 10:37:34 +0200 Subject: add cli command to check a users last login --- core/command/user/lastseen.php | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 core/command/user/lastseen.php (limited to 'core/command/user') diff --git a/core/command/user/lastseen.php b/core/command/user/lastseen.php new file mode 100644 index 00000000000..bf5914b2cde --- /dev/null +++ b/core/command/user/lastseen.php @@ -0,0 +1,47 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\Command\User; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputArgument; + +class LastSeen extends Command { + protected function configure() { + $this + ->setName('user:lastseen') + ->setDescription('shows when the user was logged it last time') + ->addArgument( + 'uid', + InputArgument::REQUIRED, + 'the username' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $userManager = \OC::$server->getUserManager(); + $user = $userManager->get($input->getArgument('uid')); + if(is_null($user)) { + $output->writeln('User does not exist'); + return; + } + + $lastLogin = $user->getLastLogin(); + if($lastLogin === 0) { + $output->writeln('User ' . $user->getUID() . + ' has never logged in, yet.'); + } else { + $date = new \DateTime(); + $date->setTimestamp($lastLogin); + $output->writeln($user->getUID() . '`s ' . + ' last login: ' . $date->format('d.m.Y h:i')); + } + } +} -- cgit v1.2.3 From e9fa74bfb791796ec53b1129c3e20cdcccc9aa49 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 23 May 2014 10:55:54 +0200 Subject: save a whitespace --- core/command/user/lastseen.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/command/user') diff --git a/core/command/user/lastseen.php b/core/command/user/lastseen.php index bf5914b2cde..b2788c00305 100644 --- a/core/command/user/lastseen.php +++ b/core/command/user/lastseen.php @@ -40,8 +40,8 @@ class LastSeen extends Command { } else { $date = new \DateTime(); $date->setTimestamp($lastLogin); - $output->writeln($user->getUID() . '`s ' . - ' last login: ' . $date->format('d.m.Y h:i')); + $output->writeln($user->getUID() . + '`s last login: ' . $date->format('d.m.Y h:i')); } } } -- cgit v1.2.3 From 7f7999c7d870c1024246cd49917554513cbab76b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 23 May 2014 19:12:51 +0200 Subject: print time in 24h format --- core/command/user/lastseen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/command/user') diff --git a/core/command/user/lastseen.php b/core/command/user/lastseen.php index b2788c00305..7a8db013e3a 100644 --- a/core/command/user/lastseen.php +++ b/core/command/user/lastseen.php @@ -41,7 +41,7 @@ class LastSeen extends Command { $date = new \DateTime(); $date->setTimestamp($lastLogin); $output->writeln($user->getUID() . - '`s last login: ' . $date->format('d.m.Y h:i')); + '`s last login: ' . $date->format('d.m.Y H:i')); } } } -- cgit v1.2.3