forked from wallabag/wallabag
Merge pull request #1436 from wallabag/v2-register
Public registration & oAuth2 \o/
This commit is contained in:
@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Entity\Config;
|
||||
|
||||
class InstallCommand extends ContainerAwareCommand
|
||||
@ -188,9 +188,10 @@ class InstallCommand extends ContainerAwareCommand
|
||||
|
||||
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$user = new User();
|
||||
$userManager = $this->getContainer()->get('fos_user.user_manager');
|
||||
$user = $userManager->createUser();
|
||||
$user->setUsername($dialog->ask($this->defaultOutput, '<question>Username</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
|
||||
$user->setPassword($dialog->ask($this->defaultOutput, '<question>Password</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
|
||||
$user->setPlainPassword($dialog->ask($this->defaultOutput, '<question>Password</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
|
||||
$user->setEmail($dialog->ask($this->defaultOutput, '<question>Email:</question>', ''));
|
||||
$user->setEnabled(true);
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Wallabag\CoreBundle\Entity\Config;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
|
||||
use Wallabag\CoreBundle\Form\Type\UserInformationType;
|
||||
use Wallabag\CoreBundle\Form\Type\NewUserType;
|
||||
@ -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'));
|
||||
|
||||
@ -5,7 +5,7 @@ namespace Wallabag\CoreBundle\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
@ -16,7 +16,7 @@ class RssController extends Controller
|
||||
* Shows unread entries for current user.
|
||||
*
|
||||
* @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"})
|
||||
* @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter")
|
||||
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
@ -29,7 +29,7 @@ class RssController extends Controller
|
||||
* Shows read entries for current user.
|
||||
*
|
||||
* @Route("/{username}/{token}/archive.xml", name="archive_rss")
|
||||
* @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter")
|
||||
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
@ -42,7 +42,7 @@ class RssController extends Controller
|
||||
* Shows starred entries for current user.
|
||||
*
|
||||
* @Route("/{username}/{token}/starred.xml", name="starred_rss")
|
||||
* @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter")
|
||||
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
|
||||
@ -1,153 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\SecurityContext;
|
||||
use Wallabag\CoreBundle\Form\Type\ResetPasswordType;
|
||||
|
||||
class SecurityController extends Controller
|
||||
{
|
||||
public function loginAction(Request $request)
|
||||
{
|
||||
$session = $request->getSession();
|
||||
// get the login error if there is one
|
||||
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
|
||||
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
|
||||
} else {
|
||||
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
|
||||
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
|
||||
}
|
||||
|
||||
return $this->render('WallabagCoreBundle:Security:login.html.twig', array(
|
||||
// last username entered by the user
|
||||
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
|
||||
'error' => $error,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Request forgot password: show form.
|
||||
*
|
||||
* @Route("/forgot-password", name="forgot_password")
|
||||
*
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function forgotPasswordAction(Request $request)
|
||||
{
|
||||
$form = $this->createForm('forgot_password');
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$user = $this->getDoctrine()->getRepository('WallabagCoreBundle:User')->findOneByEmail($form->get('email')->getData());
|
||||
|
||||
// generate "hard" token
|
||||
$user->setConfirmationToken(rtrim(strtr(base64_encode(hash('sha256', uniqid(mt_rand(), true), true)), '+/', '-_'), '='));
|
||||
$user->setPasswordRequestedAt(new \DateTime());
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
$message = \Swift_Message::newInstance()
|
||||
->setSubject('Reset Password')
|
||||
->setFrom($this->container->getParameter('from_email'))
|
||||
->setTo($user->getEmail())
|
||||
->setBody($this->renderView('WallabagCoreBundle:Mail:forgotPassword.txt.twig', array(
|
||||
'username' => $user->getUsername(),
|
||||
'confirmationUrl' => $this->generateUrl('forgot_password_reset', array('token' => $user->getConfirmationToken()), true),
|
||||
)))
|
||||
;
|
||||
$this->get('mailer')->send($message);
|
||||
|
||||
return $this->redirect($this->generateUrl('forgot_password_check_email',
|
||||
array('email' => $this->getObfuscatedEmail($user->getEmail()))
|
||||
));
|
||||
}
|
||||
|
||||
return $this->render('WallabagCoreBundle:Security:forgotPassword.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the user to check his email provider.
|
||||
*
|
||||
* @Route("/forgot-password/check-email", name="forgot_password_check_email")
|
||||
*
|
||||
* @Method({"GET"})
|
||||
*/
|
||||
public function checkEmailAction(Request $request)
|
||||
{
|
||||
$email = $request->query->get('email');
|
||||
|
||||
if (empty($email)) {
|
||||
// the user does not come from the forgotPassword action
|
||||
return $this->redirect($this->generateUrl('forgot_password'));
|
||||
}
|
||||
|
||||
return $this->render('WallabagCoreBundle:Security:checkEmail.html.twig', array(
|
||||
'email' => $email,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset user password.
|
||||
*
|
||||
* @Route("/forgot-password/{token}", name="forgot_password_reset")
|
||||
*
|
||||
* @Method({"GET", "POST"})
|
||||
*/
|
||||
public function resetAction(Request $request, $token)
|
||||
{
|
||||
$user = $this->getDoctrine()->getRepository('WallabagCoreBundle:User')->findOneByConfirmationToken($token);
|
||||
|
||||
if (null === $user) {
|
||||
throw $this->createNotFoundException(sprintf('No user found with token "%s"', $token));
|
||||
}
|
||||
|
||||
$form = $this->createForm(new ResetPasswordType());
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$user->setPassword($form->get('new_password')->getData());
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
$this->get('session')->getFlashBag()->add(
|
||||
'notice',
|
||||
'The password has been reset successfully'
|
||||
);
|
||||
|
||||
return $this->redirect($this->generateUrl('login'));
|
||||
}
|
||||
|
||||
return $this->render('WallabagCoreBundle:Security:reset.html.twig', array(
|
||||
'token' => $token,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the truncated email displayed when requesting the resetting.
|
||||
*
|
||||
* Keeping only the part following @ in the address.
|
||||
*
|
||||
* @param string $email
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getObfuscatedEmail($email)
|
||||
{
|
||||
if (false !== $pos = strpos($email, '@')) {
|
||||
$email = '...'.substr($email, $pos);
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
|
||||
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$userAdmin = new User();
|
||||
$userAdmin->setName('Big boss');
|
||||
$userAdmin->setEmail('bigboss@wallabag.org');
|
||||
$userAdmin->setUsername('admin');
|
||||
$userAdmin->setPassword('mypassword');
|
||||
$userAdmin->setEnabled(true);
|
||||
|
||||
$manager->persist($userAdmin);
|
||||
|
||||
$this->addReference('admin-user', $userAdmin);
|
||||
|
||||
$bobUser = new User();
|
||||
$bobUser->setName('Bobby');
|
||||
$bobUser->setEmail('bobby@wallabag.org');
|
||||
$bobUser->setUsername('bob');
|
||||
$bobUser->setPassword('mypassword');
|
||||
$bobUser->setEnabled(true);
|
||||
|
||||
$manager->persist($bobUser);
|
||||
|
||||
$this->addReference('bob-user', $bobUser);
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
@ -72,14 +72,14 @@ class Config
|
||||
private $rssLimit;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="User", inversedBy="config")
|
||||
* @ORM\OneToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="config")
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/*
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
public function __construct(\Wallabag\UserBundle\Entity\User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
@ -169,11 +169,11 @@ class Config
|
||||
/**
|
||||
* Set user.
|
||||
*
|
||||
* @param \Wallabag\CoreBundle\Entity\User $user
|
||||
* @param User $user
|
||||
*
|
||||
* @return Config
|
||||
*/
|
||||
public function setUser(\Wallabag\CoreBundle\Entity\User $user = null)
|
||||
public function setUser(User $user = null)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
@ -183,7 +183,7 @@ class Config
|
||||
/**
|
||||
* Get user.
|
||||
*
|
||||
* @return \Wallabag\CoreBundle\Entity\User
|
||||
* @return User
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
|
||||
@ -7,6 +7,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Hateoas\Configuration\Annotation as Hateoas;
|
||||
use JMS\Serializer\Annotation\XmlRoot;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* Entry.
|
||||
@ -129,7 +130,7 @@ class Entry
|
||||
private $isPublic;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
|
||||
* @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
|
||||
*/
|
||||
private $user;
|
||||
|
||||
@ -142,7 +143,7 @@ class Entry
|
||||
/*
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
public function __construct(\Wallabag\UserBundle\Entity\User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->tags = new ArrayCollection();
|
||||
|
||||
@ -42,11 +42,11 @@ class Tag
|
||||
private $entries;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="tags")
|
||||
* @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="tags")
|
||||
*/
|
||||
private $user;
|
||||
|
||||
public function __construct(User $user)
|
||||
public function __construct(\Wallabag\UserBundle\Entity\User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->entries = new ArrayCollection();
|
||||
|
||||
@ -1,219 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Entity;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* User.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
|
||||
* @ORM\Table
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
* @ExclusionPolicy("all")
|
||||
*
|
||||
* @UniqueEntity("email")
|
||||
* @UniqueEntity("username")
|
||||
*/
|
||||
class User extends BaseUser implements AdvancedUserInterface, \Serializable
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @Expose
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="text", nullable=true)
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var date
|
||||
*
|
||||
* @ORM\Column(name="created_at", type="datetime")
|
||||
*/
|
||||
protected $createdAt;
|
||||
|
||||
/**
|
||||
* @var date
|
||||
*
|
||||
* @ORM\Column(name="updated_at", type="datetime")
|
||||
*/
|
||||
protected $updatedAt;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
|
||||
*/
|
||||
protected $entries;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="Config", mappedBy="user")
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
|
||||
*/
|
||||
protected $tags;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->entries = new ArrayCollection();
|
||||
$this->tags = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PrePersist
|
||||
* @ORM\PreUpdate
|
||||
*/
|
||||
public function timestamps()
|
||||
{
|
||||
if (is_null($this->createdAt)) {
|
||||
$this->createdAt = new \DateTime();
|
||||
}
|
||||
|
||||
$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.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdatedAt()
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entry $entry
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function addEntry(Entry $entry)
|
||||
{
|
||||
$this->entries[] = $entry;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection<Entry>
|
||||
*/
|
||||
public function getEntries()
|
||||
{
|
||||
return $this->entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entry $entry
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function addTag(Tag $tag)
|
||||
{
|
||||
$this->tags[] = $tag;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection<Tag>
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
public function isEqualTo(UserInterface $user)
|
||||
{
|
||||
return $this->username === $user->getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set config.
|
||||
*
|
||||
* @param \Wallabag\CoreBundle\Entity\Config $config
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null)
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config.
|
||||
*
|
||||
* @return \Wallabag\CoreBundle\Entity\Config
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\EventListener;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use FOS\UserBundle\Event\FilterUserResponseEvent;
|
||||
use FOS\UserBundle\FOSUserEvents;
|
||||
use Wallabag\CoreBundle\Entity\Config;
|
||||
|
||||
class RegistrationConfirmedListener implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $theme;
|
||||
private $itemsOnPage;
|
||||
private $rssLimit;
|
||||
private $language;
|
||||
|
||||
public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->theme = $theme;
|
||||
$this->itemsOnPage = $itemsOnPage;
|
||||
$this->rssLimit = $rssLimit;
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
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->theme);
|
||||
$config->setItemsPerPage($this->itemsOnPage);
|
||||
$config->setRssLimit($this->rssLimit);
|
||||
$config->setLanguage($this->language);
|
||||
$this->em->persist($config);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
||||
class EntryFilterType extends AbstractType
|
||||
{
|
||||
|
||||
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Doctrine\Bundle\DoctrineBundle\Registry;
|
||||
|
||||
class ForgotPasswordType extends AbstractType
|
||||
{
|
||||
private $doctrine = null;
|
||||
|
||||
public function __construct(Registry $doctrine)
|
||||
{
|
||||
$this->doctrine = $doctrine;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('email', 'email', array(
|
||||
'required' => true,
|
||||
'constraints' => array(
|
||||
new Constraints\Email(),
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(array($this, 'validateEmail'))),
|
||||
),
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'forgot_password';
|
||||
}
|
||||
|
||||
public function validateEmail($email, ExecutionContextInterface $context)
|
||||
{
|
||||
$user = $this->doctrine
|
||||
->getRepository('WallabagCoreBundle:User')
|
||||
->findOneByEmail($email);
|
||||
|
||||
if (!$user) {
|
||||
$context->addViolationAt(
|
||||
'email',
|
||||
'No user found with this email',
|
||||
array(),
|
||||
$email
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
@ -30,7 +31,7 @@ class NewUserType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Wallabag\CoreBundle\Entity\User',
|
||||
'data_class' => 'Wallabag\UserBundle\Entity\User',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
|
||||
class ResetPasswordType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('new_password', 'repeated', array(
|
||||
'type' => 'password',
|
||||
'invalid_message' => 'The password fields must match.',
|
||||
'required' => true,
|
||||
'first_options' => array('label' => 'New password'),
|
||||
'second_options' => array('label' => 'Repeat new password'),
|
||||
'constraints' => array(
|
||||
new Constraints\Length(array(
|
||||
'min' => 8,
|
||||
'minMessage' => 'Password should by at least 8 chars long',
|
||||
)),
|
||||
new Constraints\NotBlank(),
|
||||
),
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'change_passwd';
|
||||
}
|
||||
}
|
||||
@ -27,7 +27,7 @@ class UserInformationType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Wallabag\CoreBundle\Entity\User',
|
||||
'data_class' => 'Wallabag\UserBundle\Entity\User',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ namespace Wallabag\CoreBundle\Helper;
|
||||
|
||||
use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
|
||||
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* This class intend to detect the active theme for the logged in user.
|
||||
|
||||
@ -7,7 +7,7 @@ use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* ParamConverter used in the RSS controller to retrieve the right user according to
|
||||
@ -49,7 +49,7 @@ class UsernameRssTokenConverter implements ParamConverterInterface
|
||||
$em = $this->registry->getManagerForClass($configuration->getClass());
|
||||
|
||||
// Check, if class name is what we need
|
||||
if ('Wallabag\CoreBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) {
|
||||
if ('Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class UserRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
* Find a user by its username and rss roken.
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $rssToken
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function findOneByUsernameAndRsstoken($username, $rssToken)
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->leftJoin('u.config', 'c')
|
||||
->where('c.rssToken = :rss_token')->setParameter('rss_token', $rssToken)
|
||||
->andWhere('u.username = :username')->setParameter('username', $username)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
||||
@ -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:
|
||||
@ -29,7 +34,8 @@ services:
|
||||
|
||||
wallabag_core.doctrine.prefixed_naming_strategy:
|
||||
class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy
|
||||
arguments: [%database_table_prefix%]
|
||||
arguments:
|
||||
- %database_table_prefix%
|
||||
|
||||
wallabag_core.graby:
|
||||
class: Graby\Graby
|
||||
@ -40,3 +46,14 @@ services:
|
||||
class: Wallabag\CoreBundle\Helper\ContentProxy
|
||||
arguments:
|
||||
- @wallabag_core.graby
|
||||
|
||||
wallabag_core.registration_confirmed:
|
||||
class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener
|
||||
arguments:
|
||||
- @doctrine.orm.entity_manager
|
||||
- %theme%
|
||||
- %items_on_page%
|
||||
- %rss_limit%
|
||||
- %language%
|
||||
tags:
|
||||
- { name: kernel.event_subscriber }
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
<script src="{{ asset('themes/_global/js/bookmarklet.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
<title>{% block title %}{% endblock %} - wallabag</title>
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
{% endblock %}
|
||||
</head>
|
||||
|
||||
@ -60,7 +60,7 @@
|
||||
|
||||
{% block messages %}{% endblock %}
|
||||
|
||||
<div id="content" class="w600p">
|
||||
<div id="content">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@ -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 %}
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
{% extends "WallabagCoreBundle::layout.html.twig" %}
|
||||
|
||||
{% block title %}{% trans %}Forgot password{% endtrans %}{% endblock %}
|
||||
|
||||
{% block body_class %}login{% endblock %}
|
||||
|
||||
{% block menu %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form>
|
||||
<fieldset class="w500p center">
|
||||
<h2 class="mbs txtcenter">{% trans %}Forgot password{% endtrans %}</h2>
|
||||
|
||||
<p>{{ 'An email has been sent to %email%. It contains a link you must click to reset your password.'|trans({'%email%': email}) }}</p>
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endblock %}
|
||||
@ -1,31 +0,0 @@
|
||||
{% extends "WallabagCoreBundle::layout.html.twig" %}
|
||||
|
||||
{% block title %}{% trans %}Forgot password{% endtrans %}{% endblock %}
|
||||
|
||||
{% block body_class %}login{% endblock %}
|
||||
|
||||
{% block menu %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="{{ path('forgot_password') }}" method="post" name="forgotPasswordform">
|
||||
<fieldset class="w500p center">
|
||||
<h2 class="mbs txtcenter">{% trans %}Forgot password{% endtrans %}</h2>
|
||||
|
||||
{{ form_errors(form) }}
|
||||
|
||||
<p>Enter your email address below and we'll send you password reset instructions.</p>
|
||||
|
||||
<div class="row">
|
||||
{{ form_label(form.email) }}
|
||||
{{ form_errors(form.email) }}
|
||||
{{ form_widget(form.email) }}
|
||||
</div>
|
||||
|
||||
<div class="row mts txtcenter">
|
||||
<button type="submit">Send me reset instructions</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
{{ form_rest(form) }}
|
||||
</form>
|
||||
{% endblock %}
|
||||
@ -1,39 +0,0 @@
|
||||
{% extends "WallabagCoreBundle::layout.html.twig" %}
|
||||
|
||||
{% block title %}{% trans %}login to your wallabag{% endtrans %}{% endblock %}
|
||||
|
||||
{% block body_class %}login{% endblock %}
|
||||
|
||||
{% block menu %}{% endblock %}
|
||||
{% block messages %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="{{ path('login_check') }}" method="post" name="loginform">
|
||||
<fieldset class="w500p center">
|
||||
<h2 class="mbs txtcenter">{% trans %}Login to wallabag{% endtrans %}</h2>
|
||||
{% if error %}
|
||||
<div>{{ error.message }}</div>
|
||||
{% endif %}
|
||||
|
||||
{% for flashMessage in app.session.flashbag.get('notice') %}
|
||||
<p>{{ flashMessage }}</p>
|
||||
{% endfor %}
|
||||
|
||||
<div class="row">
|
||||
<label class="col w150p" for="username">{% trans %}Username{% endtrans %}</label>
|
||||
<input type="text" id="username" name="_username" value="{{ last_username }}" />
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label class="col w150p" for="password">{% trans %}Password{% endtrans %}</label>
|
||||
<input type="password" id="password" name="_password" />
|
||||
</div>
|
||||
|
||||
<div class="row mts txtcenter">
|
||||
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}" />
|
||||
<button type="submit">Login</button>
|
||||
<a href="{{ path('forgot_password') }}" class="small">Forgot your password?</a>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endblock %}
|
||||
@ -1,35 +0,0 @@
|
||||
{% extends "WallabagCoreBundle::layout.html.twig" %}
|
||||
|
||||
{% block title %}{% trans %}Change password{% endtrans %}{% endblock %}
|
||||
|
||||
{% block body_class %}login{% endblock %}
|
||||
|
||||
{% block menu %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="{{ path('forgot_password_reset', {'token': token}) }}" method="post" name="loginform">
|
||||
<fieldset class="w500p center">
|
||||
<h2 class="mbs txtcenter">{% trans %}Change password{% endtrans %}</h2>
|
||||
|
||||
{{ form_errors(form) }}
|
||||
|
||||
<div class="row">
|
||||
{{ form_label(form.new_password.first) }}
|
||||
{{ form_errors(form.new_password.first) }}
|
||||
{{ form_widget(form.new_password.first) }}
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
{{ form_label(form.new_password.second) }}
|
||||
{{ form_errors(form.new_password.second) }}
|
||||
{{ form_widget(form.new_password.second) }}
|
||||
</div>
|
||||
|
||||
<div class="row mts txtcenter">
|
||||
<button type="submit">Change password</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
{{ form_rest(form) }}
|
||||
</form>
|
||||
{% endblock %}
|
||||
@ -52,7 +52,7 @@
|
||||
</li>
|
||||
<li><a href="{{ path('config') }}">{% trans %}config{% endtrans %}</a></li>
|
||||
<li><a href="{{ path('about') }}">{% trans %}about{% endtrans %}</a></li>
|
||||
<li><a class="icon icon-power" href="{{ path('logout') }}" title="{% trans %}logout{% endtrans %}">{% trans %}logout{% endtrans %}</a></li>
|
||||
<li><a class="icon icon-power" href="{{ path('fos_user_security_logout') }}" title="{% trans %}logout{% endtrans %}">{% trans %}logout{% endtrans %}</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -49,11 +49,12 @@
|
||||
{% 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>
|
||||
<div class="center">
|
||||
<a href="{{ path('forgot_password') }}">{% trans %}Forgot your password?{% endtrans %}</a>
|
||||
<a href="{{ path('fos_user_resetting_request') }}">{% trans %}Forgot your password?{% endtrans %}</a>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@ -46,8 +46,7 @@
|
||||
<li class="bold border-bottom {% if currentRoute == 'tags' %}active{% endif %}"><a class="waves-effect" href="{{ path('tag') }}">{% trans %}tags{% endtrans %}</a></li>
|
||||
<li class="bold {% if currentRoute == 'config' %}active{% endif %}"><a class="waves-effect" href="{{ path('config') }}">{% trans %}config{% endtrans %}</a></li>
|
||||
<li class="bold {% if currentRoute == 'howto' %}active{% endif %}"><a class="waves-effect" href="{{ path('howto') }}">{% trans %}howto{% endtrans %}</a></li>
|
||||
<li class="bold border-bottom {% if currentRoute == 'about' %}active{% endif %}"><a class="waves-effect" href="{{ path('about') }}">{% trans %}About{% endtrans %}</a></li>
|
||||
<li class="bold"><a class="waves-effect" class="icon icon-power" href="{{ path('logout') }}" title="{% trans %}logout{% endtrans %}">{% trans %}logout{% endtrans %}</a></li>
|
||||
<li class="bold"><a class="waves-effect" class="icon icon-power" href="{{ path('fos_user_security_logout') }}" title="{% trans %}logout{% endtrans %}">{% trans %}logout{% endtrans %}</a></li>
|
||||
</ul>
|
||||
<div class="nav-wrapper nav-panels">
|
||||
<a href="#" data-activates="slide-out" class="nav-panel-menu button-collapse"><i class="mdi-navigation-menu"></i></a>
|
||||
|
||||
@ -24,6 +24,10 @@ body {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
body.login main {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#warning_message {
|
||||
position: fixed;
|
||||
background-color: #ff6347;
|
||||
@ -250,9 +254,14 @@ main ul.row {
|
||||
}
|
||||
|
||||
.card .card-action a {
|
||||
color: #ffffff;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.card .card-action a:hover {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.settings .div_tabs {
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.0 KiB |
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Security\Authentication\Encoder;
|
||||
|
||||
use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder;
|
||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||
|
||||
/**
|
||||
* This override just add en extra variable (username) to be able to salt the password
|
||||
* the way Wallabag v1 does. It will avoid to break compatibility with Wallabag v1.
|
||||
*/
|
||||
class WallabagPasswordEncoder extends BasePasswordEncoder
|
||||
{
|
||||
private $algorithm;
|
||||
private $encodeHashAsBase64;
|
||||
private $iterations;
|
||||
private $username = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $algorithm The digest algorithm to use
|
||||
* @param bool $encodeHashAsBase64 Whether to base64 encode the password hash
|
||||
* @param int $iterations The number of iterations to use to stretch the password hash
|
||||
*/
|
||||
public function __construct($algorithm = 'sha512', $encodeHashAsBase64 = true, $iterations = 5000)
|
||||
{
|
||||
$this->algorithm = $algorithm;
|
||||
$this->encodeHashAsBase64 = $encodeHashAsBase64;
|
||||
$this->iterations = $iterations;
|
||||
}
|
||||
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encodePassword($raw, $salt)
|
||||
{
|
||||
if ($this->isPasswordTooLong($raw)) {
|
||||
throw new BadCredentialsException('Invalid password.');
|
||||
}
|
||||
|
||||
if (!in_array($this->algorithm, hash_algos(), true)) {
|
||||
throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
|
||||
}
|
||||
|
||||
$salted = $this->mergePasswordAndSalt($raw, $salt);
|
||||
$digest = hash($this->algorithm, $salted, true);
|
||||
|
||||
// "stretch" hash
|
||||
for ($i = 1; $i < $this->iterations; ++$i) {
|
||||
$digest = hash($this->algorithm, $digest.$salted, true);
|
||||
}
|
||||
|
||||
return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* We inject the username inside the salted password
|
||||
*/
|
||||
protected function mergePasswordAndSalt($password, $salt)
|
||||
{
|
||||
if (null === $this->username) {
|
||||
throw new \LogicException('We can not check the password without a username.');
|
||||
}
|
||||
|
||||
if (empty($salt)) {
|
||||
return $password;
|
||||
}
|
||||
|
||||
return $password.$this->username.$salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isPasswordValid($encoded, $raw, $salt)
|
||||
{
|
||||
return !$this->isPasswordTooLong($raw) && $this->comparePasswords($encoded, $this->encodePassword($raw, $salt));
|
||||
}
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Security\Authentication\Provider;
|
||||
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
use Symfony\Component\Security\Core\User\UserCheckerInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
|
||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider;
|
||||
|
||||
class WallabagAuthenticationProvider extends UserAuthenticationProvider
|
||||
{
|
||||
private $encoderFactory;
|
||||
private $userProvider;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param UserProviderInterface $userProvider An UserProviderInterface instance
|
||||
* @param UserCheckerInterface $userChecker An UserCheckerInterface instance
|
||||
* @param string $providerKey The provider key
|
||||
* @param EncoderFactoryInterface $encoderFactory An EncoderFactoryInterface instance
|
||||
* @param bool $hideUserNotFoundExceptions Whether to hide user not found exception or not
|
||||
*/
|
||||
public function __construct(UserProviderInterface $userProvider, UserCheckerInterface $userChecker, $providerKey, EncoderFactoryInterface $encoderFactory, $hideUserNotFoundExceptions = true)
|
||||
{
|
||||
parent::__construct($userChecker, $providerKey, $hideUserNotFoundExceptions);
|
||||
|
||||
$this->encoderFactory = $encoderFactory;
|
||||
$this->userProvider = $userProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
|
||||
{
|
||||
$currentUser = $token->getUser();
|
||||
if ($currentUser instanceof UserInterface) {
|
||||
if ($currentUser->getPassword() !== $user->getPassword()) {
|
||||
throw new BadCredentialsException('The credentials were changed from another session.');
|
||||
}
|
||||
} else {
|
||||
if ('' === ($presentedPassword = $token->getCredentials())) {
|
||||
throw new BadCredentialsException('The presented password cannot be empty.');
|
||||
}
|
||||
|
||||
// give username, it's used to hash the password
|
||||
$encoder = $this->encoderFactory->getEncoder($user);
|
||||
$encoder->setUsername($user->getUsername());
|
||||
|
||||
if (!$encoder->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) {
|
||||
throw new BadCredentialsException('The presented password is invalid.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function retrieveUser($username, UsernamePasswordToken $token)
|
||||
{
|
||||
$user = $token->getUser();
|
||||
if ($user instanceof UserInterface) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
try {
|
||||
$user = $this->userProvider->loadUserByUsername($username);
|
||||
|
||||
if (!$user instanceof UserInterface) {
|
||||
throw new AuthenticationServiceException('The user provider must return a UserInterface object.');
|
||||
}
|
||||
|
||||
return $user;
|
||||
} catch (UsernameNotFoundException $notFound) {
|
||||
$notFound->setUsername($username);
|
||||
throw $notFound;
|
||||
} catch (\Exception $repositoryProblem) {
|
||||
$ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
|
||||
$ex->setToken($token);
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Security\Validator;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
|
||||
|
||||
/**
|
||||
* @see Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator
|
||||
*/
|
||||
class WallabagUserPasswordValidator extends ConstraintValidator
|
||||
{
|
||||
private $securityContext;
|
||||
private $encoderFactory;
|
||||
|
||||
public function __construct(TokenStorageInterface $tokenStorage, EncoderFactoryInterface $encoderFactory)
|
||||
{
|
||||
$this->tokenStorage = $tokenStorage;
|
||||
$this->encoderFactory = $encoderFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($password, Constraint $constraint)
|
||||
{
|
||||
if (!$constraint instanceof UserPassword) {
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword');
|
||||
}
|
||||
|
||||
$user = $this->tokenStorage->getToken()->getUser();
|
||||
|
||||
if (!$user instanceof UserInterface) {
|
||||
throw new ConstraintDefinitionException('The User object must implement the UserInterface interface.');
|
||||
}
|
||||
|
||||
// give username, it's used to hash the password
|
||||
$encoder = $this->encoderFactory->getEncoder($user);
|
||||
$encoder->setUsername($user->getUsername());
|
||||
|
||||
if (!$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
|
||||
$this->context->addViolation($constraint->message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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',
|
||||
);
|
||||
|
||||
@ -340,7 +354,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
||||
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$user = $em
|
||||
->getRepository('WallabagCoreBundle:User')
|
||||
->getRepository('WallabagUserBundle:User')
|
||||
->findOneByUsername('wallace');
|
||||
|
||||
$this->assertTrue(false !== $user);
|
||||
@ -355,7 +369,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
||||
// reset the token
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$user = $em
|
||||
->getRepository('WallabagCoreBundle:User')
|
||||
->getRepository('WallabagUserBundle:User')
|
||||
->findOneByUsername('admin');
|
||||
|
||||
if (!$user) {
|
||||
|
||||
@ -64,7 +64,7 @@ class RssControllerTest extends WallabagCoreTestCase
|
||||
$client = $this->getClient();
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$user = $em
|
||||
->getRepository('WallabagCoreBundle:User')
|
||||
->getRepository('WallabagUserBundle:User')
|
||||
->findOneByUsername('admin');
|
||||
|
||||
$config = $user->getConfig();
|
||||
@ -85,7 +85,7 @@ class RssControllerTest extends WallabagCoreTestCase
|
||||
$client = $this->getClient();
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$user = $em
|
||||
->getRepository('WallabagCoreBundle:User')
|
||||
->getRepository('WallabagUserBundle:User')
|
||||
->findOneByUsername('admin');
|
||||
|
||||
$config = $user->getConfig();
|
||||
@ -107,7 +107,7 @@ class RssControllerTest extends WallabagCoreTestCase
|
||||
$client = $this->getClient();
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$user = $em
|
||||
->getRepository('WallabagCoreBundle:User')
|
||||
->getRepository('WallabagUserBundle:User')
|
||||
->findOneByUsername('admin');
|
||||
|
||||
$config = $user->getConfig();
|
||||
|
||||
@ -1,201 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
|
||||
|
||||
class SecurityControllerTest extends WallabagCoreTestCase
|
||||
{
|
||||
public function testLogin()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/new');
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
$this->assertContains('login', $client->getResponse()->headers->get('location'));
|
||||
}
|
||||
|
||||
public function testLoginFail()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/login');
|
||||
|
||||
$form = $crawler->filter('button[type=submit]')->form();
|
||||
$data = array(
|
||||
'_username' => 'admin',
|
||||
'_password' => 'admin',
|
||||
);
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
$this->assertContains('login', $client->getResponse()->headers->get('location'));
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
$this->assertContains('Bad credentials', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
public function testRedirectionAfterLogin()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
$client->followRedirects();
|
||||
|
||||
$crawler = $client->request('GET', '/config');
|
||||
|
||||
$form = $crawler->filter('button[type=submit]')->form();
|
||||
|
||||
$data = array(
|
||||
'_username' => 'admin',
|
||||
'_password' => 'mypassword',
|
||||
);
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertContains('RSS', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
public function testForgotPassword()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/forgot-password');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$this->assertContains('Forgot password', $client->getResponse()->getContent());
|
||||
|
||||
$form = $crawler->filter('button[type=submit]');
|
||||
|
||||
$this->assertCount(1, $form);
|
||||
|
||||
return array(
|
||||
'form' => $form->form(),
|
||||
'client' => $client,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testForgotPassword
|
||||
*/
|
||||
public function testSubmitForgotPasswordFail($parameters)
|
||||
{
|
||||
$form = $parameters['form'];
|
||||
$client = $parameters['client'];
|
||||
|
||||
$data = array(
|
||||
'forgot_password[email]' => 'material',
|
||||
);
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertContains('No user found with this email', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testForgotPassword
|
||||
*
|
||||
* Instead of using collector which slow down the test suite
|
||||
* http://symfony.com/doc/current/cookbook/email/testing.html
|
||||
*
|
||||
* Use a different way where Swift store email as file
|
||||
*/
|
||||
public function testSubmitForgotPassword($parameters)
|
||||
{
|
||||
$form = $parameters['form'];
|
||||
$client = $parameters['client'];
|
||||
|
||||
$spoolDir = $client->getKernel()->getContainer()->getParameter('swiftmailer.spool.default.file.path');
|
||||
|
||||
// cleanup pool dir
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->remove($spoolDir);
|
||||
|
||||
// to use `getCollector` since `collect: false` in config_test.yml
|
||||
$client->enableProfiler();
|
||||
|
||||
$data = array(
|
||||
'forgot_password[email]' => 'bobby@wallabag.org',
|
||||
);
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
$this->assertContains('An email has been sent to', $client->getResponse()->getContent());
|
||||
|
||||
// find every files (ie: emails) inside the spool dir except hidden files
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
->in($spoolDir)
|
||||
->ignoreDotFiles(true)
|
||||
->files();
|
||||
|
||||
$this->assertCount(1, $finder, 'Only one email has been sent');
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$message = unserialize(file_get_contents($file));
|
||||
|
||||
$this->assertInstanceOf('Swift_Message', $message);
|
||||
$this->assertEquals('Reset Password', $message->getSubject());
|
||||
$this->assertEquals('no-reply@wallabag.org', key($message->getFrom()));
|
||||
$this->assertEquals('bobby@wallabag.org', key($message->getTo()));
|
||||
$this->assertContains(
|
||||
'To reset your password - please visit',
|
||||
$message->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
$user = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:User')
|
||||
->findOneByEmail('bobby@wallabag.org');
|
||||
|
||||
$crawler = $client->request('GET', '/forgot-password/'.$user->getConfirmationToken());
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertCount(2, $crawler->filter('input[type=password]'));
|
||||
$this->assertCount(1, $form = $crawler->filter('button[type=submit]'));
|
||||
$this->assertCount(1, $form);
|
||||
|
||||
$data = array(
|
||||
'change_passwd[new_password][first]' => 'mypassword',
|
||||
'change_passwd[new_password][second]' => 'mypassword',
|
||||
);
|
||||
|
||||
$client->submit($form->form(), $data);
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
$this->assertContains('login', $client->getResponse()->headers->get('location'));
|
||||
}
|
||||
|
||||
public function testResetBadToken()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->request('GET', '/forgot-password/UIZOAU29UE902IEPZO');
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testCheckEmailWithoutEmail()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->request('GET', '/forgot-password/check-email');
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
$this->assertContains('forgot-password', $client->getResponse()->headers->get('location'));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Tests\EventListener;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use FOS\UserBundle\FOSUserEvents;
|
||||
use FOS\UserBundle\Event\FilterUserResponseEvent;
|
||||
use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener;
|
||||
use Wallabag\CoreBundle\Entity\Config;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
||||
class RegistrationConfirmedListenerTest extends KernelTestCase
|
||||
{
|
||||
private $em;
|
||||
private $listener;
|
||||
private $dispatcher;
|
||||
private $request;
|
||||
private $response;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->listener = new RegistrationConfirmedListener(
|
||||
$this->em,
|
||||
'baggy',
|
||||
20,
|
||||
50,
|
||||
'fr'
|
||||
);
|
||||
|
||||
$this->dispatcher = new EventDispatcher();
|
||||
$this->dispatcher->addSubscriber($this->listener);
|
||||
|
||||
$this->request = Request::create('/');
|
||||
$this->response = Response::create();
|
||||
}
|
||||
|
||||
public function testWithInvalidUser()
|
||||
{
|
||||
$user = new User();
|
||||
$user->setEnabled(false);
|
||||
|
||||
$event = new FilterUserResponseEvent(
|
||||
$user,
|
||||
$this->request,
|
||||
$this->response
|
||||
);
|
||||
|
||||
$this->em->expects($this->never())->method('persist');
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
|
||||
$this->dispatcher->dispatch(
|
||||
FOSUserEvents::REGISTRATION_CONFIRMED,
|
||||
$event
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithValidUser()
|
||||
{
|
||||
$user = new User();
|
||||
$user->setEnabled(true);
|
||||
|
||||
$event = new FilterUserResponseEvent(
|
||||
$user,
|
||||
$this->request,
|
||||
$this->response
|
||||
);
|
||||
|
||||
$config = new Config($user);
|
||||
$config->setTheme('baggy');
|
||||
$config->setItemsPerPage(20);
|
||||
$config->setRssLimit(50);
|
||||
$config->setLanguage('fr');
|
||||
|
||||
$this->em->expects($this->once())
|
||||
->method('persist')
|
||||
->will($this->returnValue($config));
|
||||
$this->em->expects($this->once())
|
||||
->method('flush');
|
||||
|
||||
$this->dispatcher->dispatch(
|
||||
FOSUserEvents::REGISTRATION_CONFIRMED,
|
||||
$event
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ namespace Wallabag\CoreBundle\Tests\Helper;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Helper\ContentProxy;
|
||||
|
||||
class ContentProxyTest extends KernelTestCase
|
||||
|
||||
@ -6,7 +6,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Wallabag\CoreBundle\ParamConverter\UsernameRssTokenConverter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
||||
class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
{
|
||||
@ -96,7 +96,7 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
|
||||
$meta->expects($this->once())
|
||||
->method('getName')
|
||||
->will($this->returnValue('Wallabag\CoreBundle\Entity\User'));
|
||||
->will($this->returnValue('Wallabag\UserBundle\Entity\User'));
|
||||
|
||||
$em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
|
||||
->disableOriginalConstructor()
|
||||
@ -104,7 +104,7 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getClassMetadata')
|
||||
->with('WallabagCoreBundle:User')
|
||||
->with('WallabagUserBundle:User')
|
||||
->will($this->returnValue($meta));
|
||||
|
||||
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
|
||||
@ -117,10 +117,10 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
|
||||
$registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->with('WallabagCoreBundle:User')
|
||||
->with('WallabagUserBundle:User')
|
||||
->will($this->returnValue($em));
|
||||
|
||||
$params = new ParamConverter(array('class' => 'WallabagCoreBundle:User'));
|
||||
$params = new ParamConverter(array('class' => 'WallabagUserBundle:User'));
|
||||
$converter = new UsernameRssTokenConverter($registry);
|
||||
|
||||
$this->assertTrue($converter->supports($params));
|
||||
@ -144,7 +144,7 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
*/
|
||||
public function testApplyUserNotFound()
|
||||
{
|
||||
$repo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\UserRepository')
|
||||
$repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
@ -159,7 +159,7 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('WallabagCoreBundle:User')
|
||||
->with('WallabagUserBundle:User')
|
||||
->will($this->returnValue($repo));
|
||||
|
||||
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
|
||||
@ -168,10 +168,10 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
|
||||
$registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->with('WallabagCoreBundle:User')
|
||||
->with('WallabagUserBundle:User')
|
||||
->will($this->returnValue($em));
|
||||
|
||||
$params = new ParamConverter(array('class' => 'WallabagCoreBundle:User'));
|
||||
$params = new ParamConverter(array('class' => 'WallabagUserBundle:User'));
|
||||
$converter = new UsernameRssTokenConverter($registry);
|
||||
$request = new Request(array(), array(), array('username' => 'test', 'token' => 'test'));
|
||||
|
||||
@ -182,7 +182,7 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$repo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\UserRepository')
|
||||
$repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
@ -197,7 +197,7 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with('WallabagCoreBundle:User')
|
||||
->with('WallabagUserBundle:User')
|
||||
->will($this->returnValue($repo));
|
||||
|
||||
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
|
||||
@ -206,10 +206,10 @@ class UsernameRssTokenConverterTest extends KernelTestCase
|
||||
|
||||
$registry->expects($this->once())
|
||||
->method('getManagerForClass')
|
||||
->with('WallabagCoreBundle:User')
|
||||
->with('WallabagUserBundle:User')
|
||||
->will($this->returnValue($em));
|
||||
|
||||
$params = new ParamConverter(array('class' => 'WallabagCoreBundle:User', 'name' => 'user'));
|
||||
$params = new ParamConverter(array('class' => 'WallabagUserBundle:User', 'name' => 'user'));
|
||||
$converter = new UsernameRssTokenConverter($registry);
|
||||
$request = new Request(array(), array(), array('username' => 'test', 'token' => 'test'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user