administrators management

This commit is contained in:
Etienne Roudeix
2013-10-23 16:31:37 +02:00
parent 3c69e38a3b
commit fb8b82093a
16 changed files with 1033 additions and 46 deletions

View File

@@ -0,0 +1,138 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Translation\Translator;
use Thelia\Model\AdminQuery;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ConfigQuery;
class AdministratorCreationForm extends BaseForm
{
const PROFILE_FIELD_PREFIX = "profile";
protected function buildForm()
{
$this->formBuilder
->add("login", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyExistingLogin"),
)
)),
),
"label" => Translator::getInstance()->trans("Login"),
"label_attr" => array(
"for" => "login"
),
))
->add("firstname", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => Translator::getInstance()->trans("First Name"),
"label_attr" => array(
"for" => "firstname"
),
))
->add("lastname", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => Translator::getInstance()->trans("Last Name"),
"label_attr" => array(
"for" => "lastname"
)
))
->add("password", "password", array(
"constraints" => array(),
"label" => Translator::getInstance()->trans("Password"),
"label_attr" => array(
"for" => "password"
),
))
->add("password_confirm", "password", array(
"constraints" => array(
new Constraints\Callback(array("methods" => array(
array($this, "verifyPasswordField")
)))
),
"label" => "Password confirmation",
"label_attr" => array(
"for" => "password_confirmation"
),
))
->add(
'profile',
"choice",
array(
"choices" => ProfileQuery::getProfileList(),
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => "Profile",
"label_attr" => array(
"for" => "profile"
),
)
)
;
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if($data["password"] === '' && $data["password_confirm"] === '') {
$context->addViolation("password can't be empty");
}
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation("password confirmation is not the same as password field");
}
if(strlen($data["password"]) < 4) {
$context->addViolation("password must be composed of at least 4 characters");
}
}
public function verifyExistingLogin($value, ExecutionContextInterface $context)
{
$administrator = AdminQuery::create()->findOneByLogin($value);
if ($administrator !== null) {
$context->addViolation("This login already exists");
}
}
public function getName()
{
return "thelia_admin_administrator_creation";
}
}

View File

@@ -4,7 +4,7 @@
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
@@ -20,46 +20,78 @@
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\AdminQuery;
class AdminProfileCreationForm extends BaseForm
class AdministratorModificationForm extends AdministratorCreationForm
{
protected function buildForm()
{
parent::buildForm();
$this->formBuilder
->add("wording" , "text" , array(
->add("id", "hidden", array(
"required" => true,
"constraints" => array(
new NotBlank()
new Constraints\NotBlank(),
new Constraints\Callback(
array(
"methods" => array(
array($this, "verifyAdministratorId"),
),
)
),
),
"label" => Translator::getInstance()->trans("Wording *"),
"label_attr" => array(
"for" => "wording"
))
)
->add("name" , "text" , array(
"constraints" => array(
new NotBlank()
"attr" => array(
"id" => "administrator_update_id",
),
"label" => Translator::getInstance()->trans("Name *"),
"label_attr" => array(
"for" => "name"
))
)
->add("description" , "text" , array(
"label" => Translator::getInstance()->trans("Description"),
"label_attr" => array(
"for" => "description"
))
)
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_admin_profile_creation";
return "thelia_admin_administrator_modification";
}
}
public function verifyAdministratorId($value, ExecutionContextInterface $context)
{
$administrator = AdminQuery::create()
->findPk($value);
if (null === $administrator) {
$context->addViolation("Administrator ID not found");
}
}
public function verifyExistingLogin($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
$administrator = AdminQuery::create()->findOneByLogin($value);
if ($administrator !== null && $administrator->getId() != $data['id']) {
$context->addViolation("This login already exists");
}
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation("password confirmation is not the same as password field");
}
if($data["password"] !== '' && strlen($data["password"]) < 4) {
$context->addViolation("password must be composed of at least 4 characters");
}
}
}

View File

@@ -71,7 +71,6 @@ class ProfileUpdateModuleAccessForm extends BaseForm
"attr" => array(
"tag" => "modules",
"module_code" => $module->getCode(),
"module_title" => $module->getTitle(),
),
"multiple" => true,
"constraints" => array(

View File

@@ -71,7 +71,6 @@ class ProfileUpdateResourceAccessForm extends BaseForm
"attr" => array(
"tag" => "resources",
"resource_code" => $resource->getCode(),
"resource_title" => $resource->getTitle(),
),
"multiple" => true,
"constraints" => array(