Check if username is already used for a pending registration
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
fffdb77ff6
commit
ffcc23957e
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
namespace OCA\Registration\Db;
|
namespace OCA\Registration\Db;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCP\AppFramework\Db\Entity;
|
use OCP\AppFramework\Db\Entity;
|
||||||
use OCP\AppFramework\Db\Mapper;
|
use OCP\AppFramework\Db\Mapper;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
|
@ -48,7 +49,18 @@ class RegistrationMapper extends Mapper {
|
||||||
|
|
||||||
public function findBySecret($secret) {
|
public function findBySecret($secret) {
|
||||||
return $this->findEntity('SELECT * FROM `*PREFIX*registration` WHERE `client_secret` = ? ', [$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -192,9 +192,13 @@ class RegistrationService {
|
||||||
* @throws RegistrationException
|
* @throws RegistrationException
|
||||||
*/
|
*/
|
||||||
public function validateUsername($username) {
|
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.'));
|
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.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue