Merge branch 'master' into loops
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
@@ -24,15 +23,14 @@ use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
namespace Thelia\Command;
|
||||
|
||||
|
||||
use Thelia\Command\ContainerAwareCommand;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Thelia\Core\Event\ImageEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
|
||||
class ClearImageCache extends ContainerAwareCommand
|
||||
@@ -67,4 +65,4 @@ class ClearImageCache extends ContainerAwareCommand
|
||||
$output->writeln(sprintf("Failed to clear image cache: %s", $ex->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
119
core/lib/Thelia/Command/CreateAdminUser.php
Normal file
119
core/lib/Thelia/Command/CreateAdminUser.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?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\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Thelia\Command\ContainerAwareCommand;
|
||||
use Thelia\Model\Admin;
|
||||
|
||||
class CreateAdminUser extends ContainerAwareCommand
|
||||
{
|
||||
/**
|
||||
* Configure the command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("thelia:create-admin")
|
||||
->setDescription("Create a new adminsitration user")
|
||||
->setHelp("The <info>thelia:create-admin</info> command create a new administration user.")
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln('Please enter the admin user information:');
|
||||
|
||||
$admin = $this->getAdminInfo($input, $output); // new Admin();
|
||||
|
||||
$admin->save();
|
||||
|
||||
$output->writeln(array(
|
||||
"",
|
||||
"<info>User ".$admin->getLogin()." successfully created.</info>",
|
||||
""
|
||||
));
|
||||
}
|
||||
|
||||
protected function enterData($dialog, $output, $label, $error_message)
|
||||
{
|
||||
return $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo($label),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
if (empty($answer)) {
|
||||
throw new \RuntimeException("This information is mandatory.");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask to user all needed information
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return array
|
||||
*/
|
||||
protected function getAdminInfo(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
||||
$admin = new Admin();
|
||||
|
||||
$admin->setLogin($this->enterData($dialog, $output, "Admin login name : ", "Please enter a login name."));
|
||||
$admin->setFirstname($this->enterData($dialog, $output, "User first name : ", "Please enter user first name."));
|
||||
$admin->setLastname($this->enterData($dialog, $output, "User last name : ", "Please enter user last name."));
|
||||
|
||||
do {
|
||||
$password = $this->enterData($dialog, $output, "Password : ", "Please enter a password.");
|
||||
$password_again = $this->enterData($dialog, $output, "Password (again): ", "Please enter the password again.");
|
||||
|
||||
if (! empty($password) && $password == $password_again) {
|
||||
|
||||
$admin->setPassword($password);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$output->writeln("Passwords are different, please try again.");
|
||||
}
|
||||
while (true);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
protected function decorateInfo($text)
|
||||
{
|
||||
return sprintf("<info>%s</info>", $text);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,6 +55,7 @@
|
||||
<command class="Thelia\Command\ModuleGenerateCommand"/>
|
||||
<command class="Thelia\Command\ModuleGenerateModelCommand"/>
|
||||
<command class="Thelia\Command\ModuleGenerateSqlCommand"/>
|
||||
<command class="Thelia\Command\CreateAdminUser"/>
|
||||
</commands>
|
||||
|
||||
<services>
|
||||
|
||||
@@ -26,7 +26,7 @@ class Admin extends BaseAdmin implements UserInterface
|
||||
\Thelia\Log\Tlog::getInstance()->debug($password);
|
||||
|
||||
if ($this->isNew() && ($password === null || trim($password) == "")) {
|
||||
throw new InvalidArgumentException("customer password is mandatory on creation");
|
||||
throw new \InvalidArgumentException("customer password is mandatory on creation");
|
||||
}
|
||||
|
||||
if($password !== null && trim($password) != "") {
|
||||
|
||||
@@ -17,7 +17,6 @@ class Category extends BaseCategory
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user