Loading lib/Controller/UserController.php +13 −4 Original line number Original line Diff line number Diff line Loading @@ -26,7 +26,7 @@ class UserController extends ApiController * @PublicPage * @PublicPage * @NoCSRFRequired * @NoCSRFRequired */ */ public function setAccountData(string $token, string $uid, string $email, string $quota = '1024 MB'): DataResponse public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $quota = '1024 MB'): DataResponse { { $response = new DataResponse(); $response = new DataResponse(); Loading @@ -43,17 +43,26 @@ class UserController extends ApiController $this->userService->setEmail($uid, $email); $this->userService->setEmail($uid, $email); $this->userService->setQuota($uid, $quota); $this->userService->setQuota($uid, $quota); $recoveryEmailSuccess = $this->userService->setRecoveryEmail($uid, $recoveryEmail); if(!$recoveryEmailSuccess) { return $this->getErrorResponse($response, 'error_setting_recovery', 400); } $createdFolder = $this->userService->createUserFolder($uid); $createdFolder = $this->userService->createUserFolder($uid); if(!$createdFolder){ if(!$createdFolder){ $response->setStatus(500); return $this->getErrorResponse($response, 'error_creating_user_folder', 500); $error = 'error_creating_user_folder'; $response->setData(['error' => $error]); } } return $response; return $response; } } private function getErrorResponse(DataResponse $response, string $error, int $code) { $response->setStatus($code); $response->setData(['error' => $error]); return $response; } private function checkAppCredentials(string $token) : bool { private function checkAppCredentials(string $token) : bool { $ecloud_accounts_secret = $this->userService->getConfigValue('secret'); $ecloud_accounts_secret = $this->userService->getConfigValue('secret'); return strcmp($token, $ecloud_accounts_secret) === 0; return strcmp($token, $ecloud_accounts_secret) === 0; Loading lib/Service/UserService.php +11 −0 Original line number Original line Diff line number Diff line Loading @@ -6,6 +6,7 @@ namespace OCA\EcloudAccounts\Service; use OCP\IUserManager; use OCP\IUserManager; use OCP\IConfig; use OCP\IConfig; use UnexpectedValueException; class UserService class UserService { { Loading Loading @@ -59,6 +60,16 @@ class UserService $user->setQuota($quota); $user->setQuota($quota); } } public function setRecoveryEmail(string $uid, string $recoveryEmail) : bool { try { $this->config->setUserValue($uid, 'email-recovery', 'recovery-email' ,$recoveryEmail); return true; } catch(UnexpectedValueException $e) { return false; } } public function createUserFolder(string $uid): bool public function createUserFolder(string $uid): bool { { // return true as creation can be handled at login if sharding disabled // return true as creation can be handled at login if sharding disabled Loading Loading
lib/Controller/UserController.php +13 −4 Original line number Original line Diff line number Diff line Loading @@ -26,7 +26,7 @@ class UserController extends ApiController * @PublicPage * @PublicPage * @NoCSRFRequired * @NoCSRFRequired */ */ public function setAccountData(string $token, string $uid, string $email, string $quota = '1024 MB'): DataResponse public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $quota = '1024 MB'): DataResponse { { $response = new DataResponse(); $response = new DataResponse(); Loading @@ -43,17 +43,26 @@ class UserController extends ApiController $this->userService->setEmail($uid, $email); $this->userService->setEmail($uid, $email); $this->userService->setQuota($uid, $quota); $this->userService->setQuota($uid, $quota); $recoveryEmailSuccess = $this->userService->setRecoveryEmail($uid, $recoveryEmail); if(!$recoveryEmailSuccess) { return $this->getErrorResponse($response, 'error_setting_recovery', 400); } $createdFolder = $this->userService->createUserFolder($uid); $createdFolder = $this->userService->createUserFolder($uid); if(!$createdFolder){ if(!$createdFolder){ $response->setStatus(500); return $this->getErrorResponse($response, 'error_creating_user_folder', 500); $error = 'error_creating_user_folder'; $response->setData(['error' => $error]); } } return $response; return $response; } } private function getErrorResponse(DataResponse $response, string $error, int $code) { $response->setStatus($code); $response->setData(['error' => $error]); return $response; } private function checkAppCredentials(string $token) : bool { private function checkAppCredentials(string $token) : bool { $ecloud_accounts_secret = $this->userService->getConfigValue('secret'); $ecloud_accounts_secret = $this->userService->getConfigValue('secret'); return strcmp($token, $ecloud_accounts_secret) === 0; return strcmp($token, $ecloud_accounts_secret) === 0; Loading
lib/Service/UserService.php +11 −0 Original line number Original line Diff line number Diff line Loading @@ -6,6 +6,7 @@ namespace OCA\EcloudAccounts\Service; use OCP\IUserManager; use OCP\IUserManager; use OCP\IConfig; use OCP\IConfig; use UnexpectedValueException; class UserService class UserService { { Loading Loading @@ -59,6 +60,16 @@ class UserService $user->setQuota($quota); $user->setQuota($quota); } } public function setRecoveryEmail(string $uid, string $recoveryEmail) : bool { try { $this->config->setUserValue($uid, 'email-recovery', 'recovery-email' ,$recoveryEmail); return true; } catch(UnexpectedValueException $e) { return false; } } public function createUserFolder(string $uid): bool public function createUserFolder(string $uid): bool { { // return true as creation can be handled at login if sharding disabled // return true as creation can be handled at login if sharding disabled Loading