* public registration

* remove WSSE implementation
* add oAuth2 implementation
This commit is contained in:
Nicolas Lœuillet
2015-09-29 14:31:52 +02:00
committed by Jeremy Benoist
parent 8a60bc4cc2
commit fcb1fba5c2
33 changed files with 551 additions and 528 deletions

View File

@ -25,6 +25,7 @@ class ConfigController extends Controller
{
$em = $this->getDoctrine()->getManager();
$config = $this->getConfig();
$userManager = $this->container->get('fos_user.user_manager');
$user = $this->getUser();
// handle basic config detail (this form is defined as a service)
@ -52,9 +53,8 @@ class ConfigController extends Controller
$pwdForm->handleRequest($request);
if ($pwdForm->isValid()) {
$user->setPassword($pwdForm->get('new_password')->getData());
$em->persist($user);
$em->flush();
$user->setPlainPassword($pwdForm->get('new_password')->getData());
$userManager->updateUser($user, true);
$this->get('session')->getFlashBag()->add(
'notice',
@ -69,8 +69,7 @@ class ConfigController extends Controller
$userForm->handleRequest($request);
if ($userForm->isValid()) {
$em->persist($user);
$em->flush();
$userManager->updateUser($user, true);
$this->get('session')->getFlashBag()->add(
'notice',
@ -97,14 +96,14 @@ class ConfigController extends Controller
}
// handle adding new user
$newUser = new User();
$newUser = $userManager->createUser();
// enable created user by default
$newUser->setEnabled(true);
$newUserForm = $this->createForm(new NewUserType(), $newUser, array('validation_groups' => array('Profile')));
$newUserForm->handleRequest($request);
if ($newUserForm->isValid()) {
$em->persist($newUser);
if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) {
$userManager->updateUser($newUser, true);
$config = new Config($newUser);
$config->setTheme($this->container->getParameter('theme'));

View File

@ -18,8 +18,9 @@ class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
$userAdmin->setName('Big boss');
$userAdmin->setEmail('bigboss@wallabag.org');
$userAdmin->setUsername('admin');
$userAdmin->setPassword('mypassword');
$userAdmin->setPlainPassword('mypassword');
$userAdmin->setEnabled(true);
$userAdmin->addRole('ROLE_SUPER_ADMIN');
$manager->persist($userAdmin);
@ -29,7 +30,7 @@ class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
$bobUser->setName('Bobby');
$bobUser->setEmail('bobby@wallabag.org');
$bobUser->setUsername('bob');
$bobUser->setPassword('mypassword');
$bobUser->setPlainPassword('mypassword');
$bobUser->setEnabled(true);
$manager->persist($bobUser);

View File

@ -6,7 +6,6 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
use FOS\UserBundle\Model\User as BaseUser;
@ -22,7 +21,7 @@ use FOS\UserBundle\Model\User as BaseUser;
* @UniqueEntity("email")
* @UniqueEntity("username")
*/
class User extends BaseUser implements AdvancedUserInterface, \Serializable
class User extends BaseUser
{
/**
* @var int
@ -75,6 +74,7 @@ class User extends BaseUser implements AdvancedUserInterface, \Serializable
parent::__construct();
$this->entries = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->roles = array('ROLE_USER');
}
/**
@ -90,24 +90,6 @@ class User extends BaseUser implements AdvancedUserInterface, \Serializable
$this->updatedAt = new \DateTime();
}
/**
* Set password.
*
* @param string $password
*
* @return User
*/
public function setPassword($password)
{
if (!$password && 0 === strlen($password)) {
return;
}
$this->password = sha1($password.$this->getUsername().$this->getSalt());
return $this;
}
/**
* Set name.
*

View File

@ -0,0 +1,44 @@
<?php
namespace Wallabag\CoreBundle\EventListener;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use Wallabag\CoreBundle\Entity\Config;
class AuthenticationListener implements EventSubscriberInterface
{
private $em;
private $container;
public function __construct(Container $container, $em)
{
$this->container = $container;
$this->em = $em;
}
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate',
);
}
public function authenticate(FilterUserResponseEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
{
if (!$event->getUser()->isEnabled()) {
return;
}
$config = new Config($event->getUser());
$config->setTheme($this->container->getParameter('theme'));
$config->setItemsPerPage($this->container->getParameter('items_on_page'));
$config->setRssLimit($this->container->getParameter('rss_limit'));
$config->setLanguage($this->container->getParameter('language'));
$this->em->persist($config);
$this->em->flush();
}
}

View File

@ -13,7 +13,8 @@ class NewUserType extends AbstractType
{
$builder
->add('username', 'text', array('required' => true))
->add('password', 'password', array(
->add('plainPassword', 'repeated', array(
'type' => 'password',
'constraints' => array(
new Constraints\Length(array(
'min' => 8,

View File

@ -0,0 +1,24 @@
<?php
namespace Wallabag\CoreBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return 'wallabag_user_registration';
}
}

View File

@ -13,6 +13,11 @@ services:
tags:
- { name: form.type, alias: config }
wallabag_core.form.registration:
class: Wallabag\CoreBundle\Form\Type\RegistrationType
tags:
- { name: form.type, alias: wallabag_user_registration }
wallabag_core.form.type.forgot_password:
class: Wallabag\CoreBundle\Form\Type\ForgotPasswordType
arguments:
@ -40,3 +45,9 @@ services:
class: Wallabag\CoreBundle\Helper\ContentProxy
arguments:
- @wallabag_core.graby
wallabag_core.registration_confirmed:
class: Wallabag\CoreBundle\EventListener\AuthenticationListener
arguments: [@service_container, @doctrine.orm.entity_manager]
tags:
- { name: kernel.event_subscriber }

View File

@ -135,6 +135,7 @@
{{ form_rest(form.pwd) }}
</form>
{% if is_granted('ROLE_SUPER_ADMIN') %}
<h2>{% trans %}Add a user{% endtrans %}</h2>
<form action="{{ path('config') }}" method="post" {{ form_enctype(form.new_user) }}>
@ -150,9 +151,17 @@
<fieldset class="w500p inline">
<div class="row">
{{ form_label(form.new_user.password) }}
{{ form_errors(form.new_user.password) }}
{{ form_widget(form.new_user.password) }}
{{ form_label(form.new_user.plainPassword.first) }}
{{ form_errors(form.new_user.plainPassword.first) }}
{{ form_widget(form.new_user.plainPassword.first) }}
</div>
</fieldset>
<fieldset class="w500p inline">
<div class="row">
{{ form_label(form.new_user.plainPassword.second) }}
{{ form_errors(form.new_user.plainPassword.second) }}
{{ form_widget(form.new_user.plainPassword.second) }}
</div>
</fieldset>
@ -165,5 +174,6 @@
</fieldset>
{{ form_rest(form.new_user) }}
{% endif %}
</form>
{% endblock %}

View File

@ -15,7 +15,9 @@
<li class="tab col s3"><a href="#set2">{% trans %}RSS{% endtrans %}</a></li>
<li class="tab col s3"><a href="#set3">{% trans %}User information{% endtrans %}</a></li>
<li class="tab col s3"><a href="#set4">{% trans %}Password{% endtrans %}</a></li>
{% if is_granted('ROLE_SUPER_ADMIN') %}
<li class="tab col s3"><a href="#set5">{% trans %}Add a user{% endtrans %}</a></li>
{% endif %}
</ul>
</div>
@ -175,7 +177,7 @@
</form>
</div>
{% if is_granted('ROLE_SUPER_ADMIN') %}
<div id="set5" class="col s12">
<form action="{{ path('config') }}#set5" method="post" {{ form_enctype(form.new_user) }}>
{{ form_errors(form.new_user) }}
@ -190,9 +192,17 @@
<div class="row">
<div class="input-field col s12">
{{ form_label(form.new_user.password) }}
{{ form_errors(form.new_user.password) }}
{{ form_widget(form.new_user.password) }}
{{ form_label(form.new_user.plainPassword.first) }}
{{ form_errors(form.new_user.plainPassword.first) }}
{{ form_widget(form.new_user.plainPassword.first) }}
</div>
</div>
<div class="row">
<div class="input-field col s12">
{{ form_label(form.new_user.plainPassword.second) }}
{{ form_errors(form.new_user.plainPassword.second) }}
{{ form_widget(form.new_user.plainPassword.second) }}
</div>
</div>
@ -211,6 +221,7 @@
</form>
</div>
{% endif %}
</div>
</div>

View File

@ -49,6 +49,7 @@
{% trans %}Login{% endtrans %}
<i class="mdi-content-send right"></i>
</button>
<a href="{{ path('fos_user_registration_register') }}">{% trans %}Register{% endtrans %}</a>
</div>
</form>
</div>

View File

@ -258,7 +258,8 @@ class ConfigControllerTest extends WallabagCoreTestCase
array(
array(
'new_user[username]' => '',
'new_user[password]' => '',
'new_user[plainPassword][first]' => '',
'new_user[plainPassword][second]' => '',
'new_user[email]' => '',
),
'Please enter a username',
@ -266,7 +267,8 @@ class ConfigControllerTest extends WallabagCoreTestCase
array(
array(
'new_user[username]' => 'a',
'new_user[password]' => 'mypassword',
'new_user[plainPassword][first]' => 'mypassword',
'new_user[plainPassword][second]' => 'mypassword',
'new_user[email]' => '',
),
'The username is too short',
@ -274,7 +276,8 @@ class ConfigControllerTest extends WallabagCoreTestCase
array(
array(
'new_user[username]' => 'wallace',
'new_user[password]' => 'mypassword',
'new_user[plainPassword][first]' => 'mypassword',
'new_user[plainPassword][second]' => 'mypassword',
'new_user[email]' => 'test',
),
'The email is not valid',
@ -282,11 +285,21 @@ class ConfigControllerTest extends WallabagCoreTestCase
array(
array(
'new_user[username]' => 'admin',
'new_user[password]' => 'wallacewallace',
'new_user[plainPassword][first]' => 'wallacewallace',
'new_user[plainPassword][second]' => 'wallacewallace',
'new_user[email]' => 'wallace@wallace.me',
),
'The username is already used',
),
array(
array(
'new_user[username]' => 'wallace',
'new_user[plainPassword][first]' => 'mypassword1',
'new_user[plainPassword][second]' => 'mypassword2',
'new_user[email]' => 'wallace@wallace.me',
),
'This value is not valid',
),
);
}
@ -325,7 +338,8 @@ class ConfigControllerTest extends WallabagCoreTestCase
$data = array(
'new_user[username]' => 'wallace',
'new_user[password]' => 'wallace1',
'new_user[plainPassword][first]' => 'wallace1',
'new_user[plainPassword][second]' => 'wallace1',
'new_user[email]' => 'wallace@wallace.me',
);