Merge pull request #2324 from nextcloud/fix/return-exception

Fix Exception upon validation of usernames and email addresses
This commit is contained in:
René Gieling 2022-03-23 00:32:07 +01:00 коммит произвёл GitHub
Родитель eff300b9dc ef7425c7e9
Коммит bd47604953
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 13 добавлений и 12 удалений

Просмотреть файл

@ -27,7 +27,6 @@ use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
@ -335,11 +334,9 @@ class PublicController extends Controller {
* @PublicPage
*/
public function validatePublicUsername(string $userName, string $token): DataResponse {
try {
return new DataResponse(['result' => $this->systemService->validatePublicUsername($userName, $token), 'name' => $userName], Http::STATUS_OK);
} catch (\Exception $e) {
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_CONFLICT);
}
return $this->response(function () use ($userName, $token) {
return ['result' => $this->systemService->validatePublicUsername($userName, $token), 'name' => $userName];
});
}
/**
@ -348,11 +345,9 @@ class PublicController extends Controller {
* @PublicPage
*/
public function validateEmailAddress(string $emailAddress): DataResponse {
try {
return new DataResponse(['result' => $this->systemService->validateEmailAddress($emailAddress), 'emailAddress' => $emailAddress], Http::STATUS_OK);
} catch (\Exception $e) {
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_CONFLICT);
}
return $this->response(function () use ($emailAddress) {
return ['result' => $this->systemService->validateEmailAddress($emailAddress), 'emailAddress' => $emailAddress];
});
}
/**

Просмотреть файл

@ -26,6 +26,7 @@ namespace OCA\Polls\Service;
use OCA\Polls\Exceptions\TooShortException;
use OCA\Polls\Exceptions\InvalidUsernameException;
use OCA\Polls\Exceptions\InvalidEmailAddress;
use OCA\Polls\Exceptions\NotAuthorizedException;
use OCA\Polls\Helper\Container;
use OCA\Polls\Db\ShareMapper;
@ -135,7 +136,12 @@ class SystemService {
* @return true
*/
public function validatePublicUsername(string $userName, string $token): bool {
$share = $this->shareMapper->findByToken($token);
try {
$share = $this->shareMapper->findByToken($token);
} catch (\Exception $e) {
throw new NotAuthorizedException('Token invalid');
}
if (!$userName) {
throw new TooShortException('Username must not be empty');