99use OCA \Files_External \Lib \Auth \Password \GlobalAuth ;
1010use OCA \Files_External \Lib \Auth \PublicKey \RSA ;
1111use OCP \AppFramework \Controller ;
12+ use OCP \AppFramework \Http ;
1213use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
1314use OCP \AppFramework \Http \Attribute \PasswordConfirmationRequired ;
1415use OCP \AppFramework \Http \JSONResponse ;
1516use OCP \IGroupManager ;
17+ use OCP \IL10N ;
1618use OCP \IRequest ;
1719use OCP \IUserSession ;
20+ use Rubix \ML \Helpers \JSON ;
1821
1922class AjaxController extends Controller {
2023 /**
@@ -32,6 +35,7 @@ public function __construct(
3235 private GlobalAuth $ globalAuth ,
3336 private IUserSession $ userSession ,
3437 private IGroupManager $ groupManager ,
38+ private IL10N $ l10n ,
3539 ) {
3640 parent ::__construct ($ appName , $ request );
3741 }
@@ -56,13 +60,13 @@ private function generateSshKeys($keyLength) {
5660 #[NoAdminRequired]
5761 public function getSshKeys ($ keyLength = 1024 ) {
5862 $ key = $ this ->generateSshKeys ($ keyLength );
59- return new JSONResponse (
60- [ 'data ' => [
63+ return new JSONResponse ([
64+ 'data ' => [
6165 'private_key ' => $ key ['privatekey ' ],
6266 'public_key ' => $ key ['publickey ' ]
6367 ],
64- 'status ' => 'success '
65- ]);
68+ 'status ' => 'success '
69+ ]);
6670 }
6771
6872 /**
@@ -73,10 +77,13 @@ public function getSshKeys($keyLength = 1024) {
7377 */
7478 #[NoAdminRequired]
7579 #[PasswordConfirmationRequired(strict: true )]
76- public function saveGlobalCredentials ($ uid , $ user , $ password ) {
80+ public function saveGlobalCredentials ($ uid , $ user , $ password ): JSONResponse {
7781 $ currentUser = $ this ->userSession ->getUser ();
7882 if ($ currentUser === null ) {
79- return false ;
83+ return new JSONResponse ([
84+ 'status ' => 'error ' ,
85+ 'message ' => $ this ->l10n ->t ('You are not logged in ' ),
86+ ], Http::STATUS_UNAUTHORIZED );
8087 }
8188
8289 // Non-admins can only edit their own credentials
@@ -87,9 +94,14 @@ public function saveGlobalCredentials($uid, $user, $password) {
8794
8895 if ($ allowedToEdit ) {
8996 $ this ->globalAuth ->saveAuth ($ uid , $ user , $ password );
90- return true ;
97+ return new JSONResponse ([
98+ 'status ' => 'success '
99+ ]);
91100 }
92101
93- return false ;
102+ return new JSONResponse ([
103+ 'status ' => 'success ' ,
104+ 'message ' => $ this ->l10n ->t ('Permission denied ' ),
105+ ], Http::STATUS_FORBIDDEN );
94106 }
95107}
0 commit comments