Commit 888211e8 authored by Akhil's avatar Akhil 😶
Browse files

Added recovery email setting

parent 708726c4
......@@ -26,7 +26,7 @@ class UserController extends ApiController
* @PublicPage
* @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();
......@@ -43,17 +43,26 @@ class UserController extends ApiController
$this->userService->setEmail($uid, $email);
$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);
if(!$createdFolder){
$response->setStatus(500);
$error = 'error_creating_user_folder';
$response->setData(['error' => $error]);
return $this->getErrorResponse($response, 'error_creating_user_folder', 500);
}
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 {
$ecloud_accounts_secret = $this->userService->getConfigValue('secret');
return strcmp($token, $ecloud_accounts_secret) === 0;
......
......@@ -6,6 +6,7 @@ namespace OCA\EcloudAccounts\Service;
use OCP\IUserManager;
use OCP\IConfig;
use UnexpectedValueException;
class UserService
{
......@@ -59,6 +60,16 @@ class UserService
$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
{
// return true as creation can be handled at login if sharding disabled
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment