Beispiel #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('user');
     /** @var $user \OC\User\User */
     $user = $this->userManager->get($username);
     if (is_null($user)) {
         $output->writeln("<error>There is no user called " . $username . "</error>");
         return 1;
     }
     if ($input->isInteractive()) {
         /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
         $dialog = $this->getHelperSet()->get('dialog');
         $password = $dialog->askHiddenResponse($output, '<question>Enter a new password: </question>', false);
         $confirm = $dialog->askHiddenResponse($output, '<question>Confirm the new password: </question>', false);
         if ($password === $confirm) {
             $success = $user->setPassword($password);
             if ($success) {
                 $output->writeln("<info>Successfully reset password for " . $username . "</info>");
             } else {
                 $output->writeln("<error>Error while resetting password!</error>");
                 return 1;
             }
         } else {
             $output->writeln("<error>Passwords did not match!</error>");
             return 1;
         }
     } else {
         $output->writeln("<error>Interactive input is needed for entering a new password!</error>");
         return 1;
     }
 }
Beispiel #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $wasSuccessful = $this->userManager->get($input->getArgument('uid'))->delete();
     if ($wasSuccessful === true) {
         $output->writeln('The specified user was deleted');
         return;
     }
     $output->writeln('<error>The specified could not be deleted. Please check the logs.</error>');
 }
Beispiel #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $uid = $input->getArgument('uid');
     $user = $this->userManager->get($uid);
     if (is_null($user)) {
         $output->writeln("<error>Invalid UID</error>");
         return;
     }
     $this->manager->enableTwoFactorAuthentication($user);
     $output->writeln("Two-factor authentication enabled for user {$uid}");
 }
Beispiel #4
0
 /**
  * perform login using the magic cookie (remember login)
  *
  * @param string $uid the username
  * @param string $currentToken
  * @return bool
  */
 public function loginWithCookie($uid, $currentToken)
 {
     $this->session->regenerateId();
     $this->manager->emit('\\OC\\User', 'preRememberedLogin', array($uid));
     $user = $this->manager->get($uid);
     if (is_null($user)) {
         // user does not exist
         return false;
     }
     // get stored tokens
     $tokens = \OC::$server->getConfig()->getUserKeys($uid, 'login_token');
     // test cookies token against stored tokens
     if (!in_array($currentToken, $tokens, true)) {
         return false;
     }
     // replace successfully used token with a new one
     \OC::$server->getConfig()->deleteUserValue($uid, 'login_token', $currentToken);
     $newToken = \OC::$server->getSecureRandom()->generate(32);
     \OC::$server->getConfig()->setUserValue($uid, 'login_token', $newToken, time());
     $this->setMagicInCookie($user->getUID(), $newToken);
     //login
     $this->setUser($user);
     $this->manager->emit('\\OC\\User', 'postRememberedLogin', array($user));
     return true;
 }
Beispiel #5
0
 public function updateCard($addressBookId, $uid)
 {
     /**
      * @param \Sabre\VObject\Component\VCard $vCard
      * @param \OC\User\User $user
      */
     $user = $this->userManager->get($uid);
     $userId = $user->getUID();
     $cardId = md5($userId) . ".vcf";
     $card = $this->cardDavBackend->getCard($addressBookId, $cardId);
     if (!$card) {
         $this->insertCard($addressBookId, $uid);
     } else {
         $vCard = Reader::read($card['carddata']);
         $needsUpdate = $this->converterUser->updateCard($vCard, $user);
         if ($needsUpdate) {
             $groups = \OC::$server->getGroupManager()->getUserGroups($user);
             if ($groups) {
                 foreach ($groups as $groupName => $groupInfo) {
                     $vCard->add(new Text($vCard, 'CATEGORIES', $groupName));
                 }
             }
             $this->cardDavBackend->updateCard($addressBookId, $cardId, $vCard->serialize());
             //                $this->cardDavBackend->deleteCard($addressBookId, $cardId);
             //                $this->insertCard($addressBookId, $uid);
         }
     }
 }
Beispiel #6
0
 /**
  * Get all groups a user belongs to
  * @param string $uid Name of the user
  * @return array an array of group names
  *
  * This function fetches all groups a user belongs to. It does not check
  * if the user exists at all.
  */
 public static function getUserGroups($uid)
 {
     $user = self::$userManager->get($uid);
     if ($user) {
         return self::getManager()->getUserGroupIds($user);
     } else {
         return array();
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('user');
     /** @var $user \OC\User\User */
     $user = $this->userManager->get($username);
     if (is_null($user)) {
         $output->writeln("<error>There is no user called " . $username . "</error>");
         return 1;
     }
     if ($input->getOption('password-from-env')) {
         $password = getenv('OC_PASS');
         if (!$password) {
             $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>');
             return 1;
         }
     } elseif ($input->isInteractive()) {
         /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
         $dialog = $this->getHelperSet()->get('dialog');
         if (\OCP\App::isEnabled('files_encryption')) {
             $output->writeln('<error>Warning: Resetting the password when using encryption will result in data loss!</error>');
             if (!$dialog->askConfirmation($output, '<question>Do you want to continue?</question>', true)) {
                 return 1;
             }
         }
         $password = $dialog->askHiddenResponse($output, '<question>Enter a new password: </question>', false);
         $confirm = $dialog->askHiddenResponse($output, '<question>Confirm the new password: </question>', false);
         if ($password !== $confirm) {
             $output->writeln("<error>Passwords did not match!</error>");
             return 1;
         }
     } else {
         $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>");
         return 1;
     }
     $success = $user->setPassword($password);
     if ($success) {
         $output->writeln("<info>Successfully reset password for " . $username . "</info>");
     } else {
         $output->writeln("<error>Error while resetting password!</error>");
         return 1;
     }
 }
Beispiel #8
0
 /**
  * returns all the Users from an array that really exists
  * @param string[] $userIds an array containing user IDs
  * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value
  */
 private function getVerifiedUsers($userIds)
 {
     if (!is_array($userIds)) {
         return array();
     }
     $users = array();
     foreach ($userIds as $userId) {
         $user = $this->userManager->get($userId);
         if (!is_null($user)) {
             $users[$userId] = $user;
         }
     }
     return $users;
 }
Beispiel #9
0
 /**
  * get the login name of the current user
  *
  * @return string
  */
 public function getLoginname()
 {
     if ($this->activeUser) {
         return $this->session->get('loginname');
     } else {
         $uid = $this->session->get('user_id');
         if ($uid) {
             $this->activeUser = $this->manager->get($uid);
             return $this->session->get('loginname');
         } else {
             return null;
         }
     }
 }
Beispiel #10
0
 /**
  * @brief Get all groups a user belongs to
  * @param string $uid Name of the user
  * @return array with group names
  *
  * This function fetches all groups a user belongs to. It does not check
  * if the user exists at all.
  */
 public static function getUserGroups($uid)
 {
     $user = self::$userManager->get($uid);
     if ($user) {
         $groups = self::getManager()->getUserGroups($user);
         $groupIds = array();
         foreach ($groups as $group) {
             $groupIds[] = $group->getGID();
         }
         return $groupIds;
     } else {
         return array();
     }
 }