aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-05-23 10:37:34 +0200
committerArthur Schiwon <blizzz@owncloud.com>2014-05-23 10:37:34 +0200
commit09bb8e0e3a9ba2213f3c2bd9774bbfb1502b7be5 (patch)
tree0d9ef1a46951e31cbe8fb5f59af2e1ccba95a51b /core
parent86880acee9a5a4887884f6095ecfe90e32e1e5d3 (diff)
downloadnextcloud-server-09bb8e0e3a9ba2213f3c2bd9774bbfb1502b7be5.tar.gz
nextcloud-server-09bb8e0e3a9ba2213f3c2bd9774bbfb1502b7be5.zip
add cli command to check a users last login
Diffstat (limited to 'core')
-rw-r--r--core/command/user/lastseen.php47
-rw-r--r--core/register_command.php1
2 files changed, 48 insertions, 0 deletions
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 @@
+<?php
+/**
+ * Copyright (c) 2014 Arthur Schiwon <blizzz@owncloud.com>
+ * 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'));
+ }
+ }
+}
diff --git a/core/register_command.php b/core/register_command.php
index f1361c859fc..dfb5134eff9 100644
--- a/core/register_command.php
+++ b/core/register_command.php
@@ -17,3 +17,4 @@ $application->add(new OC\Core\Command\App\Enable());
$application->add(new OC\Core\Command\App\ListApps());
$application->add(new OC\Core\Command\Maintenance\Repair(new \OC\Repair()));
$application->add(new OC\Core\Command\User\Report());
+$application->add(new OC\Core\Command\User\LastSeen());