From 647447b4d2a12ecefcefe4dedcb630d41a8d67e0 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 8 Oct 2014 10:38:04 +0200 Subject: [PATCH] Ensure that a new admin account does not already exist refs #7163 --- application/forms/Setup/AdminAccountPage.php | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/application/forms/Setup/AdminAccountPage.php b/application/forms/Setup/AdminAccountPage.php index 79237bac1..fc3a18fa8 100644 --- a/application/forms/Setup/AdminAccountPage.php +++ b/application/forms/Setup/AdminAccountPage.php @@ -187,6 +187,27 @@ class AdminAccountPage extends Form ); } + /** + * Validate the given request data and ensure that any new user does not already exist + * + * @param array $data The request data to validate + * + * @return bool + */ + public function isValid($data) + { + if (false === parent::isValid($data)) { + return false; + } + + if ($data['user_type'] === 'new_user' && array_search($data['new_user'], $this->fetchUsers()) !== false) { + $this->getElement('new_user')->addError(t('Username already exists.')); + return false; + } + + return true; + } + /** * Return the name of the externally authenticated user *