diff --git a/app/Resources/views/admin/blog/show.html.twig b/app/Resources/views/admin/blog/show.html.twig
index 3d5c6791e..60be00d72 100644
--- a/app/Resources/views/admin/blog/show.html.twig
+++ b/app/Resources/views/admin/blog/show.html.twig
@@ -7,7 +7,7 @@
diff --git a/app/Resources/views/blog/index.html.twig b/app/Resources/views/blog/index.html.twig
index bbaa90eda..10553e1f9 100644
--- a/app/Resources/views/blog/index.html.twig
+++ b/app/Resources/views/blog/index.html.twig
@@ -13,7 +13,7 @@
{{ post.publishedAt|localizeddate('long', 'medium', null, 'UTC') }}
- {{ post.author.email }}
+ {{ post.author.fullName }}
{{ post.summary|md2html }}
diff --git a/app/Resources/views/blog/post_show.html.twig b/app/Resources/views/blog/post_show.html.twig
index e1559e5a0..feea7cc36 100644
--- a/app/Resources/views/blog/post_show.html.twig
+++ b/app/Resources/views/blog/post_show.html.twig
@@ -7,7 +7,7 @@
{{ post.publishedAt|localizeddate('long', 'medium', null, 'UTC') }}
- {{ post.author.email }}
+ {{ post.author.fullName }}
{{ post.content|md2html }}
@@ -39,7 +39,7 @@
- {{ comment.author.email }} {{ 'post.commented_on'|trans }} + {{ comment.author.fullName }} {{ 'post.commented_on'|trans }} {# it's not mandatory to set the timezone in localizeddate(). This is done to avoid errors when the 'intl' PHP extension is not available and the application is forced to use the limited "intl polyfill", which only supports UTC and GMT #} diff --git a/app/Resources/views/security/login.html.twig b/app/Resources/views/security/login.html.twig index a44b6f686..d0bdd21dc 100644 --- a/app/Resources/views/security/login.html.twig +++ b/app/Resources/views/security/login.html.twig @@ -53,7 +53,7 @@
- anna_admin
+ jane_admin
kitten
@@ -97,7 +97,7 @@
// in a real application, hardcoding the user/password would be idiotic
// but for the demo application it's very convenient to do so
if (!usernameEl.val() && !passwordEl.val()) {
- usernameEl.val('anna_admin');
+ usernameEl.val('jane_admin');
passwordEl.val('kitten');
}
});
diff --git a/src/AppBundle/Command/AddUserCommand.php b/src/AppBundle/Command/AddUserCommand.php
index 76851d726..26793122f 100644
--- a/src/AppBundle/Command/AddUserCommand.php
+++ b/src/AppBundle/Command/AddUserCommand.php
@@ -61,6 +61,7 @@ protected function configure()
->addArgument('username', InputArgument::OPTIONAL, 'The username of the new user')
->addArgument('password', InputArgument::OPTIONAL, 'The plain password of the new user')
->addArgument('email', InputArgument::OPTIONAL, 'The email of the new user')
+ ->addArgument('full-name', InputArgument::OPTIONAL, 'The full name of the new user')
->addOption('admin', null, InputOption::VALUE_NONE, 'If set, the user is created as an administrator')
;
}
@@ -90,7 +91,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
- if (null !== $input->getArgument('username') && null !== $input->getArgument('password') && null !== $input->getArgument('email')) {
+ if (null !== $input->getArgument('username') && null !== $input->getArgument('password') && null !== $input->getArgument('email') && null !== $input->getArgument('full-name')) {
return;
}
@@ -163,6 +164,19 @@ protected function interact(InputInterface $input, OutputInterface $output)
} else {
$output->writeln(' > Email : '.$email);
}
+
+ // Ask for the full name if it's not defined
+ $fullName = $input->getArgument('full-name');
+ if (null === $fullName) {
+ $question = new Question(' > Full Name : ');
+ $question->setValidator([$this, 'fullNameValidator']);
+ $question->setMaxAttempts(self::MAX_ATTEMPTS);
+
+ $fullName = $console->ask($input, $output, $question);
+ $input->setArgument('full-name', $fullName);
+ } else {
+ $output->writeln(' > Full Name : '.$fullName);
+ }
}
/**
@@ -176,13 +190,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$username = $input->getArgument('username');
$plainPassword = $input->getArgument('password');
$email = $input->getArgument('email');
+ $fullName = $input->getArgument('full-name');
$isAdmin = $input->getOption('admin');
// make sure to validate the user data is correct
- $this->validateUserData($username, $plainPassword, $email);
+ $this->validateUserData($username, $plainPassword, $email, $fullName);
// create the user and encode its password
$user = new User();
+ $user->setFullName($fullName);
$user->setUsername($username);
$user->setEmail($email);
$user->setRoles([$isAdmin ? 'ROLE_ADMIN' : 'ROLE_USER']);
@@ -244,7 +260,22 @@ public function emailValidator($email)
return $email;
}
- private function validateUserData($username, $plainPassword, $email)
+ /**
+ * This internal method should be private, but it's declared as public to
+ * maintain PHP 5.3 compatibility when using it in a callback.
+ *
+ * @internal
+ */
+ public function fullNameValidator($fullName)
+ {
+ if (empty($fullName)) {
+ throw new \Exception('The full name can not be empty.');
+ }
+
+ return $fullName;
+ }
+
+ private function validateUserData($username, $plainPassword, $email, $fullName)
{
$userRepository = $this->entityManager->getRepository(User::class);
@@ -258,6 +289,7 @@ private function validateUserData($username, $plainPassword, $email)
// validate password and email if is not this input means interactive.
$this->passwordValidator($plainPassword);
$this->emailValidator($email);
+ $this->fullNameValidator($fullName);
// check if a user with the same email already exists.
$existingEmail = $userRepository->findOneBy(['email' => $email]);
diff --git a/src/AppBundle/Command/ListUsersCommand.php b/src/AppBundle/Command/ListUsersCommand.php
index 331fa7cbb..b556b6a23 100644
--- a/src/AppBundle/Command/ListUsersCommand.php
+++ b/src/AppBundle/Command/ListUsersCommand.php
@@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Doctrine query returns an array of objects and we need an array of plain arrays
$usersAsPlainArrays = array_map(function (User $user) {
- return [$user->getId(), $user->getUsername(), $user->getEmail(), implode(', ', $user->getRoles())];
+ return [$user->getId(), $user->getFullName(), $user->getUsername(), $user->getEmail(), implode(', ', $user->getRoles())];
}, $users);
// In your console commands you should always use the regular output type,
@@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$table = new Table($bufferedOutput);
$table
- ->setHeaders(['ID', 'Username', 'Email', 'Roles'])
+ ->setHeaders(['ID', 'Full Name', 'Username', 'Email', 'Roles'])
->setRows($usersAsPlainArrays)
;
$table->render();
diff --git a/src/AppBundle/DataFixtures/ORM/PostFixtures.php b/src/AppBundle/DataFixtures/ORM/PostFixtures.php
index 45352ce61..def8a7437 100644
--- a/src/AppBundle/DataFixtures/ORM/PostFixtures.php
+++ b/src/AppBundle/DataFixtures/ORM/PostFixtures.php
@@ -54,7 +54,7 @@ public function load(ObjectManager $manager)
// "References" are the way to share objects between fixtures defined
// in different files. This reference has been added in the UserFixtures
// file and it contains an instance of the User entity.
- $post->setAuthor($this->getReference('anna-admin'));
+ $post->setAuthor($this->getReference('jane-admin'));
$post->setPublishedAt(new \DateTime('now - '.$i.'days'));
$this->addRandomTags($post);
diff --git a/src/AppBundle/DataFixtures/ORM/UserFixtures.php b/src/AppBundle/DataFixtures/ORM/UserFixtures.php
index ab12c0abe..6a7759977 100644
--- a/src/AppBundle/DataFixtures/ORM/UserFixtures.php
+++ b/src/AppBundle/DataFixtures/ORM/UserFixtures.php
@@ -40,19 +40,21 @@ public function load(ObjectManager $manager)
{
$passwordEncoder = $this->container->get('security.password_encoder');
- $annaAdmin = new User();
- $annaAdmin->setUsername('anna_admin');
- $annaAdmin->setEmail('anna_admin@symfony.com');
- $annaAdmin->setRoles(['ROLE_ADMIN']);
- $encodedPassword = $passwordEncoder->encodePassword($annaAdmin, 'kitten');
- $annaAdmin->setPassword($encodedPassword);
- $manager->persist($annaAdmin);
+ $janeAdmin = new User();
+ $janeAdmin->setFullName('Jane Doe');
+ $janeAdmin->setUsername('jane_admin');
+ $janeAdmin->setEmail('jane_admin@symfony.com');
+ $janeAdmin->setRoles(['ROLE_ADMIN']);
+ $encodedPassword = $passwordEncoder->encodePassword($janeAdmin, 'kitten');
+ $janeAdmin->setPassword($encodedPassword);
+ $manager->persist($janeAdmin);
// In case if fixture objects have relations to other fixtures, adds a reference
// to that object by name and later reference it to form a relation.
// See https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#sharing-objects-between-fixtures
- $this->addReference('anna-admin', $annaAdmin);
+ $this->addReference('jane-admin', $janeAdmin);
$johnUser = new User();
+ $johnUser->setFullName('John Doe');
$johnUser->setUsername('john_user');
$johnUser->setEmail('john_user@symfony.com');
$encodedPassword = $passwordEncoder->encodePassword($johnUser, 'kitten');
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
index e9f0d3b35..41582080f 100644
--- a/src/AppBundle/Entity/User.php
+++ b/src/AppBundle/Entity/User.php
@@ -29,6 +29,13 @@ class User implements UserInterface
*/
private $id;
+ /**
+ * @var string
+ *
+ * @ORM\Column(type="string")
+ */
+ private $fullName;
+
/**
* @var string
*
@@ -62,6 +69,19 @@ public function getId()
return $this->id;
}
+ /**
+ * @param string $fullName
+ */
+ public function setFullName($fullName)
+ {
+ $this->fullName = $fullName;
+ }
+
+ public function getFullName()
+ {
+ return $this->fullName;
+ }
+
public function getUsername()
{
return $this->username;
diff --git a/tests/AppBundle/Controller/Admin/BlogControllerTest.php b/tests/AppBundle/Controller/Admin/BlogControllerTest.php
index d6d1f18b1..a83182915 100644
--- a/tests/AppBundle/Controller/Admin/BlogControllerTest.php
+++ b/tests/AppBundle/Controller/Admin/BlogControllerTest.php
@@ -59,7 +59,7 @@ public function getUrlsForRegularUsers()
public function testAdminUsers($httpMethod, $url, $statusCode)
{
$client = static::createClient([], [
- 'PHP_AUTH_USER' => 'anna_admin',
+ 'PHP_AUTH_USER' => 'jane_admin',
'PHP_AUTH_PW' => 'kitten',
]);
@@ -78,7 +78,7 @@ public function getUrlsForAdminUsers()
public function testBackendHomepage()
{
$client = static::createClient([], [
- 'PHP_AUTH_USER' => 'anna_admin',
+ 'PHP_AUTH_USER' => 'jane_admin',
'PHP_AUTH_PW' => 'kitten',
]);
diff --git a/var/data/blog.sqlite b/var/data/blog.sqlite
index 2d11650bf..4cf05309c 100644
Binary files a/var/data/blog.sqlite and b/var/data/blog.sqlite differ
diff --git a/var/data/blog_test.sqlite b/var/data/blog_test.sqlite
index 2d11650bf..e36326618 100644
Binary files a/var/data/blog_test.sqlite and b/var/data/blog_test.sqlite differ
ROLE_USER({{ 'help.role_user'|trans }})ROLE_ADMIN({{ 'help.role_admin'|trans }})