|
@@ -2,101 +2,99 @@
|
2
|
2
|
|
3
|
3
|
namespace Muzich\IndexBundle\Controller;
|
4
|
4
|
|
5
|
|
-//use Symfony\Component\HttpFoundation\Response;
|
6
|
|
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
5
|
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
6
|
+use FOS\UserBundle\Controller\SecurityController as BaseController;
|
7
|
7
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
|
8
|
+use Symfony\Component\Security\Core\SecurityContext;
|
|
9
|
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
|
10
|
+use Symfony\Component\HttpFoundation\RedirectResponse;
|
8
|
11
|
|
9
|
12
|
use Muzich\CoreBundle\Entity\Tag;
|
10
|
13
|
use Muzich\CoreBundle\Entity\UsersTagsFavorites;
|
11
|
14
|
use Muzich\CoreBundle\Entity\User;
|
12
|
15
|
|
13
|
|
-class IndexController extends Controller
|
|
16
|
+class IndexController extends BaseController
|
14
|
17
|
{
|
|
18
|
+
|
15
|
19
|
/**
|
16
|
|
- *
|
|
20
|
+ *
|
17
|
21
|
* @Template()
|
18
|
22
|
*/
|
19
|
23
|
public function indexAction()
|
20
|
24
|
{
|
21
|
|
- $em = $this->getDoctrine()->getEntityManager();
|
22
|
|
-
|
23
|
|
- $bux = $em
|
24
|
|
- ->getRepository('MuzichCoreBundle:User')
|
25
|
|
- ->findOneByUsername('bux')
|
26
|
|
- ;
|
27
|
|
-//
|
28
|
|
-// $tag_hardtek = $em
|
29
|
|
-// ->getRepository('MuzichCoreBundle:Tag')
|
30
|
|
-// ->findOneByName('Hardtek')
|
31
|
|
-// ;
|
32
|
|
-//
|
33
|
|
-// if (!$tag_hardtek)
|
34
|
|
-// {
|
35
|
|
-// $tag_hardtek = new Tag();
|
36
|
|
-// $tag_hardtek->setName('Hardtek');
|
37
|
|
-// $em->persist($tag_hardtek);
|
38
|
|
-// }
|
39
|
|
-//
|
40
|
|
-// $tag_tribe = $em
|
41
|
|
-// ->getRepository('MuzichCoreBundle:Tag')
|
42
|
|
-// ->findOneByName('Tribe')
|
43
|
|
-// ;
|
44
|
|
-//
|
45
|
|
-// if (!$tag_tribe)
|
46
|
|
-// {
|
47
|
|
-// $tag_tribe = new Tag();
|
48
|
|
-// $tag_tribe->setName('Tribe');
|
49
|
|
-// $em->persist($tag_tribe);
|
50
|
|
-// }
|
51
|
|
-//
|
52
|
|
-// //
|
53
|
|
-//
|
54
|
|
-// $user_tag_favorite_bux_hardtek = $em
|
55
|
|
-// ->getRepository('MuzichCoreBundle:UsersTagsFavorites')
|
56
|
|
-// ->findOneBy(array(
|
57
|
|
-// 'tag' => $tag_hardtek->getId(),
|
58
|
|
-// 'user' => $bux->getId()
|
59
|
|
-// ))
|
60
|
|
-// ;
|
61
|
|
-//
|
62
|
|
-// if (!$user_tag_favorite_bux_hardtek)
|
63
|
|
-// {
|
64
|
|
-// $user_tag_favorite_bux_hardtek = new UsersTagsFavorites();
|
65
|
|
-// $user_tag_favorite_bux_hardtek->setTag($tag_hardtek);
|
66
|
|
-// $user_tag_favorite_bux_hardtek->setUser($bux);
|
67
|
|
-// $user_tag_favorite_bux_hardtek->setPosition(0);
|
68
|
|
-// $em->persist($user_tag_favorite_bux_hardtek);
|
69
|
|
-// }
|
70
|
|
-//
|
71
|
|
-// $user_tag_favorite_bux_tribe = $em
|
72
|
|
-// ->getRepository('MuzichCoreBundle:UsersTagsFavorites')
|
73
|
|
-// ->findOneBy(array(
|
74
|
|
-// 'tag' => $tag_tribe->getId(),
|
75
|
|
-// 'user' => $bux->getId()
|
76
|
|
-// ))
|
77
|
|
-// ;
|
78
|
|
-//
|
79
|
|
-// if (!$user_tag_favorite_bux_tribe)
|
80
|
|
-// {
|
81
|
|
-// $user_tag_favorite_bux_tribe = new UsersTagsFavorites();
|
82
|
|
-// $user_tag_favorite_bux_tribe->setTag($tag_tribe);
|
83
|
|
-// $user_tag_favorite_bux_tribe->setUser($bux);
|
84
|
|
-// $user_tag_favorite_bux_tribe->setPosition(0);
|
85
|
|
-// $em->persist($user_tag_favorite_bux_tribe);
|
86
|
|
-// }
|
87
|
|
-//
|
88
|
|
-// $em->flush();
|
89
|
|
-//
|
90
|
|
-// //$bux = new User();
|
91
|
|
-// //var_dump($bux->getTagsFavorites()->get(0)->getTag()->getName());
|
92
|
|
-//
|
93
|
|
-// foreach ($bux->getTagsFavorites() as $UserTagFavorite)
|
94
|
|
-// {
|
95
|
|
-// echo $UserTagFavorite->getTag()->getName().'<br />';
|
96
|
|
-// }
|
97
|
|
-
|
98
|
|
- //die();
|
99
|
|
-
|
100
|
|
- return array('bux' => $bux);
|
|
25
|
+ $vars = $this->proceedLogin();
|
|
26
|
+ $vars = array_merge($vars, $this->proceedRegister());
|
|
27
|
+ return $vars;
|
101
|
28
|
}
|
|
29
|
+
|
|
30
|
+ /**
|
|
31
|
+ * Gestion du formulaire d'identification sur la page d'index.
|
|
32
|
+ *
|
|
33
|
+ * @return type array
|
|
34
|
+ */
|
|
35
|
+ protected function proceedLogin()
|
|
36
|
+ {
|
|
37
|
+ $request = $this->container->get('request');
|
|
38
|
+ /* @var $request \Symfony\Component\HttpFoundation\Request */
|
|
39
|
+ $session = $request->getSession();
|
|
40
|
+ /* @var $session \Symfony\Component\HttpFoundation\Session */
|
|
41
|
+
|
|
42
|
+ // get the error if any (works with forward and redirect -- see below)
|
|
43
|
+ if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
|
|
44
|
+ $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
|
|
45
|
+ } elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) {
|
|
46
|
+ $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
|
|
47
|
+ $session->remove(SecurityContext::AUTHENTICATION_ERROR);
|
|
48
|
+ } else {
|
|
49
|
+ $error = '';
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ if ($error) {
|
|
53
|
+ // TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
|
|
54
|
+ $error = $error->getMessage();
|
|
55
|
+ }
|
|
56
|
+ // last username entered by the user
|
|
57
|
+ $lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME);
|
|
58
|
+
|
|
59
|
+ return array(
|
|
60
|
+ 'last_username' => $lastUsername,
|
|
61
|
+ 'error' => $error,
|
|
62
|
+ );
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ /**
|
|
66
|
+ * Gestion du formulaire d'inscription sur la page d'index.
|
|
67
|
+ *
|
|
68
|
+ * @return type array
|
|
69
|
+ */
|
|
70
|
+ protected function proceedRegister()
|
|
71
|
+ {
|
|
72
|
+ $form = $this->container->get('fos_user.registration.form');
|
|
73
|
+ $formHandler = $this->container->get('fos_user.registration.form.handler');
|
|
74
|
+ $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');
|
|
75
|
+
|
|
76
|
+ $process = $formHandler->process($confirmationEnabled);
|
|
77
|
+ if ($process) {
|
|
78
|
+ $user = $form->getData();
|
|
79
|
+
|
|
80
|
+ if ($confirmationEnabled) {
|
|
81
|
+ $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
|
|
82
|
+ $route = 'fos_user_registration_check_email';
|
|
83
|
+ } else {
|
|
84
|
+ $this->authenticateUser($user);
|
|
85
|
+ $route = 'fos_user_registration_confirmed';
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ $this->setFlash('fos_user_success', 'registration.flash.user_created');
|
|
89
|
+ $url = $this->container->get('router')->generate($route);
|
|
90
|
+
|
|
91
|
+ return new RedirectResponse($url);
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ return array(
|
|
95
|
+ 'form' => $form->createView(),
|
|
96
|
+ 'theme' => $this->container->getParameter('fos_user.template.theme'),
|
|
97
|
+ );
|
|
98
|
+ }
|
|
99
|
+
|
102
|
100
|
}
|