public static function renameDocument($args) { $fileId = intval(@$args['file_id']); $name = @$_POST['name']; $file = new File($fileId); $l = new \OC_L10n('documents'); if (isset($name) && $file->getPermissions() & \OCP\PERMISSION_UPDATE) { if ($file->renameTo($name)) { // TODO: propagate to other clients \OCP\JSON::success(); return; } } \OCP\JSON::error(array('message' => $l->t('You don\'t have permission to rename this document'))); }
public static function changeUserPassword($args) { // Check if we are an user \OC_JSON::callCheck(); \OC_JSON::checkLoggedIn(); $l = new \OC_L10n('settings'); if (isset($_POST['username'])) { $username = $_POST['username']; } else { \OC_JSON::error(array('data' => array('message' => $l->t('No user supplied')))); exit; } $password = isset($_POST['password']) ? $_POST['password'] : null; $recoveryPassword = isset($_POST['recoveryPassword']) ? $_POST['recoveryPassword'] : null; $isUserAccessible = false; $currentUserObject = \OC::$server->getUserSession()->getUser(); $targetUserObject = \OC::$server->getUserManager()->get($username); if ($currentUserObject !== null && $targetUserObject !== null) { $isUserAccessible = \OC::$server->getGroupManager()->getSubAdmin()->isUserAccessible($currentUserObject, $targetUserObject); } if (\OC_User::isAdminUser(\OC_User::getUser())) { $userstatus = 'admin'; } elseif ($isUserAccessible) { $userstatus = 'subadmin'; } else { \OC_JSON::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } if (\OC_App::isEnabled('encryption')) { //handle the recovery case $crypt = new \OCA\Encryption\Crypto\Crypt(\OC::$server->getLogger(), \OC::$server->getUserSession(), \OC::$server->getConfig(), \OC::$server->getL10N('encryption')); $keyStorage = \OC::$server->getEncryptionKeyStorage(); $util = new \OCA\Encryption\Util(new \OC\Files\View(), $crypt, \OC::$server->getLogger(), \OC::$server->getUserSession(), \OC::$server->getConfig(), \OC::$server->getUserManager()); $keyManager = new \OCA\Encryption\KeyManager($keyStorage, $crypt, \OC::$server->getConfig(), \OC::$server->getUserSession(), new \OCA\Encryption\Session(\OC::$server->getSession()), \OC::$server->getLogger(), $util); $recovery = new \OCA\Encryption\Recovery(\OC::$server->getUserSession(), $crypt, \OC::$server->getSecureRandom(), $keyManager, \OC::$server->getConfig(), $keyStorage, \OC::$server->getEncryptionFilesHelper(), new \OC\Files\View()); $recoveryAdminEnabled = $recovery->isRecoveryKeyEnabled(); $validRecoveryPassword = false; $recoveryEnabledForUser = false; if ($recoveryAdminEnabled) { $validRecoveryPassword = $keyManager->checkRecoveryPassword($recoveryPassword); $recoveryEnabledForUser = $recovery->isRecoveryEnabledForUser($username); } if ($recoveryEnabledForUser && $recoveryPassword === '') { \OC_JSON::error(array('data' => array('message' => $l->t('Please provide an admin recovery password, otherwise all user data will be lost')))); } elseif ($recoveryEnabledForUser && !$validRecoveryPassword) { \OC_JSON::error(array('data' => array('message' => $l->t('Wrong admin recovery password. Please check the password and try again.')))); } else { // now we know that everything is fine regarding the recovery password, let's try to change the password $result = \OC_User::setPassword($username, $password, $recoveryPassword); if (!$result && $recoveryEnabledForUser) { \OC_JSON::error(array("data" => array("message" => $l->t("Backend doesn't support password change, but the user's encryption key was successfully updated.")))); } elseif (!$result && !$recoveryEnabledForUser) { \OC_JSON::error(array("data" => array("message" => $l->t("Unable to change password")))); } else { \OC_JSON::success(array("data" => array("username" => $username))); } } } else { // if encryption is disabled, proceed if (!is_null($password) && \OC_User::setPassword($username, $password)) { \OC_JSON::success(array('data' => array('username' => $username))); } else { \OC_JSON::error(array('data' => array('message' => $l->t('Unable to change password')))); } } }
public static function unFavorite($args) { $tagger = self::getTagger($args['type']); if (!$tagger->removeFromFavorites($args['id'])) { $l = new \OC_L10n('core'); \OC_JSON::error(array('message' => $l->t('Error unfavoriting'))); } else { \OC_JSON::success(); } }
public static function changeUserPassword($args) { // Check if we are an user \OC_JSON::callCheck(); \OC_JSON::checkLoggedIn(); // Manually load apps to ensure hooks work correctly (workaround for issue 1503) \OC_App::loadApps(); if (isset($_POST['username'])) { $username = $_POST['username']; } else { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('No user supplied')))); exit; } $password = isset($_POST['password']) ? $_POST['password'] : null; $recoveryPassword = isset($_POST['recoveryPassword']) ? $_POST['recoveryPassword'] : null; if (\OC_User::isAdminUser(\OC_User::getUser())) { $userstatus = 'admin'; } elseif (\OC_SubAdmin::isUserAccessible(\OC_User::getUser(), $username)) { $userstatus = 'subadmin'; } else { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } if (\OC_App::isEnabled('files_encryption')) { //handle the recovery case $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), $username); $recoveryAdminEnabled = \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'); $validRecoveryPassword = false; $recoveryPasswordSupported = false; if ($recoveryAdminEnabled) { $validRecoveryPassword = $util->checkRecoveryPassword($recoveryPassword); $recoveryEnabledForUser = $util->recoveryEnabledForUser(); } if ($recoveryEnabledForUser && $recoveryPassword === '') { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('Please provide an admin recovery password, otherwise all user data will be lost')))); } elseif ($recoveryEnabledForUser && !$validRecoveryPassword) { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('Wrong admin recovery password. Please check the password and try again.')))); } else { // now we know that everything is fine regarding the recovery password, let's try to change the password $result = \OC_User::setPassword($username, $password, $recoveryPassword); if (!$result && $recoveryPasswordSupported) { $l = new \OC_L10n('settings'); \OC_JSON::error(array("data" => array("message" => $l->t("Back-end doesn't support password change, but the users encryption key was successfully updated.")))); } elseif (!$result && !$recoveryPasswordSupported) { $l = new \OC_L10n('settings'); \OC_JSON::error(array("data" => array("message" => $l->t("Unable to change password")))); } else { \OC_JSON::success(array("data" => array("username" => $username))); } } } else { // if encryption is disabled, proceed if (!is_null($password) && \OC_User::setPassword($username, $password)) { \OC_JSON::success(array('data' => array('username' => $username))); } else { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('Unable to change password')))); } } }
public static function postCroppedAvatar($args) { \OC_JSON::checkLoggedIn(); \OC_JSON::callCheck(); $user = \OC_User::getUser(); if (isset($_POST['crop'])) { $crop = $_POST['crop']; } else { $l = new \OC_L10n('core'); \OC_JSON::error(array("data" => array("message" => $l->t("No crop data provided")))); return; } $tmpavatar = \OC_Cache::get('tmpavatar'); if (is_null($tmpavatar)) { $l = new \OC_L10n('core'); \OC_JSON::error(array("data" => array("message" => $l->t("No temporary profile picture available, try again")))); return; } $image = new \OC_Image($tmpavatar); $image->crop($crop['x'], $crop['y'], $crop['w'], $crop['h']); try { $avatar = new \OC_Avatar($user); $avatar->set($image->data()); // Clean up \OC_Cache::remove('tmpavatar'); \OC_JSON::success(); } catch (\Exception $e) { \OC_JSON::error(array("data" => array("message" => $e->getMessage()))); } }
OCP\Util::addScript('imprint', 'imprint_header_right'); break; default: // don't show a link! break; } // switch } else { // if logged in // user logged in, we have more positions to place the link: switch (OCP\Config::getAppValue('imprint', 'position', 'standalone')) { case 'header-left': OCP\Util::addScript('imprint', 'imprint_header_left'); break; case 'header-right': OCP\Util::addScript('imprint', 'imprint_header_right'); break; case 'navigation-top': OCP\Util::addScript('imprint', 'imprint_navigation_top'); break; case 'navigation-bottom': OCP\Util::addScript('imprint', 'imprint_navigation_bottom'); break; default: case 'standalone': // no js required, we add the imprint as a normal app to the navigation OCP\App::addNavigationEntry(array('id' => 'imprint', 'order' => 99999, 'href' => OCP\Util::linkTo('imprint', 'index.php'), 'icon' => 5 <= @reset(OCP\Util::getVersion()) ? OCP\Util::imagePath('imprint', 'imprint-light.svg') : OCP\Util::imagePath('imprint', 'imprint-dusky.svg'), 'name' => $l->t("Legal notice"))); } // switch } // if logged in