forked from Public/pics
Refactor out DummyBox objects from EditUser controller.
This commit is contained in:
parent
d7b68995e8
commit
3694819d13
@ -24,9 +24,8 @@ class EditUser extends HTMLController
|
|||||||
// Adding a user?
|
// Adding a user?
|
||||||
if (isset($_GET['add']))
|
if (isset($_GET['add']))
|
||||||
{
|
{
|
||||||
parent::__construct('Add a new user');
|
$form_title = 'Add a new user';
|
||||||
$view = new DummyBox('Add a new user');
|
parent::__construct($form_title);
|
||||||
$this->page->adopt($view);
|
|
||||||
$this->page->addClass('edituser');
|
$this->page->addClass('edituser');
|
||||||
}
|
}
|
||||||
// Deleting one?
|
// Deleting one?
|
||||||
@ -50,9 +49,8 @@ class EditUser extends HTMLController
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$user = Member::fromId($id_user);
|
$user = Member::fromId($id_user);
|
||||||
parent::__construct('Edit user \'' . $user->getFullName() . '\'');
|
$form_title = 'Edit user \'' . $user->getFullName() . '\'';
|
||||||
$view = new DummyBox('Edit user \'' . $user->getFullName() . '\'');
|
parent::__construct($form_title);
|
||||||
$this->page->adopt($view);
|
|
||||||
$this->page->addClass('edituser');
|
$this->page->addClass('edituser');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,8 +120,8 @@ class EditUser extends HTMLController
|
|||||||
|
|
||||||
// Create the form, add in default values.
|
// Create the form, add in default values.
|
||||||
$form->setData($id_user ? $user->getProps() : $_POST);
|
$form->setData($id_user ? $user->getProps() : $_POST);
|
||||||
$formview = new FormView($form);
|
$formview = new FormView($form, $form_title);
|
||||||
$view->adopt($formview);
|
$this->page->adopt($formview);
|
||||||
|
|
||||||
if (!empty($_POST))
|
if (!empty($_POST))
|
||||||
{
|
{
|
||||||
@ -131,7 +129,7 @@ class EditUser extends HTMLController
|
|||||||
|
|
||||||
// Anything missing?
|
// Anything missing?
|
||||||
if (!empty($form->getMissing()))
|
if (!empty($form->getMissing()))
|
||||||
return $formview->adopt(new DummyBox('Some data missing', 'Please fill out the following fields: ' . implode(', ', $form->getMissing())));
|
return $formview->adopt(new Alert('Some data missing', 'Please fill out the following fields: ' . implode(', ', $form->getMissing()), 'error'));
|
||||||
|
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
|
|
||||||
@ -152,18 +150,18 @@ class EditUser extends HTMLController
|
|||||||
|
|
||||||
// If it looks like an e-mail address...
|
// If it looks like an e-mail address...
|
||||||
if (!empty($data['emailaddress']) && !preg_match('~^[^ ]+@[^ ]+\.[a-z]+$~', $data['emailaddress']))
|
if (!empty($data['emailaddress']) && !preg_match('~^[^ ]+@[^ ]+\.[a-z]+$~', $data['emailaddress']))
|
||||||
return $formview->adopt(new DummyBox('Email addresses invalid', 'The email address you entered is not a valid email address.'));
|
return $formview->adopt(new Alert('Email addresses invalid', 'The email address you entered is not a valid email address.', 'error'));
|
||||||
// Check whether email address is already linked to an account in the database -- just not to the account we happen to be editing, of course.
|
// Check whether email address is already linked to an account in the database -- just not to the account we happen to be editing, of course.
|
||||||
elseif (!empty($data['emailaddress']) && Member::exists($data['emailaddress']) && !($id_user && $user->getEmailAddress() == $data['emailaddress']))
|
elseif (!empty($data['emailaddress']) && Member::exists($data['emailaddress']) && !($id_user && $user->getEmailAddress() == $data['emailaddress']))
|
||||||
return $formview->adopt(new DummyBox('Email address already in use', 'Another account is already using the e-mail address you entered.'));
|
return $formview->adopt(new Alert('Email address already in use', 'Another account is already using the e-mail address you entered.', 'error'));
|
||||||
|
|
||||||
// Setting passwords? We'll need two!
|
// Setting passwords? We'll need two!
|
||||||
if (!$id_user || !empty($data['password1']) && !empty($data['password2']))
|
if (!$id_user || !empty($data['password1']) && !empty($data['password2']))
|
||||||
{
|
{
|
||||||
if (strlen($data['password1']) < 6 || !preg_match('~[^A-z]~', $data['password1']))
|
if (strlen($data['password1']) < 6 || !preg_match('~[^A-z]~', $data['password1']))
|
||||||
return $formview->adopt(new DummyBox('Password not acceptable', 'Please fill in a password that is at least six characters long and contains at least one non-alphabetic character (e.g. a number or symbol).'));
|
return $formview->adopt(new Alert('Password not acceptable', 'Please fill in a password that is at least six characters long and contains at least one non-alphabetic character (e.g. a number or symbol).', 'error'));
|
||||||
elseif ($data['password1'] !== $data['password2'])
|
elseif ($data['password1'] !== $data['password2'])
|
||||||
return $formview->adopt(new DummyBox('Passwords do not match', 'The passwords you entered do not match. Please try again.'));
|
return $formview->adopt(new Alert('Passwords do not match', 'The passwords you entered do not match. Please try again.', 'error'));
|
||||||
else
|
else
|
||||||
$data['password'] = $data['password1'];
|
$data['password'] = $data['password1'];
|
||||||
|
|
||||||
@ -175,7 +173,7 @@ class EditUser extends HTMLController
|
|||||||
{
|
{
|
||||||
$return = Member::createNew($data);
|
$return = Member::createNew($data);
|
||||||
if ($return === false)
|
if ($return === false)
|
||||||
return $formview->adopt(new DummyBox('Cannot create this user', 'Something went wrong while creating the user...'));
|
return $formview->adopt(new Alert('Cannot create this user', 'Something went wrong while creating the user...', 'error'));
|
||||||
|
|
||||||
if (isset($_POST['submit_and_new']))
|
if (isset($_POST['submit_and_new']))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user