Check if username is already used for a pending registration

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2017-07-08 14:27:51 +02:00
parent fffdb77ff6
commit ffcc23957e
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 17 additions and 1 deletions

View File

@ -23,6 +23,7 @@
namespace OCA\Registration\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
@ -48,7 +49,18 @@ class RegistrationMapper extends Mapper {
public function findBySecret($secret) {
return $this->findEntity('SELECT * FROM `*PREFIX*registration` WHERE `client_secret` = ? ', [$secret]);
}
public function usernameIsPending($username) {
try {
$entity = $this->findEntity(
'SELECT id FROM `*PREFIX*registration` WHERE `username` = ? ',
[$username]
);
} catch (DoesNotExistException $e) {
return false;
}
return true;
}
/**

View File

@ -192,9 +192,13 @@ class RegistrationService {
* @throws RegistrationException
*/
public function validateUsername($username) {
if($username === "" || $this->userManager->get($username) !== null) {
if($username === "") {
throw new RegistrationException($this->l10n->t('Please provide a valid user name.'));
}
if($this->registrationMapper->usernameIsPending($username) || $this->userManager->get($username) !== null) {
throw new RegistrationException($this->l10n->t('The username you have chosen already exists.'));
}
}
/**