Example #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'));
 }
Example #2
0
 /**
  * Set the mail address of a user
  *
  * @NoAdminRequired
  * @NoSubadminRequired
  *
  * @param string $id
  * @param string $mailAddress
  * @return DataResponse
  */
 public function setMailAddress($id, $mailAddress)
 {
     $userId = $this->userSession->getUser()->getUID();
     $user = $this->userManager->get($id);
     if ($userId !== $id && !$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
         return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Forbidden'))), Http::STATUS_FORBIDDEN);
     }
     if ($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
         return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Invalid mail address'))), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if (!$user) {
         return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Invalid user'))), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     // this is the only permission a backend provides and is also used
     // for the permission of setting a email address
     if (!$user->canChangeDisplayName()) {
         return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Unable to change mail address'))), Http::STATUS_FORBIDDEN);
     }
     // delete user value if email address is empty
     if ($mailAddress === '') {
         $this->config->deleteUserValue($id, 'settings', 'email');
     } else {
         $this->config->setUserValue($id, 'settings', 'email', $mailAddress);
     }
     return new DataResponse(array('status' => 'success', 'data' => array('username' => $id, 'mailAddress' => $mailAddress, 'message' => (string) $this->l10n->t('Email saved'))), Http::STATUS_OK);
 }
 /**
  * @PublicPage
  * @param string $token
  * @param string $userId
  * @param string $password
  * @param boolean $proceed
  * @return array
  */
 public function setPassword($token, $userId, $password, $proceed)
 {
     if ($this->isDataEncrypted && !$proceed) {
         return $this->error('', array('encryption' => true));
     }
     try {
         $user = $this->userManager->get($userId);
         $splittedToken = explode(':', $this->config->getUserValue($userId, 'owncloud', 'lostpassword', null));
         if (count($splittedToken) !== 2) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
         }
         if ($splittedToken[0] < $this->timeFactory->getTime() - 60 * 60 * 12 || $user->getLastLogin() > $splittedToken[0]) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired'));
         }
         if (!StringUtils::equals($splittedToken[1], $token)) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
         }
         if (!$user->setPassword($password)) {
             throw new \Exception();
         }
         \OC_Hook::emit('\\OC\\Core\\LostPassword\\Controller\\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password));
         $this->config->deleteUserValue($userId, 'owncloud', 'lostpassword');
         @\OC_User::unsetMagicInCookie();
     } catch (\Exception $e) {
         return $this->error($e->getMessage());
     }
     return $this->success();
 }
Example #4
0
 /**
  * update database
  */
 public function updateDB()
 {
     // make sure that we don't update the file cache multiple times
     // only update during the first run
     if ($this->installedVersion === '-1') {
         return;
     }
     // delete left-over from old encryption which is no longer needed
     $this->config->deleteAppValue('files_encryption', 'ocsid');
     $this->config->deleteAppValue('files_encryption', 'types');
     $this->config->deleteAppValue('files_encryption', 'enabled');
     $oldAppValues = $this->connection->createQueryBuilder();
     $oldAppValues->select('*')->from('`*PREFIX*appconfig`')->where($oldAppValues->expr()->eq('`appid`', ':appid'))->setParameter('appid', 'files_encryption');
     $appSettings = $oldAppValues->execute();
     while ($row = $appSettings->fetch()) {
         // 'installed_version' gets deleted at the end of the migration process
         if ($row['configkey'] !== 'installed_version') {
             $this->config->setAppValue('encryption', $row['configkey'], $row['configvalue']);
             $this->config->deleteAppValue('files_encryption', $row['configkey']);
         }
     }
     $oldPreferences = $this->connection->createQueryBuilder();
     $oldPreferences->select('*')->from('`*PREFIX*preferences`')->where($oldPreferences->expr()->eq('`appid`', ':appid'))->setParameter('appid', 'files_encryption');
     $preferenceSettings = $oldPreferences->execute();
     while ($row = $preferenceSettings->fetch()) {
         $this->config->setUserValue($row['userid'], 'encryption', $row['configkey'], $row['configvalue']);
         $this->config->deleteUserValue($row['userid'], 'files_encryption', $row['configkey']);
     }
 }
Example #5
0
 /**
  * set the email address of the user
  *
  * @param string|null $mailAddress
  * @return void
  * @since 9.0.0
  */
 public function setEMailAddress($mailAddress)
 {
     if ($mailAddress === '') {
         $this->config->deleteUserValue($this->uid, 'settings', 'email');
     } else {
         $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
     }
     $this->triggerChange('eMailAddress', $mailAddress);
 }
Example #6
0
 /**
  * set the email address of the user
  *
  * @param string|null $mailAddress
  * @return void
  * @since 9.0.0
  */
 public function setEMailAddress($mailAddress)
 {
     if ($mailAddress === '') {
         $this->config->deleteUserValue($this->uid, 'settings', 'email');
     } else {
         $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
     }
     if ($this->emitter) {
         $this->emitter->emit('\\OC\\User', 'changeUser', array($this));
     }
 }
 /**
  * @PublicPage
  * @param string $token
  * @param string $userId
  * @param string $password
  * @param boolean $proceed
  * @return array
  */
 public function setPassword($token, $userId, $password, $proceed)
 {
     if ($this->isDataEncrypted && !$proceed) {
         return $this->error('', array('encryption' => true));
     }
     try {
         $this->checkPasswordResetToken($token, $userId);
         $user = $this->userManager->get($userId);
         if (!$user->setPassword($password)) {
             throw new \Exception();
         }
         \OC_Hook::emit('\\OC\\Core\\LostPassword\\Controller\\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password));
         $this->config->deleteUserValue($userId, 'owncloud', 'lostpassword');
         @\OC_User::unsetMagicInCookie();
     } catch (\Exception $e) {
         return $this->error($e->getMessage());
     }
     return $this->success();
 }
Example #8
0
 /**
  * update database
  */
 public function updateDB()
 {
     // delete left-over from old encryption which is no longer needed
     $this->config->deleteAppValue('files_encryption', 'ocsid');
     $this->config->deleteAppValue('files_encryption', 'types');
     $this->config->deleteAppValue('files_encryption', 'enabled');
     $oldAppValues = $this->connection->getQueryBuilder();
     $oldAppValues->select('*')->from('*PREFIX*appconfig')->where($oldAppValues->expr()->eq('appid', $oldAppValues->createParameter('appid')))->setParameter('appid', 'files_encryption');
     $appSettings = $oldAppValues->execute();
     while ($row = $appSettings->fetch()) {
         // 'installed_version' gets deleted at the end of the migration process
         if ($row['configkey'] !== 'installed_version') {
             $this->config->setAppValue('encryption', $row['configkey'], $row['configvalue']);
             $this->config->deleteAppValue('files_encryption', $row['configkey']);
         }
     }
     $oldPreferences = $this->connection->getQueryBuilder();
     $oldPreferences->select('*')->from('*PREFIX*preferences')->where($oldPreferences->expr()->eq('appid', $oldPreferences->createParameter('appid')))->setParameter('appid', 'files_encryption');
     $preferenceSettings = $oldPreferences->execute();
     while ($row = $preferenceSettings->fetch()) {
         $this->config->setUserValue($row['userid'], 'encryption', $row['configkey'], $row['configvalue']);
         $this->config->deleteUserValue($row['userid'], 'files_encryption', $row['configkey']);
     }
 }
Example #9
0
 /**
  * Deletes a key
  * @param string $user user
  * @param string $app app
  * @param string $key key
  * @deprecated use deleteUserValue of \OCP\IConfig instead
  *
  * Deletes a key.
  */
 public function deleteKey($user, $app, $key)
 {
     $this->config->deleteUserValue($user, $app, $key);
 }
Example #10
0
 /**
  * Enable all 2FA checks for the given user
  *
  * @param IUser $user
  */
 public function enableTwoFactorAuthentication(IUser $user)
 {
     $this->config->deleteUserValue($user->getUID(), 'core', 'two_factor_auth_disabled');
 }