Passed
Pull Request — master (#1428)
by Nick
06:09
created
www/docs/user/login/fb.php 2 patches
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
     If the input is not OK, the form is displayed again with error messages.
10 10
 */
11 11
 
12
-$new_style_template = TRUE;
12
+$new_style_template = true;
13 13
 
14 14
 include_once '../../../includes/easyparliament/init.php';
15 15
 # need to include this as login code uses error_message
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@
 block discarded – undo
27 27
 
28 28
 $data['fb_login_url'] = $login->getLoginURL();
29 29
 if (isset($data['token'])) {
30
-  $success = $login->loginUser($data['token']);
31
-  if (!$success) {
30
+    $success = $login->loginUser($data['token']);
31
+    if (!$success) {
32 32
     $data['error'] = 'Could not login using Facebook token';
33 33
     \MySociety\TheyWorkForYou\Renderer::output('login/facebook', $data);
34
-  }
34
+    }
35 35
 } else {
36 36
     \MySociety\TheyWorkForYou\Renderer::output('login/facebook', $data);
37 37
 }
Please login to merge, or discard this patch.
classes/User.php 2 patches
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 class User {
15
-    public function getUserDetails($user_id = False) {
15
+    public function getUserDetails($user_id = false) {
16 16
         global $THEUSER;
17 17
 
18 18
         $user = $THEUSER;
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
             }
251 251
 
252 252
             if ($details['email'] != $THEUSER->email()) {
253
-                $results['email_changed'] = True;
253
+                $results['email_changed'] = true;
254 254
             }
255 255
 
256 256
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
         $data['url'] = $user->url();
33 33
         $data['email'] = $user->email();
34 34
         $data['optin'] = $user->optin() == true ? "Yes" : "No";
35
-        $data['postcode']	= $user->postcode();
35
+        $data['postcode'] = $user->postcode();
36 36
         $data['website']	= $user->url();
37
-        $data['registrationtime']	= $user->registrationtime();
38
-        $data['status']= $user->status();
37
+        $data['registrationtime'] = $user->registrationtime();
38
+        $data['status'] = $user->status();
39 39
         $data["deleted"] = $user->deleted();
40 40
         $data["confirmed"] = $user->confirmed();
41 41
         $data["status"] = $user->status();
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
         // Who are we updating? $THEUSER or someone else?
243 243
         if ($this_page == "otheruseredit") {
244 244
             $who = 'the user’s';
245
-            $success = $THEUSER->update_other_user ( $details );
245
+            $success = $THEUSER->update_other_user($details);
246 246
         } else {
247 247
             $who = 'your';
248
-            $success = $THEUSER->update_self ( $details );
248
+            $success = $THEUSER->update_self($details);
249 249
         }
250 250
 
251 251
 
@@ -277,12 +277,12 @@  discard block
 block discarded – undo
277 277
         // If this goes well, the user will have their data
278 278
         // added to the database and a confirmation email
279 279
         // will be sent to them.
280
-        $success = $THEUSER->add ( $details );
280
+        $success = $THEUSER->add($details);
281 281
 
282 282
         $errors = array();
283 283
 
284 284
         if (!$success) {
285
-            $errors["db"] = "Sorry, we were unable to create an account for you. Please <a href=\"mailto:". str_replace('@', '&#64;', CONTACTEMAIL) . "\">let us know</a>. Thanks.";
285
+            $errors["db"] = "Sorry, we were unable to create an account for you. Please <a href=\"mailto:" . str_replace('@', '&#64;', CONTACTEMAIL) . "\">let us know</a>. Thanks.";
286 286
         }
287 287
 
288 288
         return $errors;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 
291 291
     public function getRep($cons_type, $mp_house) {
292 292
         global $THEUSER;
293
-        if ( !$THEUSER->has_postcode() ) {
293
+        if (!$THEUSER->has_postcode()) {
294 294
             return array();
295 295
         }
296 296
 
@@ -303,11 +303,11 @@  discard block
 block discarded – undo
303 303
         // Scottish homepage
304 304
         try {
305 305
             $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($THEUSER->postcode());
306
-            if ( isset($constituencies[$cons_type]) ) {
306
+            if (isset($constituencies[$cons_type])) {
307 307
                 $constituency = $constituencies[$cons_type];
308 308
                 $MEMBER = new Member(array('constituency'=>$constituency, 'house'=> $mp_house));
309 309
             }
310
-        } catch ( MemberException $e ) {
310
+        } catch (MemberException $e) {
311 311
             return array();
312 312
         }
313 313
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
         $mreg = array();
345 345
         if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) {
346 346
             $reps = \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, $mp_house, $cons_type);
347
-            foreach ( $reps as $rep ) {
347
+            foreach ($reps as $rep) {
348 348
                 $member = new \MySociety\TheyWorkForYou\Member(array('person_id' => $rep['person_id']));
349 349
                 $mreg[$rep['person_id']] = $this->constructMPData($member, $THEUSER, $mp_house);
350 350
             }
Please login to merge, or discard this patch.
www/docs/user/index.php 3 patches
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * page so leave it like that for now.
6 6
  */
7 7
 
8
-$new_style_template = TRUE;
8
+$new_style_template = true;
9 9
 
10 10
 include_once '../../includes/easyparliament/init.php';
11 11
 # need to include this as login code uses error_message
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                 $data['errors'] = $results['errors'];
128 128
                 $template = 'user/form';
129 129
             } else {
130
-                $data['edited'] = True;
130
+                $data['edited'] = true;
131 131
                 if (isset($results['email_changed'])) {
132 132
                     $data['email_changed'] = $results['email_changed'];
133 133
                 }
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -107,10 +107,10 @@
 block discarded – undo
107 107
 
108 108
 // if data has been submitted then handle that
109 109
 if (
110
-      get_http_var("submitted") == "true" && (
110
+        get_http_var("submitted") == "true" && (
111 111
         $this_page == 'useredit' || $this_page == 'otheruseredit' || $this_page == 'userjoin'
112
-      )
113
-   ) {
112
+        )
113
+    ) {
114 114
     // Put all the user-submitted data in an array.
115 115
     $data = $user->getUpdateDetails($this_page, $THEUSER);
116 116
     $data['ret'] = get_http_var("ret");
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
         // We need a user_id. So make sure that exists.
31 31
         // And make sure the user is allowed to do this!
32 32
         $template = 'user/form';
33
-        if (is_numeric( get_http_var("u") ) && $THEUSER->is_able_to("edituser")) {
33
+        if (is_numeric(get_http_var("u")) && $THEUSER->is_able_to("edituser")) {
34 34
 
35 35
             $data = $user->getUserDetails(get_http_var('u'));
36 36
             $data['showall'] = true;
Please login to merge, or discard this patch.
www/includes/easyparliament/templates/html/user/form.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@
 block discarded – undo
125 125
                   <span class="label">Security status:</span>
126 126
                   <span class="formw"><select name="status">
127 127
                   <?php
128
-                  foreach ($statuses as $n => $status_name) { ?>
128
+                    foreach ($statuses as $n => $status_name) { ?>
129 129
                     <option value="<?= $status_name ?>"<?= $status_name == $status ? ' selected' : '' ?>>
130 130
                       <?= $status_name ?>
131 131
                     </option>
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
                 <input type="hidden" name="pg" value="edit">
39 39
               </form>
40 40
             <?php } else { ?>
41
-              <?php if (isset($showall) && $showall == True && isset($user_id)) { ?>
41
+              <?php if (isset($showall) && $showall == true && isset($user_id)) { ?>
42 42
               <h1>Edit the user&rsquo;s details</h1>
43 43
               <?php } else { ?>
44 44
               <h1>Edit your details</h1>
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
                 <span class="formw"><input type="text" name="url" id="url" value="<?= _htmlentities($url) ?>" maxlength="255" size="20" class="form"> <small>Optional and public</small></span>
132 132
                 </div>
133 133
 
134
-                <?php if (isset($showall) && $showall == True) { ?>
134
+                <?php if (isset($showall) && $showall == true) { ?>
135 135
                   <?php if (isset($errors['status'])) { ?>
136 136
                   <p class="error">
137 137
                       <?= $errors['status'] ?>
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
                 <input type="hidden" name="submitted" value="true">
193 193
                 <input type="hidden" name="pg" value="<?= _htmlentities($pg) ?>">
194 194
 
195
-                <?php if (isset($showall) && $showall == True && isset($user_id)) { ?>
195
+                <?php if (isset($showall) && $showall == true && isset($user_id)) { ?>
196 196
                     <input type="hidden" name="u" value="<?= _htmlentities($user_id) ?>">
197 197
                 <?php } ?>
198 198
 
Please login to merge, or discard this patch.
www/includes/easyparliament/templates/html/user/index.php 2 patches
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
           <h1>Your details</h1>
13 13
           <?php if (isset($edited)) { ?>
14 14
             <p>
15
-              <strong>have been updated<?= isset($email_changed) && $email_changed == True ? " and we&rsquo;ve sent a confirmation email to your new email address" : '' ?>.</strong>
15
+              <strong>have been updated<?= isset($email_changed) && $email_changed == true ? " and we&rsquo;ve sent a confirmation email to your new email address" : '' ?>.</strong>
16 16
             </p>
17 17
           <?php } else { ?>
18 18
           <p>
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 
38 38
           <div class="row">
39 39
             <span class="label">Website</span>
40
-            <span class="formw"><?= $website == '' ? 'none' : '<a rel="nofollow" href="' . _htmlentities($website) . '">'. _htmlentities($website) . '</a>' ?></span>
40
+            <span class="formw"><?= $website == '' ? 'none' : '<a rel="nofollow" href="' . _htmlentities($website) . '">' . _htmlentities($website) . '</a>' ?></span>
41 41
           </div>
42 42
 
43 43
           <?php if ($facebook_user) { ?>
Please login to merge, or discard this patch.
www/includes/easyparliament/user.php 4 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -851,8 +851,8 @@  discard block
 block discarded – undo
851 851
         if ($cookie == '') {
852 852
             $cookie = get_cookie_var("facebook_id");
853 853
             if ($cookie != '') {
854
-              $this->facebook_user = True;
855
-              twfy_debug("THEUSER", "is facebook login");
854
+                $this->facebook_user = True;
855
+                twfy_debug("THEUSER", "is facebook login");
856 856
             }
857 857
         }
858 858
 
@@ -873,36 +873,36 @@  discard block
 block discarded – undo
873 873
                     // And make sure the user hasn't been "deleted".
874 874
 
875 875
                     if ($this->facebook_user) {
876
-                      if (md5($this->facebook_token()) == $matches[2] && $this->deleted() == false) {
877
-                          twfy_debug ("THEUSER", "init SUCCESS: setting as logged in");
878
-                          $this->loggedin = true;
879
-                      } elseif (md5 ($this->facebook_token()) != $matches[2]) {
880
-                          twfy_debug ("THEUSER", "init FAILED: Facebook token doesn't match cookie");
881
-                          $this->loggedin = false;
882
-                      } else {
883
-                          twfy_debug ("THEUSER", "init FAILED: User is deleted");
884
-                          $this->loggedin = false;
885
-                      }
876
+                        if (md5($this->facebook_token()) == $matches[2] && $this->deleted() == false) {
877
+                            twfy_debug ("THEUSER", "init SUCCESS: setting as logged in");
878
+                            $this->loggedin = true;
879
+                        } elseif (md5 ($this->facebook_token()) != $matches[2]) {
880
+                            twfy_debug ("THEUSER", "init FAILED: Facebook token doesn't match cookie");
881
+                            $this->loggedin = false;
882
+                        } else {
883
+                            twfy_debug ("THEUSER", "init FAILED: User is deleted");
884
+                            $this->loggedin = false;
885
+                        }
886 886
                     } else {
887
-                      if (md5($this->password()) == $matches[2] && $this->deleted() == false) {
888
-                          // The correct password is in the cookie,
889
-                          // and the user isn't deleted, so set the user to be logged in.
887
+                        if (md5($this->password()) == $matches[2] && $this->deleted() == false) {
888
+                            // The correct password is in the cookie,
889
+                            // and the user isn't deleted, so set the user to be logged in.
890 890
 
891
-                          // This would be an appropriate place to call other functions
892
-                          // that might set user info that only a logged-in user is going
893
-                          // to need. Their preferences and saved things or something.
891
+                            // This would be an appropriate place to call other functions
892
+                            // that might set user info that only a logged-in user is going
893
+                            // to need. Their preferences and saved things or something.
894 894
 
895 895
 
896
-                          twfy_debug ("THEUSER init SUCCEEDED", "setting as logged in");
897
-                          $this->loggedin = true;
896
+                            twfy_debug ("THEUSER init SUCCEEDED", "setting as logged in");
897
+                            $this->loggedin = true;
898 898
 
899
-                      } elseif (md5 ($this->password()) != $matches[2]) {
900
-                          twfy_debug ("THEUSER init FAILED", "Password doesn't match cookie");
901
-                          $this->loggedin = false;
902
-                      } else {
903
-                          twfy_debug ("THEUSER init FAILED", "User is deleted");
904
-                          $this->loggedin = false;
905
-                      }
899
+                        } elseif (md5 ($this->password()) != $matches[2]) {
900
+                            twfy_debug ("THEUSER init FAILED", "Password doesn't match cookie");
901
+                            $this->loggedin = false;
902
+                        } else {
903
+                            twfy_debug ("THEUSER init FAILED", "User is deleted");
904
+                            $this->loggedin = false;
905
+                        }
906 906
                     }
907 907
 
908 908
                 } else {
Please login to merge, or discard this patch.
Braces   +27 added lines, -9 removed lines patch added patch discarded remove patch
@@ -445,9 +445,15 @@  discard block
 block discarded – undo
445 445
                 // Generates the password ....
446 446
                 for ($x=0; $x < 6;) {
447 447
                     $y = rand(1,1000);
448
-                    if($y>350 && $y<601) $d=chr(rand(48,57));
449
-                    if($y<351) $d=chr(rand(65,90));
450
-                    if($y>600) $d=chr(rand(97,122));
448
+                    if($y>350 && $y<601) {
449
+                        $d=chr(rand(48,57));
450
+                    }
451
+                    if($y<351) {
452
+                        $d=chr(rand(65,90));
453
+                    }
454
+                    if($y>600) {
455
+                        $d=chr(rand(97,122));
456
+                    }
451 457
                     if ($d!=$o && !preg_match('#[O01lI]#', $d)) {
452 458
                         $o=$d; $pwd.=$d; $x++;
453 459
                     }
@@ -1171,8 +1177,12 @@  discard block
 block discarded – undo
1171 1177
 
1172 1178
     public function confirm_email($token, $redirect=true) {
1173 1179
         $arg = '';
1174
-        if (strstr($token, '::')) $arg = '::';
1175
-        if (strstr($token, '-')) $arg = '-';
1180
+        if (strstr($token, '::')) {
1181
+            $arg = '::';
1182
+        }
1183
+        if (strstr($token, '-')) {
1184
+            $arg = '-';
1185
+        }
1176 1186
         list($user_id, $registrationtoken) = explode($arg, $token);
1177 1187
 
1178 1188
         if (!is_numeric($user_id) || $registrationtoken == '') {
@@ -1254,8 +1264,12 @@  discard block
 block discarded – undo
1254 1264
 
1255 1265
         // Split the token into its parts.
1256 1266
         $arg = '';
1257
-        if (strstr($token, '::')) $arg = '::';
1258
-        if (strstr($token, '-')) $arg = '-';
1267
+        if (strstr($token, '::')) {
1268
+            $arg = '::';
1269
+        }
1270
+        if (strstr($token, '-')) {
1271
+            $arg = '-';
1272
+        }
1259 1273
         list($user_id, $registrationtoken) = explode($arg, $token);
1260 1274
 
1261 1275
         if (!is_numeric($user_id) || $registrationtoken == '') {
@@ -1385,15 +1399,19 @@  discard block
 block discarded – undo
1385 1399
         // not-logged-in users.
1386 1400
 
1387 1401
         $this->postcode = $pc;
1388
-        if (!headers_sent()) // if in debug mode
1402
+        if (!headers_sent()) {
1403
+            // if in debug mode
1389 1404
             setcookie (POSTCODE_COOKIE, $pc, time()+7*86400, "/", COOKIEDOMAIN);
1405
+        }
1390 1406
 
1391 1407
         twfy_debug('USER', "Set the cookie named '" . POSTCODE_COOKIE . " to '$pc' for " . COOKIEDOMAIN . " domain");
1392 1408
     }
1393 1409
 
1394 1410
     public function unset_postcode_cookie() {
1395
-        if (!headers_sent()) // if in debug mode
1411
+        if (!headers_sent()) {
1412
+            // if in debug mode
1396 1413
             setcookie (POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN);
1414
+        }
1397 1415
     }
1398 1416
 
1399 1417
     // mostly here for updating from facebook where we do not need
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
         if ($cookie == '') {
873 873
             $cookie = get_cookie_var("facebook_id");
874 874
             if ($cookie != '') {
875
-              $this->facebook_user = True;
875
+              $this->facebook_user = true;
876 876
               twfy_debug("THEUSER", "is facebook login");
877 877
             }
878 878
         }
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 
1075 1075
         twfy_debug("USER", "logging in user from facebook " . $this->user_id);
1076 1076
 
1077
-        $this->loggedin = True;
1077
+        $this->loggedin = true;
1078 1078
         $this->_login($returl, $expire, $cookie, 'facebook_id');
1079 1079
         return true;
1080 1080
     }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -56,21 +56,21 @@  discard block
 block discarded – undo
56 56
 
57 57
 class USER {
58 58
 
59
-    public $user_id = "0";         // So we have an ID for non-logged in users reporting comments etc.
60
-    public $firstname = "Guest";   // So we have something to print for non-logged in users.
59
+    public $user_id = "0"; // So we have an ID for non-logged in users reporting comments etc.
60
+    public $firstname = "Guest"; // So we have something to print for non-logged in users.
61 61
     public $lastname = "";
62
-    public $password = "";         // This will be a hashed version of a plaintext pw.
62
+    public $password = ""; // This will be a hashed version of a plaintext pw.
63 63
     public $email = "";
64 64
     public $postcode = "";
65 65
     public $url = "";
66
-    public $lastvisit = "";        // Last time the logged-in user loaded a page (GMT).
66
+    public $lastvisit = ""; // Last time the logged-in user loaded a page (GMT).
67 67
     public $registrationtime = ""; // When they registered (GMT).
68
-    public $registrationip = "";   // Where they registered from.
69
-    public $optin = "";            // boolean - Do they want emails from us?
70
-    public $deleted = "";          // User can't log in or have their info displayed.
71
-    public $confirmed = '';        // boolean - Has the user confirmed via email?
72
-    public $facebook_id = '';      // Facebook ID for users who login with FB
73
-    public $facebook_token = '';   // Facebook token for users who login with FB
68
+    public $registrationip = ""; // Where they registered from.
69
+    public $optin = ""; // boolean - Do they want emails from us?
70
+    public $deleted = ""; // User can't log in or have their info displayed.
71
+    public $confirmed = ''; // boolean - Has the user confirmed via email?
72
+    public $facebook_id = ''; // Facebook ID for users who login with FB
73
+    public $facebook_token = ''; // Facebook token for users who login with FB
74 74
     // Don't use the status to check access privileges - use the is_able_to() function.
75 75
     public $status = "Viewer";
76 76
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 
143 143
     }
144 144
 
145
-    public function add($details, $confirmation_required=true) {
145
+    public function add($details, $confirmation_required = true) {
146 146
         // Adds a new user's info into the db.
147 147
         // Then optionally (and usually) calls another function to
148 148
         // send them a confirmation email.
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             // This will be sent to them via email, so we can confirm they exist.
225 225
             // The token will be the first 16 characters of a hash.
226 226
 
227
-            $token = substr( password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16 );
227
+            $token = substr(password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16);
228 228
 
229 229
             // Full stops don't work well at the end of URLs in emails,
230 230
             // so replace them. We won't be doing anything clever with the hash
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
             $r = $this->db->query("UPDATE users
237 237
                             SET registrationtoken = :registrationtoken
238 238
                             WHERE   user_id = :user_id
239
-                            ", array (
239
+                            ", array(
240 240
                                 ':registrationtoken' => $this->registrationtoken,
241 241
                                 ':user_id' => $this->user_id
242 242
                             ));
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
     }
284 284
 
285 285
     public function add_facebook_id($facebook_id) {
286
-        $q = $this->db->query ("UPDATE users SET facebook_id = :facebook_id WHERE email = :email",
286
+        $q = $this->db->query("UPDATE users SET facebook_id = :facebook_id WHERE email = :email",
287 287
             array(
288 288
                 ':facebook_id' => $facebook_id,
289 289
                 ':email' => $this->email
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
             !isset($details['email']) ||
305 305
             $details['email'] == '' ||
306 306
             !isset($details['token']) ||
307
-            $details['token'] == '' ) {
307
+            $details['token'] == '') {
308 308
             return false;
309 309
         }
310 310
 
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
         $confirmurl = 'https://' . DOMAIN . '/E/' . $urltoken;
317 317
 
318 318
         // Arrays we need to send a templated email.
319
-        $data = array (
319
+        $data = array(
320 320
             'to'        => $details['email'],
321 321
             'template'  => 'email_confirmation'
322 322
         );
323 323
 
324
-        $merge = array (
324
+        $merge = array(
325 325
             'FIRSTNAME'     => $details['firstname'],
326 326
             'LASTNAME'      => $details['lastname'],
327 327
             'CONFIRMURL'    => $confirmurl
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
         }
362 362
 
363 363
         // Arrays we need to send a templated email.
364
-        $data = array (
364
+        $data = array(
365 365
             'to'        => $details['email'],
366 366
             'template'  => 'join_confirmation'
367 367
         );
368 368
 
369
-        $merge = array (
369
+        $merge = array(
370 370
             'FIRSTNAME'     => $details['firstname'],
371 371
             'LASTNAME'      => $details['lastname'],
372 372
             'CONFIRMURL'    => $confirmurl
@@ -428,23 +428,23 @@  discard block
 block discarded – undo
428 428
             $this->email = $email;
429 429
             for (;;) {
430 430
 
431
-                $pwd=null;
432
-                $o=null;
431
+                $pwd = null;
432
+                $o = null;
433 433
 
434 434
                 // Generates the password ....
435
-                for ($x=0; $x < 6;) {
436
-                    $y = rand(1,1000);
437
-                    if($y>350 && $y<601) $d=chr(rand(48,57));
438
-                    if($y<351) $d=chr(rand(65,90));
439
-                    if($y>600) $d=chr(rand(97,122));
440
-                    if ($d!=$o && !preg_match('#[O01lI]#', $d)) {
441
-                        $o=$d; $pwd.=$d; $x++;
435
+                for ($x = 0; $x < 6;) {
436
+                    $y = rand(1, 1000);
437
+                    if ($y > 350 && $y < 601) $d = chr(rand(48, 57));
438
+                    if ($y < 351) $d = chr(rand(65, 90));
439
+                    if ($y > 600) $d = chr(rand(97, 122));
440
+                    if ($d != $o && !preg_match('#[O01lI]#', $d)) {
441
+                        $o = $d; $pwd .= $d; $x++;
442 442
                     }
443 443
                 }
444 444
 
445 445
                 // If the PW fits your purpose (e.g. this regexpression) return it, else make a new one
446 446
                 // (You can change this regular-expression how you want ....)
447
-                if (preg_match("/^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+/",$pwd)) {
447
+                if (preg_match("/^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+/", $pwd)) {
448 448
                     break;
449 449
                 }
450 450
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 
463 463
         $passwordforDB = password_hash($pwd, PASSWORD_BCRYPT);
464 464
 
465
-        $q = $this->db->query ("UPDATE users SET password = :password WHERE email = :email",
465
+        $q = $this->db->query("UPDATE users SET password = :password WHERE email = :email",
466 466
             array(
467 467
                 ':password' => $passwordforDB,
468 468
                 ':email' => $email
@@ -490,14 +490,14 @@  discard block
 block discarded – undo
490 490
             return false;
491 491
         }
492 492
 
493
-        $data = array (
493
+        $data = array(
494 494
             'to'            => $this->email(),
495 495
             'template'      => 'new_password'
496 496
         );
497 497
 
498 498
         $URL = new \MySociety\TheyWorkForYou\Url("userlogin");
499 499
 
500
-        $merge = array (
500
+        $merge = array(
501 501
             'EMAIL'         => $this->email(),
502 502
             'LOGINURL'      => "https://" . DOMAIN . $URL->generate(),
503 503
             'PASSWORD'      => $this->password()
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
     public function facebook_id_exists($id, $return_id = false) {
553 553
         // Returns true if there's a user with this facebook id.
554 554
 
555
-        if ($id!= "") {
555
+        if ($id != "") {
556 556
             $q = $this->db->query("SELECT user_id FROM users WHERE facebook_id = :id", array(':id' => $id))->first();
557 557
             if ($q) {
558 558
                 if ($return_id) {
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
                 /* Everyone */              return true;
628 628
 
629 629
             default:
630
-                $PAGE->error_message ("You need to set permissions for '$action'!");
630
+                $PAGE->error_message("You need to set permissions for '$action'!");
631 631
 
632 632
                 return false;
633 633
 
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
         // Maybe there's a way of fetching these from the DB,
646 646
         // so we don't duplicate them here...?
647 647
 
648
-        $statuses = array ("Viewer", "User", "Moderator", "Administrator", "Superuser");
648
+        $statuses = array("Viewer", "User", "Moderator", "Administrator", "Superuser");
649 649
 
650 650
         return $statuses;
651 651
 
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
             return $details;
801 801
 
802 802
         } else {
803
-            $PAGE->error_message ("Sorry, we were unable to update user id '" . _htmlentities($details["user_id"]) . "'");
803
+            $PAGE->error_message("Sorry, we were unable to update user id '" . _htmlentities($details["user_id"]) . "'");
804 804
 
805 805
             return false;
806 806
         }
@@ -873,13 +873,13 @@  discard block
 block discarded – undo
873 873
 
874 874
                     if ($this->facebook_user) {
875 875
                       if (md5($this->facebook_token()) == $matches[2] && $this->deleted() == false) {
876
-                          twfy_debug ("THEUSER", "init SUCCESS: setting as logged in");
876
+                          twfy_debug("THEUSER", "init SUCCESS: setting as logged in");
877 877
                           $this->loggedin = true;
878
-                      } elseif (md5 ($this->facebook_token()) != $matches[2]) {
879
-                          twfy_debug ("THEUSER", "init FAILED: Facebook token doesn't match cookie");
878
+                      } elseif (md5($this->facebook_token()) != $matches[2]) {
879
+                          twfy_debug("THEUSER", "init FAILED: Facebook token doesn't match cookie");
880 880
                           $this->loggedin = false;
881 881
                       } else {
882
-                          twfy_debug ("THEUSER", "init FAILED: User is deleted");
882
+                          twfy_debug("THEUSER", "init FAILED: User is deleted");
883 883
                           $this->loggedin = false;
884 884
                       }
885 885
                     } else {
@@ -892,30 +892,30 @@  discard block
 block discarded – undo
892 892
                           // to need. Their preferences and saved things or something.
893 893
 
894 894
 
895
-                          twfy_debug ("THEUSER init SUCCEEDED", "setting as logged in");
895
+                          twfy_debug("THEUSER init SUCCEEDED", "setting as logged in");
896 896
                           $this->loggedin = true;
897 897
 
898
-                      } elseif (md5 ($this->password()) != $matches[2]) {
899
-                          twfy_debug ("THEUSER init FAILED", "Password doesn't match cookie");
898
+                      } elseif (md5($this->password()) != $matches[2]) {
899
+                          twfy_debug("THEUSER init FAILED", "Password doesn't match cookie");
900 900
                           $this->loggedin = false;
901 901
                       } else {
902
-                          twfy_debug ("THEUSER init FAILED", "User is deleted");
902
+                          twfy_debug("THEUSER init FAILED", "User is deleted");
903 903
                           $this->loggedin = false;
904 904
                       }
905 905
                     }
906 906
 
907 907
                 } else {
908
-                    twfy_debug ("THEUSER init FAILED", "didn't get 1 row from db");
908
+                    twfy_debug("THEUSER init FAILED", "didn't get 1 row from db");
909 909
                     $this->loggedin = false;
910 910
                 }
911 911
 
912 912
             } else {
913
-                twfy_debug ("THEUSER init FAILED", "cookie's user_id is not numeric");
913
+                twfy_debug("THEUSER init FAILED", "cookie's user_id is not numeric");
914 914
                 $this->loggedin = false;
915 915
             }
916 916
 
917 917
         } else {
918
-            twfy_debug ("THEUSER init FAILED", "cookie is not of the correct form");
918
+            twfy_debug("THEUSER init FAILED", "cookie is not of the correct form");
919 919
             $this->loggedin = false;
920 920
         }
921 921
 
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
             // Set last_visit to now.
942 942
             $date_now = gmdate("Y-m-d H:i:s");
943 943
             $this->db->query("UPDATE users SET lastvisit = :lastvisit WHERE user_id = :user_id",
944
-                [ ':lastvisit' => $date_now, ':user_id' => $this->user_id() ]);
944
+                [':lastvisit' => $date_now, ':user_id' => $this->user_id()]);
945 945
 
946 946
             $this->lastvisit = $date_now;
947 947
         }
@@ -997,55 +997,55 @@  discard block
 block discarded – undo
997 997
 
998 998
             } else {
999 999
                 // Failed.
1000
-                return array ("invalidemail" => $error_string);
1000
+                return array("invalidemail" => $error_string);
1001 1001
 
1002 1002
             }
1003 1003
 
1004 1004
         } else {
1005 1005
             // Failed.
1006
-            return array ("invalidemail" => $error_string);
1006
+            return array("invalidemail" => $error_string);
1007 1007
         }
1008 1008
 
1009 1009
     }
1010 1010
 
1011 1011
     public function has_postcode() {
1012 1012
         $has_postcode = false;
1013
-        if ( $this->isloggedin() && $this->postcode() != '' || $this->postcode_is_set() ) {
1013
+        if ($this->isloggedin() && $this->postcode() != '' || $this->postcode_is_set()) {
1014 1014
             $has_postcode = true;
1015 1015
         }
1016 1016
         return $has_postcode;
1017 1017
     }
1018 1018
 
1019 1019
 
1020
-    public function facebook_login($returl="", $expire, $accessToken) {
1020
+    public function facebook_login($returl = "", $expire, $accessToken) {
1021 1021
         global $PAGE;
1022 1022
 
1023 1023
         twfy_debug("THEUSER", "Faceook login, user_id " . $this->user_id);
1024 1024
         twfy_debug("THEUSER", "Faceook login, facebook_id " . $this->facebook_id);
1025 1025
         twfy_debug("THEUSER", "Faceook login, email" . $this->email);
1026 1026
         if ($this->facebook_id() == "") {
1027
-            $PAGE->error_message ("We don't have a facebook id for this user.", true);
1027
+            $PAGE->error_message("We don't have a facebook id for this user.", true);
1028 1028
 
1029 1029
             return;
1030 1030
         }
1031 1031
 
1032 1032
         twfy_debug("THEUSER", "Faceook login, facebook_token: " . $accessToken);
1033 1033
 
1034
-        $q = $this->db->query ("UPDATE users SET facebook_token = :token WHERE email = :email",
1034
+        $q = $this->db->query("UPDATE users SET facebook_token = :token WHERE email = :email",
1035 1035
             array(
1036 1036
                 ':token' => $accessToken,
1037 1037
                 ':email' => $this->email
1038 1038
             ));
1039 1039
 
1040 1040
         if (!$q->success()) {
1041
-            $PAGE->error_message ("There was a problem logging you in", true);
1041
+            $PAGE->error_message("There was a problem logging you in", true);
1042 1042
             twfy_debug("THEUSER", "Faceook login, failed to set accessToken");
1043 1043
 
1044 1044
             return false;
1045 1045
         }
1046 1046
 
1047 1047
         // facebook login users probably don't have a password
1048
-        $cookie = $this->user_id() . "." . md5 ($accessToken);
1048
+        $cookie = $this->user_id() . "." . md5($accessToken);
1049 1049
         twfy_debug("THEUSER", "Faceook login, cookie: " . $cookie);
1050 1050
 
1051 1051
         twfy_debug("USER", "logging in user from facebook " . $this->user_id);
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
         return true;
1056 1056
     }
1057 1057
 
1058
-    public function login($returl="", $expire) {
1058
+    public function login($returl = "", $expire) {
1059 1059
 
1060 1060
         // This is used to log the user in. Duh.
1061 1061
         // You should already have checked the user's email and password using
@@ -1077,21 +1077,21 @@  discard block
 block discarded – undo
1077 1077
 
1078 1078
         // Various checks about the user - if they fail, we exit.
1079 1079
         if ($this->user_id() == "" || $this->password == "") {
1080
-            $PAGE->error_message ("We don't have the user_id or password to make the cookie.", true);
1080
+            $PAGE->error_message("We don't have the user_id or password to make the cookie.", true);
1081 1081
 
1082 1082
             return;
1083 1083
         } elseif ($this->deleted) {
1084
-            $PAGE->error_message ("This user has been deleted.", true);
1084
+            $PAGE->error_message("This user has been deleted.", true);
1085 1085
 
1086 1086
             return;
1087 1087
         } elseif (!$this->confirmed) {
1088
-            $PAGE->error_message ("You have not yet confirmed your account by clicking the link in the confirmation email we sent to you. If you don't have the email, you can <a href='/user/login/?resend=" . $this->user_id() . "'>have it resent</a>. If it still doesn't arrive, get in touch.", true);
1088
+            $PAGE->error_message("You have not yet confirmed your account by clicking the link in the confirmation email we sent to you. If you don't have the email, you can <a href='/user/login/?resend=" . $this->user_id() . "'>have it resent</a>. If it still doesn't arrive, get in touch.", true);
1089 1089
 
1090 1090
             return;
1091 1091
         }
1092 1092
 
1093 1093
         // Reminder: $this->password is actually a hashed version of the plaintext pw.
1094
-        $cookie = $this->user_id() . "." . md5 ($this->password());
1094
+        $cookie = $this->user_id() . "." . md5($this->password());
1095 1095
 
1096 1096
         $this->_login($returl, $expire, $cookie);
1097 1097
     }
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
         $cookie_expires = 0;
1108 1108
         if ($expire == 'never') {
1109 1109
             twfy_debug("THEUSER", "cookie never expires");
1110
-            $cookie_expires = time()+86400*365*20;
1110
+            $cookie_expires = time() + 86400 * 365 * 20;
1111 1111
         } elseif (is_int($expire) && $expire > time()) {
1112 1112
             twfy_debug("THEUSER", "cookie expires at " . $expire);
1113 1113
             $cookie_expires = $expire;
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
         }
1146 1146
     }
1147 1147
 
1148
-    public function confirm_email($token, $redirect=true) {
1148
+    public function confirm_email($token, $redirect = true) {
1149 1149
         $arg = '';
1150 1150
         if (strstr($token, '::')) $arg = '::';
1151 1151
         if (strstr($token, '-')) $arg = '-';
@@ -1158,24 +1158,24 @@  discard block
 block discarded – undo
1158 1158
             FROM    tokens
1159 1159
             WHERE   token = :token
1160 1160
             AND   type = 'E'
1161
-        ", array (':token' => $registrationtoken))->first();
1161
+        ", array(':token' => $registrationtoken))->first();
1162 1162
 
1163 1163
         if ($q) {
1164 1164
             $expires = $q['expires'];
1165 1165
             $expire_time = strtotime($expires);
1166
-            if ( $expire_time < time() ) {
1166
+            if ($expire_time < time()) {
1167 1167
                 global $PAGE;
1168 1168
                 if ($PAGE && $redirect) {
1169
-                    $PAGE->error_message ("Sorry, that token seems to have expired");
1169
+                    $PAGE->error_message("Sorry, that token seems to have expired");
1170 1170
                 }
1171 1171
 
1172 1172
                 return false;
1173 1173
             }
1174 1174
 
1175
-            list( $user_id, $email ) = explode('::', $q['data']);
1175
+            list($user_id, $email) = explode('::', $q['data']);
1176 1176
 
1177 1177
             // if we are logged in as someone else don't change the email
1178
-            if ( $this->user_id() != 0 && $this->user_id() != $user_id ) {
1178
+            if ($this->user_id() != 0 && $this->user_id() != $user_id) {
1179 1179
                 return false;
1180 1180
             }
1181 1181
 
@@ -1317,7 +1317,7 @@  discard block
 block discarded – undo
1317 1317
 
1318 1318
             twfy_debug("THEUSER", "User with ID found to confirm: " . $this->user_id());
1319 1319
             // We'll need these to be set before logging the user in.
1320
-            $this->email    = $q['email'];
1320
+            $this->email = $q['email'];
1321 1321
 
1322 1322
             // Set that they're confirmed in the DB.
1323 1323
             $r = $this->db->query("UPDATE users
@@ -1364,14 +1364,14 @@  discard block
 block discarded – undo
1364 1364
 
1365 1365
         $this->postcode = $pc;
1366 1366
         if (!headers_sent()) // if in debug mode
1367
-            setcookie (POSTCODE_COOKIE, $pc, time()+7*86400, "/", COOKIEDOMAIN);
1367
+            setcookie(POSTCODE_COOKIE, $pc, time() + 7 * 86400, "/", COOKIEDOMAIN);
1368 1368
 
1369 1369
         twfy_debug('USER', "Set the cookie named '" . POSTCODE_COOKIE . " to '$pc' for " . COOKIEDOMAIN . " domain");
1370 1370
     }
1371 1371
 
1372 1372
     public function unset_postcode_cookie() {
1373 1373
         if (!headers_sent()) // if in debug mode
1374
-            setcookie (POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN);
1374
+            setcookie(POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN);
1375 1375
     }
1376 1376
 
1377 1377
     // mostly here for updating from facebook where we do not need
@@ -1384,8 +1384,8 @@  discard block
 block discarded – undo
1384 1384
 
1385 1385
             // this is checked elsewhere but just in case we check here and
1386 1386
             // bail out to be on the safe side
1387
-            if ( isset($details['email'] ) ) {
1388
-                if ( $details['email'] != $this->email() && $this->email_exists( $details['email'] ) ) {
1387
+            if (isset($details['email'])) {
1388
+                if ($details['email'] != $this->email() && $this->email_exists($details['email'])) {
1389 1389
                     return false;
1390 1390
                 }
1391 1391
             }
@@ -1433,8 +1433,8 @@  discard block
 block discarded – undo
1433 1433
             // this is checked elsewhere but just in case we check here and
1434 1434
             // bail out to be on the safe side
1435 1435
             $email = '';
1436
-            if ( isset($details['email'] ) ) {
1437
-                if ( $details['email'] != $this->email() && $this->email_exists( $details['email'] ) ) {
1436
+            if (isset($details['email'])) {
1437
+                if ($details['email'] != $this->email() && $this->email_exists($details['email'])) {
1438 1438
                     return false;
1439 1439
                 }
1440 1440
                 $email = $details['email'];
@@ -1461,7 +1461,7 @@  discard block
 block discarded – undo
1461 1461
                 }
1462 1462
 
1463 1463
                 if ($email && $email != $this->email) {
1464
-                    $token = substr( password_hash($email . microtime(), PASSWORD_BCRYPT), 29, 16 );
1464
+                    $token = substr(password_hash($email . microtime(), PASSWORD_BCRYPT), 29, 16);
1465 1465
                     $data = $this->user_id() . '::' . $email;
1466 1466
                     $r = $this->db->query("INSERT INTO tokens
1467 1467
                         ( expires, token, type, data )
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
                     ));
1479 1479
 
1480 1480
                     // send confirmation email here
1481
-                    if ( $r->success() ) {
1481
+                    if ($r->success()) {
1482 1482
                         $newdetails['email'] = $email;
1483 1483
                         $newdetails['token'] = $token;
1484 1484
                         if ($confirm_email) {
Please login to merge, or discard this patch.
www/docs/user/login/index.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,14 +19,14 @@  discard block
 block discarded – undo
19 19
 if (get_http_var("submitted") == "true") {
20 20
     // Form has been submitted, so check input.
21 21
 
22
-    $email 		= get_http_var("email");
22
+    $email = get_http_var("email");
23 23
     $password 	= get_http_var("password");
24 24
     $remember 	= get_http_var("remember");
25 25
 
26 26
     // The user may have tried to do something that requires being logged in.
27 27
     // In which case we should arrive here with that page's URL in 'ret'.
28 28
     // We can then send the user there after log in.
29
-    $returnurl 	= get_http_var("ret");
29
+    $returnurl = get_http_var("ret");
30 30
 
31 31
     $errors = array();
32 32
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
             if ($remember == "true") {
54 54
                 $expire = "never";
55 55
             } else {
56
-                $expire ="session";
56
+                $expire = "session";
57 57
             }
58 58
 
59 59
             // $returnurl is the url of where we'll send the user after login.
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 }
97 97
 
98 98
 
99
-function display_page( $errors=array() ) {
99
+function display_page($errors = array()) {
100 100
     global $PAGE, $this_page, $THEUSER;
101 101
 
102 102
     $PAGE->page_start();
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     <?php
128 128
 
129 129
         $PAGE->stripe_end(array(
130
-            array (
130
+            array(
131 131
                 'type' => 'include',
132 132
                 'content' => 'userlogin'
133 133
             )
Please login to merge, or discard this patch.
tests/TWFY_Database_TestCase.php 1 patch
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 
26 26
     public function tearDown()
27 27
     {
28
-        $this->db = NULL;
28
+        $this->db = null;
29 29
 
30 30
         parent::tearDown();
31 31
     }
Please login to merge, or discard this patch.
tests/HousesTest.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     /**
10 10
      * Test that the Royal edge-case house is correctly defined.
11 11
      */
12
-	public function testRoyalHouseDefined()
12
+    public function testRoyalHouseDefined()
13 13
     {
14 14
         $this->assertEquals(0, HOUSE_TYPE_ROYAL);
15 15
     }
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * Test that the House of Commons is correctly defined.
19 19
      */
20
-	public function testCommonsHouseDefined()
20
+    public function testCommonsHouseDefined()
21 21
     {
22 22
         $this->assertEquals(1, HOUSE_TYPE_COMMONS);
23 23
     }
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     /**
26 26
      * Test that the House of Lords is correctly defined.
27 27
      */
28
-	public function testLordsHouseDefined()
28
+    public function testLordsHouseDefined()
29 29
     {
30 30
         $this->assertEquals(2, HOUSE_TYPE_LORDS);
31 31
     }
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     /**
34 34
      * Test that the Northern Ireland Assembly is correctly defined.
35 35
      */
36
-	public function testNIHouseDefined()
36
+    public function testNIHouseDefined()
37 37
     {
38 38
         $this->assertEquals(3, HOUSE_TYPE_NI);
39 39
     }
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     /**
42 42
      * Test that the Scottish Parliament is correctly defined.
43 43
      */
44
-	public function testScotlandHouseDefined()
44
+    public function testScotlandHouseDefined()
45 45
     {
46 46
         $this->assertEquals(4, HOUSE_TYPE_SCOTLAND);
47 47
     }
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     /**
50 50
      * Test that the Assembly for Wales is correctly defined.
51 51
      */
52
-	public function testWalesHouseDefined()
52
+    public function testWalesHouseDefined()
53 53
     {
54 54
         $this->assertEquals(5, HOUSE_TYPE_WALES);
55 55
     }
Please login to merge, or discard this patch.