Browse Source

Evolution #710: Confirmation de l'email: si pas connecté ?

Sevajol Bastien 11 years ago
parent
commit
fbdda61cf3

+ 0 - 0
src/Muzich/CoreBundle/Form/User/PrivacyForm.php View File


+ 0 - 0
src/Muzich/CoreBundle/Managers/UserPrivacy.php View File


+ 3 - 1
src/Muzich/CoreBundle/Resources/config/security.yml View File

@@ -19,7 +19,7 @@ security:
19 19
             pattern:      .*
20 20
             form_login:
21 21
                 provider:       fos_userbundle
22
-                login_path:     home
22
+                login_path:     home_login
23 23
                 use_forward:    false
24 24
                 check_path:     /login_check
25 25
                 failure_path:   null
@@ -98,6 +98,8 @@ security:
98 98
         - { path: ^/(?:fr|en)/event/view/elements, role: IS_AUTHENTICATED_ANONYMOUSLY }
99 99
         - { path: ^/test-error, role: IS_AUTHENTICATED_ANONYMOUSLY }
100 100
         - { path: ^/share-from, role: IS_AUTHENTICATED_ANONYMOUSLY }
101
+        - { path: ^/(?:fr|en)/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
102
+        - { path: ^/(?:fr|en)/account/email/confirm/, role: IS_AUTHENTICATED_ANONYMOUSLY }
101 103
         
102 104
         ## New public roads for visitors
103 105
         - { path: ^/(?:fr|en)$, role: IS_AUTHENTICATED_ANONYMOUSLY }

+ 6 - 5
src/Muzich/CoreBundle/Resources/public/js/muzich.js View File

@@ -3271,7 +3271,7 @@ $(document).ready(function(){
3271 3271
    
3272 3272
 });
3273 3273
 
3274
-function open_ajax_popin(url, callback)
3274
+function open_ajax_popin(url, callback, data)
3275 3275
 {
3276 3276
   if (!popin_opened)
3277 3277
   {
@@ -3280,7 +3280,7 @@ function open_ajax_popin(url, callback)
3280 3280
       '<div id="helpbox" class="popin_block"><img src="/bundles/muzichcore/img/ajax-loader.gif" alt="loading..." /></div>'
3281 3281
     );
3282 3282
     open_popin_dialog('helpbox');
3283
-    JQueryJson(url, {}, function(response){
3283
+    JQueryJson(url, data, function(response){
3284 3284
       if (response.status == 'success')
3285 3285
       {
3286 3286
         $('div#helpbox').html(
@@ -3300,7 +3300,7 @@ function open_ajax_popin(url, callback)
3300 3300
   }
3301 3301
 }
3302 3302
 
3303
-function open_connection_or_subscription_window(open_login_part)
3303
+function open_connection_or_subscription_window(open_login_part, data)
3304 3304
 {
3305 3305
   if (window_login_or_subscription_opened == false)
3306 3306
   {
@@ -3310,6 +3310,7 @@ function open_connection_or_subscription_window(open_login_part)
3310 3310
       {
3311 3311
         $('div#helpbox div#login_box').show();
3312 3312
         $('a#registration_link').show();
3313
+        $('input#username').focus();
3313 3314
       }
3314 3315
       else
3315 3316
       {
@@ -3328,7 +3329,7 @@ function open_connection_or_subscription_window(open_login_part)
3328 3329
         $('div.login form').find('img.loader').hide();
3329 3330
         if (response.status == 'success')
3330 3331
         {
3331
-          $(location).attr('href', url_home);
3332
+          $(location).attr('href', response.data.redirect_url);
3332 3333
         }
3333 3334
         else if (response.status == 'error')
3334 3335
         {
@@ -3356,7 +3357,7 @@ function open_connection_or_subscription_window(open_login_part)
3356 3357
       $('div#facebook_login').prependTo('div#helpbox');
3357 3358
       $('div#facebook_login').show();
3358 3359
       
3359
-    });
3360
+    }, data);
3360 3361
   }
3361 3362
 }
3362 3363
 

+ 20 - 3
src/Muzich/CoreBundle/Security/Http/Authentication/AuthenticationSuccessHandler.php View File

@@ -41,12 +41,29 @@ class AuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterf
41 41
    function onAuthenticationSuccess(Request $request, TokenInterface $token)
42 42
    {
43 43
       if ($request->isXmlHttpRequest())
44
-      {
45
-        $response = new Response(json_encode(array('status' => 'success')));
44
+      {        
45
+        $response = new Response(json_encode(array(
46
+          'status' => 'success',
47
+          'data'   => array(
48
+            'redirect_url' => $this->getRedirectionUrl($request)
49
+          )
50
+        )));
46 51
         $response->headers->set('Content-Type', 'application/json; charset=utf-8');
47 52
         return $response;
48 53
       }
49 54
       
50
-      return new RedirectResponse($this->router->generate('home'));
55
+      return new RedirectResponse($this->getRedirectionUrl($request));
56
+   }
57
+   
58
+   protected function getRedirectionUrl(Request $request)
59
+   {
60
+     if ($request->get('email_confirmation_token'))
61
+     {
62
+       return $this->router->generate('email_confirm', array(
63
+         'token' => $request->get('email_confirmation_token')
64
+       ));
65
+     }
66
+     
67
+     return $this->router->generate('home');
51 68
    }
52 69
 }

+ 15 - 4
src/Muzich/HomeBundle/Controller/HomeController.php View File

@@ -15,7 +15,7 @@ class HomeController extends Controller
15 15
    * 
16 16
    * @Template()
17 17
    */
18
-  public function indexAction($count = null, $network = 'public')
18
+  public function indexAction($count = null, $network = 'public', $login = false)
19 19
   {
20 20
     $search_object = $this->getElementSearcher($count);
21 21
     $user = $this->getUser(true, array('join' => array(
@@ -26,8 +26,7 @@ class HomeController extends Controller
26 26
     $add_form = $this->getAddForm();
27 27
     
28 28
     $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
29
-    //$count_elements = count($elements);
30
-        
29
+    
31 30
     return array(
32 31
       'search_tags_id'   => $search_object->getTags(),
33 32
       'ids_display'      => $search_object->getIdsDisplay(),
@@ -39,10 +38,22 @@ class HomeController extends Controller
39 38
       'network_public'   => $search_object->isNetworkPublic(),
40 39
       'elements'         => $elements,
41 40
       'from_url'         => $this->getRequest()->get('from_url'),
42
-      'display_launch_demo' => true
41
+      'display_launch_demo' => true,
42
+      'login'            => $login,
43
+      'email_token'      => $this->getEmailTokenIfExist()
43 44
     );
44 45
   }
45 46
   
47
+  protected function getEmailTokenIfExist()
48
+  {
49
+    if ($this->get("session")->get('user.confirm_email.token'))
50
+    {
51
+      return $this->get("session")->get('user.confirm_email.token');
52
+    }
53
+    
54
+    return null;
55
+  }
56
+  
46 57
   public function needTagsAction()
47 58
   {
48 59
     $es = $this->getNewElementSearcher();

+ 6 - 2
src/Muzich/HomeBundle/Resources/config/routing.yml View File

@@ -2,11 +2,15 @@
2 2
 
3 3
 home:
4 4
   pattern:  /
5
-  defaults: { _controller: MuzichHomeBundle:Home:index, network: network_public }
5
+  defaults: { _controller: MuzichHomeBundle:Home:index, network: network_public, login: false }
6
+  
7
+home_login:
8
+  pattern:  /login
9
+  defaults: { _controller: MuzichHomeBundle:Home:index, network: network_public, login: true }
6 10
   
7 11
 home_more:
8 12
   pattern:  /more/{count}
9
-  defaults: { _controller: MuzichHomeBundle:Home:index, count: null }
13
+  defaults: { _controller: MuzichHomeBundle:Home:index, count: null, login: false }
10 14
   
11 15
 show_user:
12 16
   pattern: /user/{slug}

+ 12 - 0
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig View File

@@ -35,6 +35,18 @@
35 35
     </script>
36 36
   {% endif %}
37 37
   {% endif %}
38
+    
39
+  {% if login %}
40
+    <script type="text/javascript">
41
+      $(document).ready(function(){
42
+        {% if not email_token %}
43
+          open_connection_or_subscription_window(true);
44
+        {% else %}
45
+          open_connection_or_subscription_window(true, {"email_confirmation_token":"{{ email_token }}"});
46
+        {% endif %}
47
+      });
48
+    </script>
49
+  {% endif %}
38 50
 
39 51
   <div class="top_tools" {% if search_tags_id|length == 0 %}style="display: none;"{% endif %}>
40 52
   

+ 6 - 0
src/Muzich/UserBundle/Controller/UserController.php View File

@@ -743,6 +743,12 @@ class UserController extends Controller
743 743
   
744 744
   public function confirmEmailAction(Request $request, $token)
745 745
   {
746
+    if ($this->isVisitor())
747
+    {
748
+      $this->get("session")->set('user.confirm_email.token', $token);
749
+      return $this->redirect($this->generateUrl('home_login'));
750
+    }
751
+    
746 752
     $user = $this->getUser();
747 753
     
748 754
     if ($token == hash('sha256', $user->getConfirmationToken().$user->getEmail()))

+ 4 - 0
src/Muzich/UserBundle/Resources/views/Security/login.html.twig View File

@@ -12,6 +12,10 @@
12 12
 
13 13
   <form action="{{ path("fos_user_security_check") }}" method="post">
14 14
     
15
+    {% if app.request.get('email_confirmation_token') %}
16
+      <input type="hidden" name="email_confirmation_token" value="{{ app.request.get('email_confirmation_token') }}" />
17
+    {% endif %}
18
+    
15 19
     <input type="text" id="username" name="_username" value="{{ last_username }}"
16 20
       class="niceinput"
17 21
       placeholder="{{ 'security.login.username'|trans({}, 'userui') }}"