Przeglądaj źródła

Evolution #414: Navigation en mode non inscrit

Sevajol Bastien 11 lat temu
rodzic
commit
46c9ba4f37

+ 20 - 4
src/Muzich/CoreBundle/Resources/public/js/muzich.js Wyświetl plik

@@ -2720,7 +2720,7 @@ $(document).ready(function(){
2720 2720
 
2721 2721
 $(document).ready(function(){
2722 2722
    
2723
-   $('#registration_link').click(function(){
2723
+   $('#registration_link').live('click', function(){
2724 2724
      $('#registration_box').slideDown("slow");
2725 2725
      $('#login_box').slideUp("slow");
2726 2726
      $(this).hide();
@@ -2728,7 +2728,7 @@ $(document).ready(function(){
2728 2728
      return false;
2729 2729
    });
2730 2730
    
2731
-   $('#login_link').click(function(){
2731
+   $('#login_link').live('click', function(){
2732 2732
      $('#login_box').slideDown("slow");
2733 2733
      $('#registration_box').slideUp("slow");
2734 2734
      $('#registration_link').show();
@@ -2736,7 +2736,6 @@ $(document).ready(function(){
2736 2736
      return false;
2737 2737
    });
2738 2738
    
2739
-   
2740 2739
  });
2741 2740
 
2742 2741
 $(document).ready(function(){
@@ -2944,17 +2943,23 @@ function open_connection_or_subscription_window(open_login_part)
2944 2943
       if (open_login_part)
2945 2944
       {
2946 2945
         $('div#helpbox div#login_box').show();
2946
+        $('a#registration_link').show();
2947 2947
       }
2948 2948
       else
2949 2949
       {
2950 2950
         $('div#helpbox div#registration_box').show();
2951
+        $('a#login_link').show();
2951 2952
       }
2952 2953
       
2953 2954
       $('a#helpbox_close').click(function(){
2954 2955
         window_login_or_subscription_opened = false;
2955 2956
       });
2956 2957
       
2958
+      $('div.login form').submit(function(){
2959
+        $(this).find('img.loader').show();
2960
+      });
2957 2961
       $('div.login form').ajaxForm(function(response) {
2962
+        $('div.login form').find('img.loader').hide();
2958 2963
         if (response.status == 'success')
2959 2964
         {
2960 2965
           $(location).attr('href', url_home);
@@ -2966,8 +2971,19 @@ function open_connection_or_subscription_window(open_login_part)
2966 2971
         }
2967 2972
       });
2968 2973
       
2974
+      $('div.register form.fos_user_registration_register').submit(function(){
2975
+        $(this).find('img.loader').show();
2976
+      });
2969 2977
       $('div.register form.fos_user_registration_register').ajaxForm(function(response) {
2970
-        
2978
+        $('div.register form.fos_user_registration_register').find('img.loader').hide();
2979
+        if (response.status == 'success')
2980
+        {
2981
+          $(location).attr('href', url_home);
2982
+        }
2983
+        else if (response.status == 'error')
2984
+        {
2985
+          $('div.register form').html(response.data.html);
2986
+        }
2971 2987
       });
2972 2988
       
2973 2989
     });

+ 0 - 0
src/Muzich/CoreBundle/Security/Http/Authentication/AuthenticationFailureHandler.php Wyświetl plik


+ 0 - 0
src/Muzich/CoreBundle/Security/Http/Authentication/AuthenticationSuccessHandler.php Wyświetl plik


+ 48 - 18
src/Muzich/UserBundle/Controller/UserController.php Wyświetl plik

@@ -141,7 +141,7 @@ class UserController extends Controller
141 141
     if ($process)
142 142
     {
143 143
       $user = $form->getData();
144
-
144
+      
145 145
       $authUser = false;
146 146
       if ($confirmationEnabled) {
147 147
           $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
@@ -150,13 +150,10 @@ class UserController extends Controller
150 150
           $authUser = true;
151 151
           $route = 'start';
152 152
       }
153
-
154
-      $this->setFlash('fos_user_success', 'registration.flash.user_created');
155
-      $url = $this->container->get('router')->generate($route);
156
-      $response = new RedirectResponse($url);
157
-
153
+      
154
+      $response = $this->getSuccessRegistrationResponse();
158 155
       if ($authUser) {
159
-          $this->authenticateUser($user, $response);
156
+        $this->authenticateUser($user, $response);
160 157
       }
161 158
       
162 159
       $formHandler->getToken()->addUseCount();
@@ -167,18 +164,51 @@ class UserController extends Controller
167 164
       return $response;
168 165
     }
169 166
     
170
-    return $this->container->get('templating')->renderResponse(
171
-      'MuzichIndexBundle:Index:index.html.twig',
172
-      array(
173
-        'form'                     => $form->createView(),
174
-        'error'                    => null,
175
-        'registration_errors'      => $form->getErrors(),
176
-        'registration_errors_pers' => $formHandler->getErrors(),
177
-        'last_username'            => null,
178
-        'registration_page'        => true,
179
-        'presubscription_form'     => $this->getPreSubscriptionForm()->createView()
180
-      )
167
+    return $this->getFailureRegistrationResponse($form, $formHandler);
168
+  }
169
+  
170
+  protected function getSuccessRegistrationResponse()
171
+  {
172
+    if (!$this->getRequest()->isXmlHttpRequest())
173
+    {
174
+      $url = $this->container->get('router')->generate($route);
175
+      return new RedirectResponse($url);
176
+    }
177
+    
178
+    return $this->jsonResponse(array(
179
+      'status' => 'success'
180
+    ));
181
+  }
182
+  
183
+  protected function getFailureRegistrationResponse($form, $formHandler)
184
+  {
185
+    $parameters = array(
186
+      'form'                     => $form->createView(),
187
+      'error'                    => null,
188
+      'registration_errors'      => $form->getErrors(),
189
+      'registration_errors_pers' => $formHandler->getErrors(),
190
+      'last_username'            => null,
191
+      'registration_page'        => true,
192
+      'presubscription_form'     => $this->getPreSubscriptionForm()->createView()
181 193
     );
194
+    
195
+    if (!$this->getRequest()->isXmlHttpRequest())
196
+    {
197
+      return $this->render(
198
+        'MuzichIndexBundle:Index:index.html.twig',
199
+        $parameters
200
+      );
201
+    }
202
+    
203
+    return $this->jsonResponse(array(
204
+      'status' => 'error',
205
+      'data'   => array(
206
+        'html' => $this->render(
207
+          'MuzichUserBundle:Registration:register_form_content.html.twig',
208
+          $parameters
209
+        )->getContent()
210
+      )
211
+    ));
182 212
   }
183 213
   
184 214
   /**

+ 10 - 0
src/Muzich/UserBundle/Resources/views/Account/subscribe_or_login.html.twig Wyświetl plik

@@ -1,3 +1,13 @@
1
+
2
+<a href="#" id="registration_link" class="button gradient" style="display: none;">
3
+  {{ 'registration.display'|trans({}, 'navigationui') }}
4
+  <img src="{{ asset('/img/icon_dart_right_white.png') }}" alt="" />
5
+</a>
6
+<a href="#" id="login_link" class="button gradient" style="display: none;">
7
+  {{ 'login.display'|trans({}, 'navigationui') }}
8
+  <img src="{{ asset('/img/icon_dart_left_white.png') }}" alt="" />
9
+</a>
10
+
1 11
 <div id="login_box" style="display: none;">
2 12
   
3 13
   {% include "MuzichUserBundle:Security:login.html.twig" %}

+ 1 - 68
src/Muzich/UserBundle/Resources/views/Registration/register.html.twig Wyświetl plik

@@ -7,75 +7,8 @@
7 7
     method="POST" 
8 8
     class="fos_user_registration_register nicelabels"
9 9
   >
10
-        
11
-    {% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
12 10
     
13
-    {{ form_errors(form) }}
11
+    {% include 'MuzichUserBundle:Registration:register_form_content.html.twig' %}
14 12
     
15
-    {% if registration_errors_pers|length > 0 %}
16
-    <ul class="error_list">
17
-      {% for error in registration_errors_pers %}
18
-        <li>{{ error }}</li>
19
-      {% endfor %}
20
-    </ul>
21
-    {% endif %}
22
-    
23
-    <div class="field">
24
-      {{ form_errors(form.username) }}
25
-      {{ form_label(form.username, 'username'|trans({}, 'userform')) }}
26
-      {{ form_widget(form.username, {'attr':{'class':'niceinput'}}) }}
27
-    </div>   
28
-        
29
-    <div class="field">
30
-      {{ form_errors(form.email) }}
31
-      {{ form_label(form.email, 'email'|trans({}, 'userform')) }}
32
-      {{ form_widget(form.email, {'attr':{'class':'niceinput'}}) }}
33
-    </div> 
34
-    
35
-    <div class="field">
36
-      {{ form_errors(form.plainPassword.first) }}
37
-      {{ form_label(form.plainPassword.first, 'password.first'|trans({}, 'userform')) }}
38
-      {{ form_widget(form.plainPassword.first, {'attr':{'class':'niceinput'}}) }}
39
-    </div> 
40
-    
41
-    <div class="field">
42
-      {{ form_errors(form.plainPassword.second) }}
43
-      {{ form_label(form.plainPassword.second, 'password.second'|trans({}, 'userform')) }}
44
-      {{ form_widget(form.plainPassword.second, {'attr':{'class':'niceinput'}}) }}
45
-    </div> 
46
-    
47
-    <span class="help">{{ 'help.token'|trans({}, 'userform') }}</span>
48
-    
49
-    <div class="field">
50
-      {{ form_errors(form.token) }}
51
-      {{ form_label(form.token, 'token'|trans({}, 'userform')) }}
52
-      {{ form_widget(form.token, {'attr':{'class':'niceinput'}}) }}
53
-    </div>
54
-    
55
-    <div class="field">
56
-      {{ form_errors(form.cgu_accepted) }}
57
-      {{ form_widget(form.cgu_accepted, {'attr':{}}) }}
58
-      {% autoescape false %}
59
-      {{ 'cgu_accepted'|trans({'%url%':path('info_cgu')}, 'userform') }}
60
-      {% endautoescape %}
61
-    </div>
62
-    
63
-    <div class="field">
64
-      {{ form_errors(form.mail_newsletter) }}
65
-      {{ form_widget(form.mail_newsletter, {'attr':{}}) }}
66
-      {{ 'mail_newsletter'|trans({}, 'userform') }}
67
-    </div>
68
-    
69
-    <div class="field">
70
-      {{ form_errors(form.mail_partner) }}
71
-      {{ form_widget(form.mail_partner, {'attr':{}}) }}
72
-      {{ 'mail_partner'|trans({}, 'userform') }}
73
-    </div> 
74
-
75
-    {{ form_rest(form) }}
76
-    
77
-    <div class="alignright">
78
-        <input type="submit" class="button" value="{{ 'registration.submit'|trans({}, 'userui') }}" />
79
-    </div>
80 13
   </form>
81 14
 </div>

+ 74 - 0
src/Muzich/UserBundle/Resources/views/Registration/register_form_content.html.twig Wyświetl plik

@@ -0,0 +1,74 @@
1
+{% if registration_errors_pers is not defined %}
2
+  {% set registration_errors_pers = null %}
3
+{% endif %}
4
+
5
+{% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
6
+
7
+{{ form_errors(form) }}
8
+
9
+{% if registration_errors_pers|length > 0 %}
10
+<ul class="error_list">
11
+  {% for error in registration_errors_pers %}
12
+    <li>{{ error }}</li>
13
+  {% endfor %}
14
+</ul>
15
+{% endif %}
16
+
17
+<div class="field">
18
+  {{ form_errors(form.username) }}
19
+  {{ form_label(form.username, 'username'|trans({}, 'userform')) }}
20
+  {{ form_widget(form.username, {'attr':{'class':'niceinput'}}) }}
21
+</div>   
22
+    
23
+<div class="field">
24
+  {{ form_errors(form.email) }}
25
+  {{ form_label(form.email, 'email'|trans({}, 'userform')) }}
26
+  {{ form_widget(form.email, {'attr':{'class':'niceinput'}}) }}
27
+</div> 
28
+
29
+<div class="field">
30
+  {{ form_errors(form.plainPassword.first) }}
31
+  {{ form_label(form.plainPassword.first, 'password.first'|trans({}, 'userform')) }}
32
+  {{ form_widget(form.plainPassword.first, {'attr':{'class':'niceinput'}}) }}
33
+</div> 
34
+
35
+<div class="field">
36
+  {{ form_errors(form.plainPassword.second) }}
37
+  {{ form_label(form.plainPassword.second, 'password.second'|trans({}, 'userform')) }}
38
+  {{ form_widget(form.plainPassword.second, {'attr':{'class':'niceinput'}}) }}
39
+</div> 
40
+
41
+<span class="help">{{ 'help.token'|trans({}, 'userform') }}</span>
42
+
43
+<div class="field">
44
+  {{ form_errors(form.token) }}
45
+  {{ form_label(form.token, 'token'|trans({}, 'userform')) }}
46
+  {{ form_widget(form.token, {'attr':{'class':'niceinput'}}) }}
47
+</div>
48
+
49
+<div class="field">
50
+  {{ form_errors(form.cgu_accepted) }}
51
+  {{ form_widget(form.cgu_accepted, {'attr':{}}) }}
52
+  {% autoescape false %}
53
+  {{ 'cgu_accepted'|trans({'%url%':path('info_cgu')}, 'userform') }}
54
+  {% endautoescape %}
55
+</div>
56
+
57
+<div class="field">
58
+  {{ form_errors(form.mail_newsletter) }}
59
+  {{ form_widget(form.mail_newsletter, {'attr':{}}) }}
60
+  {{ 'mail_newsletter'|trans({}, 'userform') }}
61
+</div>
62
+
63
+<div class="field">
64
+  {{ form_errors(form.mail_partner) }}
65
+  {{ form_widget(form.mail_partner, {'attr':{}}) }}
66
+  {{ 'mail_partner'|trans({}, 'userform') }}
67
+</div> 
68
+
69
+{{ form_rest(form) }}
70
+
71
+<div class="alignright">
72
+  <img class="loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
73
+  <input type="submit" class="button" value="{{ 'registration.submit'|trans({}, 'userui') }}" />
74
+</div>

+ 2 - 0
src/Muzich/UserBundle/Resources/views/Security/login.html.twig Wyświetl plik

@@ -22,6 +22,8 @@
22 22
         placeholder="{{ 'security.login.password'|trans({}, 'userui') }}""
23 23
       />
24 24
 
25
+      
26
+  <img class="loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
25 27
       <input type="submit" class="button" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}" />
26 28
       
27 29
       <div class="textcenter">