diff --git a/controller/apikeycontroller.php b/controller/apikeycontroller.php index df5e3f6..f051f1c 100644 --- a/controller/apikeycontroller.php +++ b/controller/apikeycontroller.php @@ -64,8 +64,14 @@ public function addKey($key){ $apikey->setApiKey($key); $apikey->setUserId($this->userId); - /* @var $apikey ApiKey */ - $apikey = $this->apiKeyMapper->insert($apikey); + //if there is an existing key, update, insert otherwise + try { + $oldKey = $this->apiKeyMapper->findByUser($this->userId); + $this->updateKey($key, $oldKey->getId()); + } catch(\OCP\AppFramework\Db\DoesNotExistException $e) { + /* @var $apikey ApiKey */ + $apikey = $this->apiKeyMapper->insert($apikey); + } $response = array('id'=> $apikey->getId()); return new JSONResponse($response);