Преглед на файлове

Evolution #404: Inscription: confirmation de l'email et conséquences

Bastien Sevajol преди 11 години
родител
ревизия
2a86766b5e

+ 7 - 0
app/Resources/translations/userui.en.yml Целия файл

@@ -52,6 +52,13 @@ my_account:
52 52
   change_email:     Changer mon adresse email
53 53
   change_email_submit: Mettre à jour mon email
54 54
   choose_password:  Choisir un mot de passe pour mon compte
55
+  email_not_confirmed:
56
+    title:          Veuillez confirmer votre adresse email
57
+    text:           |
58
+                    Cette action nécéssite que vous confirmiez votre adresse mail.
59
+                    Pour cela veuillez cliquer sur le lien que nous vous avons envoyé par email.
60
+    button:         Renvoyer l'email de confirmation
61
+    help:           Pensez à vérifier le contenu de votre dossier SPAM
55 62
   address:
56 63
     title:          Mon adresse
57 64
     description:    Avec votre adresse Muzi.ch pourra vous avertir plus aisément des événements à venirs dans votre région.

+ 8 - 1
app/Resources/translations/userui.fr.yml Целия файл

@@ -43,7 +43,7 @@ title:
43 43
   change_username: Change son nom d'utilisateur
44 44
   
45 45
 my_account: 
46
-  title:          Mon compte
46
+  title:            Mon compte
47 47
   username:         Nom d'utilisateur
48 48
   change_username:  Modifier
49 49
   email:            Adresse email
@@ -53,6 +53,13 @@ my_account:
53 53
   change_email:     Changer mon adresse email
54 54
   change_email_submit: Mettre à jour mon email
55 55
   choose_password:  Choisir un mot de passe pour mon compte
56
+  email_not_confirmed:
57
+    title:          Veuillez confirmer votre adresse email
58
+    text:           |
59
+                    Cette action nécéssite que vous confirmiez votre adresse mail.
60
+                    Pour cela veuillez cliquer sur le lien que nous vous avons envoyé par email.
61
+    button:         Renvoyer l'email de confirmation
62
+    help:           Pensez à vérifier le contenu de votre dossier SPAM
56 63
   address:
57 64
     title:          Mon adresse
58 65
     description:    Avec votre adresse Muzi.ch pourra vous avertir plus aisément des événements à venir dans votre région.

+ 6 - 0
src/Muzich/CoreBundle/Controller/ElementController.php Целия файл

@@ -14,6 +14,7 @@ use Muzich\CoreBundle\Entity\User;
14 14
 use Muzich\CoreBundle\lib\AutoplayManager;
15 15
 use Muzich\CoreBundle\Searcher\ElementSearcher;
16 16
 use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
17
+use Muzich\CoreBundle\Security\Context as SecurityContext;
17 18
 
18 19
 class ElementController extends Controller
19 20
 {
@@ -572,6 +573,11 @@ class ElementController extends Controller
572 573
       return $response;
573 574
     }
574 575
     
576
+    if (($non_condition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION)) !== false)
577
+    {
578
+      return $this->jsonResponseError($non_condition);
579
+    }
580
+    
575 581
     if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
576 582
       ->findOneById($element_id)))
577 583
     {

+ 1 - 1
src/Muzich/CoreBundle/Entity/User.php Целия файл

@@ -268,7 +268,7 @@ class User extends BaseUser
268 268
    * @ORM\Column(type="boolean", nullable=false)
269 269
    * @var type boolean
270 270
    */
271
-  private $email_confirmed = false;
271
+  private $email_confirmed = true;
272 272
   
273 273
  /**
274 274
   * @ORM\Column(type="integer")

+ 27 - 0
src/Muzich/CoreBundle/Resources/public/css/main.css Целия файл

@@ -2140,4 +2140,31 @@ div.myaccount_part.flashing
2140 2140
 div.choose_password
2141 2141
 {
2142 2142
   text-align: center;
2143
+}
2144
+
2145
+div.center
2146
+{
2147
+  text-align: center;
2148
+}
2149
+
2150
+div#email_not_confirmed_box input
2151
+{
2152
+  margin: 10px;
2153
+}
2154
+
2155
+div#email_not_confirmed_box p.info
2156
+{
2157
+  font-style: italic;
2158
+}
2159
+
2160
+span.message_success
2161
+{
2162
+  font-weight: bold;
2163
+  color: green;
2164
+}
2165
+
2166
+span.message_error
2167
+{
2168
+  font-weight: bold;
2169
+  color: red;
2143 2170
 }

+ 106 - 53
src/Muzich/CoreBundle/Resources/public/js/muzich.js Целия файл

@@ -20,6 +20,41 @@ function hideAllMessages()
20 20
  }
21 21
 }
22 22
 
23
+function ResponseController()
24
+{
25
+  var propagate = function(response)
26
+  {
27
+    if (response.status === 'error')
28
+    {
29
+      if (response.error === 'UserEmailNotConfirmed')
30
+      {
31
+        open_ajax_popin(url_email_not_confirmed, function(){
32
+          
33
+        });
34
+      }
35
+      else if (response.error === 'UserNotConnected')
36
+      {
37
+        open_connection_or_subscription_window();
38
+      }
39
+    }
40
+  }
41
+  
42
+  this.execute = function(response, success_callback, failure_callback)
43
+  {
44
+    propagate(response);
45
+    if (response.status === 'success')
46
+    {
47
+      success_callback();
48
+    }
49
+    else
50
+    {
51
+      failure_callback();
52
+    }
53
+  }
54
+}
55
+
56
+window.ResponseController = new ResponseController();
57
+
23 58
 $(document).ready(function(){
24 59
 		 
25 60
   // Initially, hide them all
@@ -2238,7 +2273,7 @@ $(document).ready(function(){
2238 2273
    * 
2239 2274
    */
2240 2275
   
2241
- // Ouverture du formulaire de modification
2276
+ // Ouverture du formulaire de proposition de tags
2242 2277
   $('a.element_propose_tags').live('click', function(){
2243 2278
     
2244 2279
     var link = $(this);
@@ -2248,68 +2283,72 @@ $(document).ready(function(){
2248 2283
     
2249 2284
     $.getJSON($(this).attr('href'), function(response) {
2250 2285
       
2251
-      if (response.status == 'mustbeconnected')
2252
-      {
2253
-        $(location).attr('href', url_index);
2254
-      }
2255
-      
2256 2286
       li.find('img.element_loader').hide();
2257
-      
2258
-      if (response.status == 'success')
2259
-      {
2260
-        
2261
-        // On prépare le tagBox
2262
-        var table = li.find('table:first');
2263
-        li.find('div.tag_proposition').remove();
2264
-        table.after(response.html);
2287
+      window.ResponseController.execute(
2288
+        response,
2289
+        function(){
2290
+          // On prépare le tagBox
2291
+          var table = li.find('table:first');
2292
+          li.find('div.tag_proposition').remove();
2293
+          table.after(response.html);
2265 2294
 
2266
-        // Pour le click sur l'input de saisie de tag
2267
-        //li.find('ul.tagbox li.input input[type="text"]').formDefaults();
2295
+          // Pour le click sur l'input de saisie de tag
2296
+          //li.find('ul.tagbox li.input input[type="text"]').formDefaults();
2268 2297
 
2269
-        var options = new Array();
2270
-        options.form_name  = response.form_name;
2271
-        options.tag_init   = response.tags;
2298
+          var options = new Array();
2299
+          options.form_name  = response.form_name;
2300
+          options.tag_init   = response.tags;
2272 2301
 
2273
-        ajax_query_timestamp = null;
2302
+          ajax_query_timestamp = null;
2274 2303
 
2275
-        //$("#tags_prompt_list_"+response.form_name).tagBox(options);
2276
-      
2277
-      // On rend ce formulaire ajaxFormable
2278
-      $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
2279
-        li = $(this).parents('li.element');
2280
-        li.find('img.element_loader').show();
2281
-      });
2282
-      $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
2283
-        
2284
-        if (response.status == 'mustbeconnected')
2285
-        {
2286
-          $(location).attr('href', url_index);
2287
-        }
2288
-                
2289
-        if (response.status == 'success')
2290
-        {
2291
-          li = $('li#'+response.dom_id);
2292
-          li.find('img.element_loader').hide();
2293
-          li.find('form')
2294
-          li.find('div.tag_proposition').remove();
2295
-        }
2296
-        else if (response.status == 'error')
2297
-        {
2298
-          li.find('img.element_loader').hide();
2299
-          li.find('ul.error_list').remove();
2300
-          var ul_errors = $('<ul>').addClass('error_list');
2301
-          
2302
-          for (i in response.errors)
2304
+          //$("#tags_prompt_list_"+response.form_name).tagBox(options);
2305
+
2306
+        // On rend ce formulaire ajaxFormable
2307
+        $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
2308
+          li = $(this).parents('li.element');
2309
+          li.find('img.element_loader').show();
2310
+        });
2311
+        $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
2312
+
2313
+          if (response.status == 'mustbeconnected')
2303 2314
           {
2304
-            ul_errors.append($('<li>').append(response.errors[i]));
2315
+            $(location).attr('href', url_index);
2305 2316
           }
2317
+
2318
+          if (response.status == 'success')
2319
+          {
2320
+            li = $('li#'+response.dom_id);
2321
+            li.find('img.element_loader').hide();
2322
+            li.find('form')
2323
+            li.find('div.tag_proposition').remove();
2324
+          }
2325
+          else if (response.status == 'error')
2326
+          {
2327
+            li.find('img.element_loader').hide();
2328
+            li.find('ul.error_list').remove();
2329
+            var ul_errors = $('<ul>').addClass('error_list');
2330
+
2331
+            for (i in response.errors)
2332
+            {
2333
+              ul_errors.append($('<li>').append(response.errors[i]));
2334
+            }
2335
+
2336
+            li.find('div.tag_proposition div.tags_prompt').prepend(ul_errors);
2337
+          }
2338
+
2339
+        });
2340
+        },
2341
+        function(){
2306 2342
           
2307
-          li.find('div.tag_proposition div.tags_prompt').prepend(ul_errors);
2308 2343
         }
2309
-        
2310
-      });
2344
+      );
2345
+      
2346
+//      if (response.status === 'mustbeconnected')
2347
+//      {
2348
+//        $(location).attr('href', url_index);
2349
+//      }
2350
+      
2311 2351
       
2312
-      }
2313 2352
     });
2314 2353
     return false;
2315 2354
   });
@@ -2908,6 +2947,20 @@ $(document).ready(function(){
2908 2947
       open_connection_or_subscription_window(true);
2909 2948
     });
2910 2949
    
2950
+   /*
2951
+    * Confirm email ajax
2952
+    */
2953
+   
2954
+   $('div#email_not_confirmed_box input').live('click', function(){
2955
+     $('div#email_not_confirmed_box img.loader').show();
2956
+     $.getJSON(url_send_email_confirmation, function(response) {
2957
+       $('div#email_not_confirmed_box img.loader').hide();
2958
+       $('div#email_not_confirmed_box div.center').html(
2959
+         '<span class="message_'+response.status+'">'+response.message+'</span>'      
2960
+       );
2961
+     });
2962
+   });
2963
+   
2911 2964
 });
2912 2965
 
2913 2966
 function open_ajax_popin(url, callback)

+ 2 - 0
src/Muzich/CoreBundle/Resources/views/Layout/head_js.html.twig Целия файл

@@ -123,6 +123,8 @@
123 123
   url_get_embed_for_element = "{{ path('url_get_embed_for_element') }}";
124 124
   
125 125
   url_subscription_or_login = "{{ path('subscribe_or_login') }}";
126
+  url_email_not_confirmed = "{{ path('email_not_confirmed') }}";
127
+  url_send_email_confirmation = "{{ path('send_email_confirmation') }}";
126 128
   
127 129
   config_player_youtube_width = "{{ player_config_youtube_width }}";
128 130
   config_player_youtube_height = "{{ player_config_youtube_height }}";

+ 84 - 26
src/Muzich/CoreBundle/Security/Context.php Целия файл

@@ -22,44 +22,88 @@ class Context
22 22
   const AFFECT_NO_SCORING = 1;
23 23
   
24 24
   const CONDITION_USER_EMAIL_NOT_CONFIRMED = 'UserEmailNotConfirmed';
25
+  const CONDITION_USER_NOT_CONNECTED = 'UserNotConnected';
25 26
   
26 27
   static $affecteds_actions = array(
27 28
     self::AFFECT_CANT_MAKE => array(
28
-      self::ACTION_ELEMENT_ADD,
29
-      self::ACTION_ELEMENT_NOTE,
30
-      self::ACTION_COMMENT_ALERT,
31
-      self::ACTION_ELEMENT_ALERT,
32
-      self::ACTION_TAG_ADD,
33
-      self::ACTION_ELEMENT_TAGS_PROPOSITION,
34
-      self::ACTION_GROUP_ADD
29
+      self::ACTION_ELEMENT_ADD => array(
30
+        self::CONDITION_USER_NOT_CONNECTED,
31
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
32
+      ),
33
+      self::ACTION_ELEMENT_NOTE => array(
34
+        self::CONDITION_USER_NOT_CONNECTED,
35
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
36
+      ),
37
+      self::ACTION_COMMENT_ALERT => array(
38
+        self::CONDITION_USER_NOT_CONNECTED,
39
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
40
+      ),
41
+      self::ACTION_ELEMENT_ALERT => array(
42
+        self::CONDITION_USER_NOT_CONNECTED,
43
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
44
+      ),
45
+      self::ACTION_TAG_ADD => array(
46
+        self::CONDITION_USER_NOT_CONNECTED,
47
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
48
+      ),
49
+      self::ACTION_ELEMENT_TAGS_PROPOSITION => array(
50
+        self::CONDITION_USER_NOT_CONNECTED,
51
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
52
+      ),
53
+      self::ACTION_GROUP_ADD => array(
54
+        self::CONDITION_USER_NOT_CONNECTED,
55
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
56
+      ),
57
+      self::ACTION_ELEMENT_ADD_TO_FAVORITES => array(
58
+        self::CONDITION_USER_NOT_CONNECTED
59
+      ),
60
+      self::ACTION_COMMENT_ADD => array(
61
+        self::CONDITION_USER_NOT_CONNECTED,
62
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
63
+      ),
64
+      self::ACTION_USER_FOLLOW => array(
65
+        self::CONDITION_USER_NOT_CONNECTED
66
+      )
35 67
     ),
36 68
     self::AFFECT_NO_SCORING => array(
37
-      self::ACTION_ELEMENT_NOTE,
38
-      self::ACTION_ELEMENT_ADD_TO_FAVORITES,
39
-      self::ACTION_ELEMENT_TAGS_PROPOSITION,
40
-      self::ACTION_USER_FOLLOW
41
-    )
42
-  );
43
-  
44
-  static $affecteds_conditions = array(
45
-    self::AFFECT_CANT_MAKE => array(
46
-      self::CONDITION_USER_EMAIL_NOT_CONFIRMED
47
-    ),
48
-    self::AFFECT_NO_SCORING => array(
49
-      self::CONDITION_USER_EMAIL_NOT_CONFIRMED
69
+      self::ACTION_ELEMENT_NOTE => array(
70
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
71
+      ),
72
+      self::ACTION_ELEMENT_ADD_TO_FAVORITES => array(
73
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
74
+      ),
75
+      self::ACTION_ELEMENT_TAGS_PROPOSITION => array(
76
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
77
+      ),
78
+      self::ACTION_USER_FOLLOW => array(
79
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
80
+      )
50 81
     )
51 82
   );
52 83
   
53 84
   private $user;
85
+  private $anonymous = false;
54 86
   
55
-  public function __construct(User $user)
87
+  public function __construct($user)
56 88
   {
57
-    $this->user = $user;
89
+    if ($user instanceof User)
90
+    {
91
+      $this->user = $user;
92
+    }
93
+    else if ($user == 'anon.')
94
+    {
95
+      $this->user = new User();
96
+      $this->anonymous = true;
97
+    }
98
+    else
99
+    {
100
+      throw new \Exception('Unable to determine type of user');
101
+    }
58 102
   }
59 103
   
60 104
   public function canMakeAction($action)
61 105
   {
62
-    if ($this->actionIsAffectedBy(self::AFFECT_CANT_MAKE, $action))
106
+    if ($this->actionIsAffectedBy(self::AFFECT_CANT_MAKE, $action) !== false)
63 107
       return false;
64 108
     return true;
65 109
   }
@@ -69,7 +113,7 @@ class Context
69 113
     if (!array_key_exists($affect, self::$affecteds_actions))
70 114
       throw new \Exception("Unknow action $action");
71 115
     
72
-    if (in_array($action, self::$affecteds_actions[$affect]))
116
+    if (array_key_exists($action, self::$affecteds_actions[$affect]))
73 117
       return true;
74 118
     return false;
75 119
   }
@@ -78,12 +122,12 @@ class Context
78 122
   {
79 123
     if ($this->actionCanBeAffectedBy($affect, $action))
80 124
     {
81
-      foreach (self::$affecteds_conditions[$affect] as $affected_condition)
125
+      foreach (self::$affecteds_actions[$affect][$action] as $affected_condition)
82 126
       {
83 127
         $affected_condition_method = 'is'.$affected_condition;
84 128
         if ($this->$affected_condition_method())
85 129
         {
86
-          return true;
130
+          return $affected_condition;
87 131
         }
88 132
       }
89 133
     }
@@ -91,6 +135,15 @@ class Context
91 135
     return false;
92 136
   }
93 137
   
138
+  protected function isUserNotConnected()
139
+  {
140
+    if ($this->anonymous)
141
+    {
142
+      return true;
143
+    }
144
+    return false;
145
+  }
146
+  
94 147
   protected function isUserEmailNotConfirmed()
95 148
   {
96 149
     if ($this->user->isEmailConfirmed())
@@ -100,4 +153,9 @@ class Context
100 153
     return true;
101 154
   }
102 155
   
156
+  public function getConditionForAffectedAction($action)
157
+  {
158
+    
159
+  }
160
+  
103 161
 }

+ 33 - 4
src/Muzich/CoreBundle/Tests/Security/ContextTest.php Целия файл

@@ -17,15 +17,16 @@ class ContextTest extends \PHPUnit_Framework_TestCase
17 17
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_COMMENT_ALERT));
18 18
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_ALERT));
19 19
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_TAG_ADD));
20
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_COMMENT_ADD));
20 21
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION));
21 22
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_GROUP_ADD));
22 23
     $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_USER_FOLLOW));
23 24
     $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
24 25
     
25
-    $this->assertTrue($secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_ELEMENT_NOTE));
26
-    $this->assertTrue($secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION));
27
-    $this->assertTrue($secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_USER_FOLLOW));
28
-    $this->assertTrue($secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
26
+    $this->assertEquals('UserEmailNotConfirmed', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_ELEMENT_NOTE));
27
+    $this->assertEquals('UserEmailNotConfirmed', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION));
28
+    $this->assertEquals('UserEmailNotConfirmed', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_USER_FOLLOW));
29
+    $this->assertEquals('UserEmailNotConfirmed', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
29 30
   }
30 31
   
31 32
   public function testActionsWithConfirmedEmailUser()
@@ -39,6 +40,7 @@ class ContextTest extends \PHPUnit_Framework_TestCase
39 40
     $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_COMMENT_ALERT));
40 41
     $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_ALERT));
41 42
     $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_TAG_ADD));
43
+    $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_COMMENT_ADD));
42 44
     $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION));
43 45
     $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_GROUP_ADD));
44 46
     $this->assertTrue($secutiry_context->canMakeAction(SecurityContext::ACTION_USER_FOLLOW));
@@ -50,4 +52,31 @@ class ContextTest extends \PHPUnit_Framework_TestCase
50 52
     $this->assertFalse($secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_NO_SCORING, SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
51 53
   }
52 54
   
55
+  public function testCanMakeActionsWithNotConnectedUser()
56
+  {
57
+    $secutiry_context = new SecurityContext('anon.');
58
+    
59
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_ADD));
60
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_NOTE));
61
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_COMMENT_ALERT));
62
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_ALERT));
63
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_TAG_ADD));
64
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_COMMENT_ADD));
65
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION));
66
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_GROUP_ADD));
67
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_USER_FOLLOW));
68
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
69
+    
70
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_ADD));
71
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_NOTE));
72
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_COMMENT_ALERT));
73
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_ALERT));
74
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_TAG_ADD));
75
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_COMMENT_ADD));
76
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_COMMENT_ADD));
77
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION));
78
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_GROUP_ADD));
79
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
80
+  }
81
+  
53 82
 }

+ 35 - 2
src/Muzich/CoreBundle/lib/Controller.php Целия файл

@@ -12,6 +12,7 @@ use Muzich\CoreBundle\Searcher\GlobalSearcher;
12 12
 use Muzich\CoreBundle\Entity\Element;
13 13
 use Muzich\CoreBundle\Entity\Presubscription;
14 14
 use Muzich\CoreBundle\Entity\User;
15
+use Muzich\CoreBundle\Security\Context as SecurityContext;
15 16
 
16 17
 class Controller extends BaseController
17 18
 {
@@ -19,6 +20,8 @@ class Controller extends BaseController
19 20
   protected static $user = null;
20 21
   protected static $user_personal_query = null;
21 22
   protected static $tags = array();
23
+  /** @var SecurityContext */
24
+  protected $security_context;
22 25
   
23 26
   /**
24 27
    * Authenticate a user with Symfony Security
@@ -405,6 +408,15 @@ class Controller extends BaseController
405 408
     return $response;
406 409
   }
407 410
   
411
+  protected function jsonResponseError($error_type, $error_content = array())
412
+  {
413
+    return $this->jsonResponse(array(
414
+      'status' => 'error',
415
+      'error'  => $error_type,
416
+      'data'   => $error_content
417
+    ));
418
+  }
419
+  
408 420
   protected function jsonNotFoundResponse()
409 421
   {
410 422
     $response = new Response(json_encode(array(
@@ -566,13 +578,14 @@ class Controller extends BaseController
566 578
     return false;
567 579
   }
568 580
   
569
-  protected function sendEmailconfirmationEmail()
581
+  protected function sendEmailconfirmationEmail($set_send_time = true)
570 582
   {
571 583
     $user = $this->getUser();
572 584
     
573 585
     $tokenGenerator = $this->container->get('fos_user.util.token_generator');
574 586
     $user->setConfirmationToken($tokenGenerator->generateToken());
575
-    $user->setEmailConfirmationSentTimestamp(time());
587
+    if ($set_send_time)
588
+      $user->setEmailConfirmationSentTimestamp(time());
576 589
     
577 590
     $token = hash('sha256', $user->getConfirmationToken().$user->getEmail());
578 591
     $url = $this->get('router')->generate('email_confirm', array('token' => $token), true);
@@ -606,4 +619,24 @@ class Controller extends BaseController
606 619
     return $this->container->getParameter($key);
607 620
   }
608 621
   
622
+  protected function userHaveNonConditionToMakeAction($action)
623
+  {
624
+    $secutity_context = $this->getSecurityContext();
625
+    if (($condition = $secutity_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, $action)) !== false)
626
+    {
627
+      return $condition;
628
+    }
629
+    
630
+    return false;
631
+  }
632
+  
633
+  /** @return SecurityContext */
634
+  protected function getSecurityContext()
635
+  {
636
+    if ($this->security_context == null)
637
+      $this->security_context = new SecurityContext($this->getUser());
638
+    
639
+    return $this->security_context;
640
+  }
641
+  
609 642
 }

+ 14 - 3
src/Muzich/UserBundle/Controller/UserController.php Целия файл

@@ -150,7 +150,7 @@ class UserController extends Controller
150 150
       $response = $this->getSuccessRegistrationResponse();
151 151
       $userManager->updateUser($user);
152 152
       $this->authenticateUser($user, $response);
153
-      $this->sendEmailconfirmationEmail();
153
+      $this->sendEmailconfirmationEmail(false);
154 154
       return $response;
155 155
     }
156 156
     
@@ -165,12 +165,15 @@ class UserController extends Controller
165 165
   /** @return User */
166 166
   protected function getNewUser()
167 167
   {
168
+    // Ce serais mieux d'appeler notre user manager et d'utiliser notre createUser
169
+    // avec ce code.
168 170
     $userManager = $this->container->get('fos_user.user_manager');
169 171
     $user = $userManager->createUser();
170 172
     $user->setUsername($this->generateUsername());
171 173
     $user->setPlainPassword($this->generatePassword(32));
172 174
     $user->setEnabled(true);
173 175
     $user->setCguAccepted(true);
176
+    $user->setEmailConfirmed(false);
174 177
     $user->setUsernameUpdatable(true);
175 178
     $user->setPasswordSet(false);
176 179
     return $user;
@@ -760,7 +763,7 @@ class UserController extends Controller
760 763
     ;
761 764
   }
762 765
   
763
-  public function sendEmailConfirmAction(Request $request)
766
+  public function sendEmailConfirmAction(Request $request, $set_send_time = true)
764 767
   {
765 768
     $user = $this->getUser();
766 769
     if ($user->isEmailConfirmed())
@@ -792,7 +795,7 @@ class UserController extends Controller
792 795
       return new RedirectResponse($this->generateUrl('my_account'));
793 796
     }
794 797
     
795
-    $this->sendEmailconfirmationEmail();
798
+    $this->sendEmailconfirmationEmail($set_send_time);
796 799
     
797 800
     if ($request->isXmlHttpRequest())
798 801
     {
@@ -823,4 +826,12 @@ class UserController extends Controller
823 826
     return new RedirectResponse($this->generateUrl('my_account'));
824 827
   }
825 828
   
829
+  public function showEmailNotConfirmedAction()
830
+  {
831
+    return $this->jsonResponse(array(
832
+      'status' => 'success',
833
+      'data' => $this->render('MuzichUserBundle:Account:email_not_confirmed.html.twig')->getContent()
834
+    ));
835
+  }
836
+  
826 837
 }

+ 9 - 0
src/Muzich/UserBundle/Resources/config/routing.yml Целия файл

@@ -76,3 +76,12 @@ subscribe_or_login:
76 76
 change_username:
77 77
   pattern: /account/username/update
78 78
   defaults: { _controller: MuzichUserBundle:User:changeUsername }
79
+
80
+email_not_confirmed:
81
+  pattern: /account/email-not-confirmed
82
+  defaults: { _controller: MuzichUserBundle:User:showEmailNotConfirmed }
83
+
84
+send_email_confirmation:
85
+  pattern: /account/send-email-confirmation
86
+  defaults: { _controller: MuzichUserBundle:User:sendEmailConfirm }
87
+    

+ 14 - 0
src/Muzich/UserBundle/Resources/views/Account/email_not_confirmed.html.twig Целия файл

@@ -0,0 +1,14 @@
1
+
2
+<div id="email_not_confirmed_box">
3
+  
4
+  <h2>{{ 'my_account.email_not_confirmed.title'|trans({}, 'userui') }}</h2>
5
+
6
+  <p>{{ 'my_account.email_not_confirmed.text'|trans({}, 'userui') }}</p>
7
+  
8
+  <div class="center">
9
+    <input type="button" class="button" value="{{ 'my_account.email_not_confirmed.button'|trans({}, 'userui') }}" /><img class="loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
10
+  </div>
11
+  
12
+  <p class="info">{{ 'my_account.email_not_confirmed.help'|trans({}, 'userui') }}</p>
13
+  
14
+</div>