Kaynağa Gözat

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

Sevajol Bastien 11 yıl önce
ebeveyn
işleme
fbdda61cf3

+ 0 - 0
src/Muzich/CoreBundle/Form/User/PrivacyForm.php Dosyayı Görüntüle


+ 0 - 0
src/Muzich/CoreBundle/Managers/UserPrivacy.php Dosyayı Görüntüle


+ 3 - 1
src/Muzich/CoreBundle/Resources/config/security.yml Dosyayı Görüntüle

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

+ 6 - 5
src/Muzich/CoreBundle/Resources/public/js/muzich.js Dosyayı Görüntüle

3271
    
3271
    
3272
 });
3272
 });
3273
 
3273
 
3274
-function open_ajax_popin(url, callback)
3274
+function open_ajax_popin(url, callback, data)
3275
 {
3275
 {
3276
   if (!popin_opened)
3276
   if (!popin_opened)
3277
   {
3277
   {
3280
       '<div id="helpbox" class="popin_block"><img src="/bundles/muzichcore/img/ajax-loader.gif" alt="loading..." /></div>'
3280
       '<div id="helpbox" class="popin_block"><img src="/bundles/muzichcore/img/ajax-loader.gif" alt="loading..." /></div>'
3281
     );
3281
     );
3282
     open_popin_dialog('helpbox');
3282
     open_popin_dialog('helpbox');
3283
-    JQueryJson(url, {}, function(response){
3283
+    JQueryJson(url, data, function(response){
3284
       if (response.status == 'success')
3284
       if (response.status == 'success')
3285
       {
3285
       {
3286
         $('div#helpbox').html(
3286
         $('div#helpbox').html(
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
   if (window_login_or_subscription_opened == false)
3305
   if (window_login_or_subscription_opened == false)
3306
   {
3306
   {
3310
       {
3310
       {
3311
         $('div#helpbox div#login_box').show();
3311
         $('div#helpbox div#login_box').show();
3312
         $('a#registration_link').show();
3312
         $('a#registration_link').show();
3313
+        $('input#username').focus();
3313
       }
3314
       }
3314
       else
3315
       else
3315
       {
3316
       {
3328
         $('div.login form').find('img.loader').hide();
3329
         $('div.login form').find('img.loader').hide();
3329
         if (response.status == 'success')
3330
         if (response.status == 'success')
3330
         {
3331
         {
3331
-          $(location).attr('href', url_home);
3332
+          $(location).attr('href', response.data.redirect_url);
3332
         }
3333
         }
3333
         else if (response.status == 'error')
3334
         else if (response.status == 'error')
3334
         {
3335
         {
3356
       $('div#facebook_login').prependTo('div#helpbox');
3357
       $('div#facebook_login').prependTo('div#helpbox');
3357
       $('div#facebook_login').show();
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 Dosyayı Görüntüle

41
    function onAuthenticationSuccess(Request $request, TokenInterface $token)
41
    function onAuthenticationSuccess(Request $request, TokenInterface $token)
42
    {
42
    {
43
       if ($request->isXmlHttpRequest())
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
         $response->headers->set('Content-Type', 'application/json; charset=utf-8');
51
         $response->headers->set('Content-Type', 'application/json; charset=utf-8');
47
         return $response;
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 Dosyayı Görüntüle

15
    * 
15
    * 
16
    * @Template()
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
     $search_object = $this->getElementSearcher($count);
20
     $search_object = $this->getElementSearcher($count);
21
     $user = $this->getUser(true, array('join' => array(
21
     $user = $this->getUser(true, array('join' => array(
26
     $add_form = $this->getAddForm();
26
     $add_form = $this->getAddForm();
27
     
27
     
28
     $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
28
     $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
29
-    //$count_elements = count($elements);
30
-        
29
+    
31
     return array(
30
     return array(
32
       'search_tags_id'   => $search_object->getTags(),
31
       'search_tags_id'   => $search_object->getTags(),
33
       'ids_display'      => $search_object->getIdsDisplay(),
32
       'ids_display'      => $search_object->getIdsDisplay(),
39
       'network_public'   => $search_object->isNetworkPublic(),
38
       'network_public'   => $search_object->isNetworkPublic(),
40
       'elements'         => $elements,
39
       'elements'         => $elements,
41
       'from_url'         => $this->getRequest()->get('from_url'),
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
   public function needTagsAction()
57
   public function needTagsAction()
47
   {
58
   {
48
     $es = $this->getNewElementSearcher();
59
     $es = $this->getNewElementSearcher();

+ 6 - 2
src/Muzich/HomeBundle/Resources/config/routing.yml Dosyayı Görüntüle

2
 
2
 
3
 home:
3
 home:
4
   pattern:  /
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
 home_more:
11
 home_more:
8
   pattern:  /more/{count}
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
 show_user:
15
 show_user:
12
   pattern: /user/{slug}
16
   pattern: /user/{slug}

+ 12 - 0
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig Dosyayı Görüntüle

35
     </script>
35
     </script>
36
   {% endif %}
36
   {% endif %}
37
   {% endif %}
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
   <div class="top_tools" {% if search_tags_id|length == 0 %}style="display: none;"{% endif %}>
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 Dosyayı Görüntüle

743
   
743
   
744
   public function confirmEmailAction(Request $request, $token)
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
     $user = $this->getUser();
752
     $user = $this->getUser();
747
     
753
     
748
     if ($token == hash('sha256', $user->getConfirmationToken().$user->getEmail()))
754
     if ($token == hash('sha256', $user->getConfirmationToken().$user->getEmail()))

+ 4 - 0
src/Muzich/UserBundle/Resources/views/Security/login.html.twig Dosyayı Görüntüle

12
 
12
 
13
   <form action="{{ path("fos_user_security_check") }}" method="post">
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
     <input type="text" id="username" name="_username" value="{{ last_username }}"
19
     <input type="text" id="username" name="_username" value="{{ last_username }}"
16
       class="niceinput"
20
       class="niceinput"
17
       placeholder="{{ 'security.login.username'|trans({}, 'userui') }}"
21
       placeholder="{{ 'security.login.username'|trans({}, 'userui') }}"