diff options
Diffstat (limited to 'apps/files_external/lib/Controller/AjaxController.php')
-rw-r--r-- | apps/files_external/lib/Controller/AjaxController.php | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/apps/files_external/lib/Controller/AjaxController.php b/apps/files_external/lib/Controller/AjaxController.php index 3332044c948..4d5497b73cb 100644 --- a/apps/files_external/lib/Controller/AjaxController.php +++ b/apps/files_external/lib/Controller/AjaxController.php @@ -9,10 +9,12 @@ namespace OCA\Files_External\Controller; use OCA\Files_External\Lib\Auth\Password\GlobalAuth; use OCA\Files_External\Lib\Auth\PublicKey\RSA; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired; use OCP\AppFramework\Http\JSONResponse; use OCP\IGroupManager; +use OCP\IL10N; use OCP\IRequest; use OCP\IUserSession; @@ -32,6 +34,7 @@ class AjaxController extends Controller { private GlobalAuth $globalAuth, private IUserSession $userSession, private IGroupManager $groupManager, + private IL10N $l10n, ) { parent::__construct($appName, $request); } @@ -56,27 +59,30 @@ class AjaxController extends Controller { #[NoAdminRequired] public function getSshKeys($keyLength = 1024) { $key = $this->generateSshKeys($keyLength); - return new JSONResponse( - ['data' => [ + return new JSONResponse([ + 'data' => [ 'private_key' => $key['privatekey'], 'public_key' => $key['publickey'] ], - 'status' => 'success' - ]); + 'status' => 'success', + ]); } /** * @param string $uid * @param string $user * @param string $password - * @return bool + * @return JSONResponse */ #[NoAdminRequired] #[PasswordConfirmationRequired(strict: true)] - public function saveGlobalCredentials($uid, $user, $password) { + public function saveGlobalCredentials($uid, $user, $password): JSONResponse { $currentUser = $this->userSession->getUser(); if ($currentUser === null) { - return false; + return new JSONResponse([ + 'status' => 'error', + 'message' => $this->l10n->t('You are not logged in'), + ], Http::STATUS_UNAUTHORIZED); } // Non-admins can only edit their own credentials @@ -87,9 +93,14 @@ class AjaxController extends Controller { if ($allowedToEdit) { $this->globalAuth->saveAuth($uid, $user, $password); - return true; + return new JSONResponse([ + 'status' => 'success', + ]); } - return false; + return new JSONResponse([ + 'status' => 'success', + 'message' => $this->l10n->t('Permission denied'), + ], Http::STATUS_FORBIDDEN); } } |