Пример #1
0
 /**
  * @NoAdminRequired
  * @UseSession
  *
  * @return RedirectResponse
  */
 public function logout()
 {
     $loginToken = $this->request->getCookie('oc_token');
     if (!is_null($loginToken)) {
         $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken);
     }
     $this->userSession->logout();
     return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
 }
Пример #2
0
    public function removeShare($mountPoint)
    {
        $user = $this->userSession->getUser();
        $mountPoint = $this->stripPath($mountPoint);
        $hash = md5($mountPoint);
        $query = $this->connection->prepare('
			DELETE FROM `*PREFIX*share_external`
			WHERE `mountpoint_hash` = ?
			AND `user` = ?
		');
        return (bool) $query->execute(array($hash, $user->getUID()));
    }
 /**
  * Send a mail to test the settings
  * @return array
  */
 public function sendTestMail()
 {
     $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', '');
     if (!empty($email)) {
         try {
             $this->mail->send($email, $this->userSession->getUser()->getDisplayName(), $this->l10n->t('test email settings'), $this->l10n->t('If you received this email, the settings seem to be correct.'), $this->defaultMailAddress, $this->defaults->getName());
         } catch (\Exception $e) {
             return array('data' => array('message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings.')), 'status' => 'error');
         }
         return array('data' => array('message' => (string) $this->l10n->t('Email sent')), 'status' => 'success');
     }
     return array('data' => array('message' => (string) $this->l10n->t('You need to set your user email before being able to send test emails.')), 'status' => 'error');
 }
Пример #4
0
 /**
  * @param Controller $controller
  * @param string $methodName
  */
 public function beforeController($controller, $methodName)
 {
     if ($this->reflector->hasAnnotation('PublicPage')) {
         // Don't block public pages
         return;
     }
     if ($controller instanceof \OC\Core\Controller\LoginController && $methodName === 'logout') {
         // Don't block the logout page, to allow canceling the 2FA
         return;
     }
     if ($this->userSession->isLoggedIn()) {
         $user = $this->userSession->getUser();
         if ($this->twoFactorManager->isTwoFactorAuthenticated($user)) {
             $this->checkTwoFactor($controller, $methodName);
         } else {
             if ($controller instanceof TwoFactorChallengeController) {
                 // Allow access to the two-factor controllers only if two-factor authentication
                 // is in progress.
                 throw new UserAlreadyLoggedInException();
             }
         }
     }
     // TODO: dont check/enforce 2FA if a auth token is used
 }
 /**
  * Send a mail to test the settings
  * @return array
  */
 public function sendTestMail()
 {
     $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', '');
     if (!empty($email)) {
         try {
             $message = $this->mailer->createMessage();
             $message->setTo([$email => $this->userSession->getUser()->getDisplayName()]);
             $message->setFrom([$this->defaultMailAddress]);
             $message->setSubject($this->l10n->t('test email settings'));
             $message->setPlainBody('If you received this email, the settings seem to be correct.');
             $this->mailer->send($message);
         } catch (\Exception $e) {
             return ['data' => ['message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()])], 'status' => 'error'];
         }
         return array('data' => array('message' => (string) $this->l10n->t('Email sent')), 'status' => 'success');
     }
     return array('data' => array('message' => (string) $this->l10n->t('You need to set your user email before being able to send test emails.')), 'status' => 'error');
 }
Пример #6
0
 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return array
  * @throws NotAuthenticated
  */
 private function auth(RequestInterface $request, ResponseInterface $response)
 {
     $forcedLogout = false;
     if (!$this->request->passesCSRFCheck() && $this->requiresCSRFCheck()) {
         // In case of a fail with POST we need to recheck the credentials
         if ($this->request->getMethod() === 'POST') {
             $forcedLogout = true;
         } else {
             $response->setStatus(401);
             throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.');
         }
     }
     if ($forcedLogout) {
         $this->userSession->logout();
     } else {
         if ($this->twoFactorManager->needsSecondFactor()) {
             throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
         }
         if (\OC_User::handleApacheAuth() || $this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED)) || $this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null) {
             $user = $this->userSession->getUser()->getUID();
             \OC_Util::setupFS($user);
             $this->currentUser = $user;
             $this->session->close();
             return [true, $this->principalPrefix . $user];
         }
     }
     if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
         // do not re-authenticate over ajax, use dummy auth name to prevent browser popup
         $response->addHeader('WWW-Authenticate', 'DummyBasic realm="' . $this->realm . '"');
         $response->setStatus(401);
         throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
     }
     $data = parent::check($request, $response);
     if ($data[0] === true) {
         $startPos = strrpos($data[1], '/') + 1;
         $user = $this->userSession->getUser()->getUID();
         $data[1] = substr_replace($data[1], $user, $startPos);
     }
     return $data;
 }
Пример #7
0
 /**
  * return a list of shares which are not yet accepted by the user
  *
  * @return array list of open server-to-server shares
  */
 public function getOpenShares()
 {
     $openShares = $this->connection->prepare('SELECT * FROM `*PREFIX*share_external` WHERE `accepted` = ? AND `user` = ?');
     $result = $openShares->execute(array(0, $this->userSession->getUser()->getUID()));
     return $result ? $openShares->fetchAll() : array();
 }