@@ -445,9 +445,15 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -56,21 +56,21 @@ discard block |
||
| 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 = ""; // Int containing multiple binary opt-ins. (See top of User.php) |
|
| 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 = ""; // Int containing multiple binary opt-ins. (See top of User.php) |
|
| 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 |
||
| 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. |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | // This will be sent to them via email, so we can confirm they exist. |
| 223 | 223 | // The token will be the first 16 characters of a hash. |
| 224 | 224 | |
| 225 | - $token = substr( password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16 ); |
|
| 225 | + $token = substr(password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16); |
|
| 226 | 226 | |
| 227 | 227 | // Full stops don't work well at the end of URLs in emails, so |
| 228 | 228 | // replace them. And double slash would be treated as single and |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $r = $this->db->query("UPDATE users |
| 236 | 236 | SET registrationtoken = :registrationtoken |
| 237 | 237 | WHERE user_id = :user_id |
| 238 | - ", array ( |
|
| 238 | + ", array( |
|
| 239 | 239 | ':registrationtoken' => $this->registrationtoken, |
| 240 | 240 | ':user_id' => $this->user_id |
| 241 | 241 | )); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | public function add_facebook_id($facebook_id) { |
| 285 | - $q = $this->db->query ("UPDATE users SET facebook_id = :facebook_id WHERE email = :email", |
|
| 285 | + $q = $this->db->query("UPDATE users SET facebook_id = :facebook_id WHERE email = :email", |
|
| 286 | 286 | array( |
| 287 | 287 | ':facebook_id' => $facebook_id, |
| 288 | 288 | ':email' => $this->email |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | !isset($details['email']) || |
| 304 | 304 | $details['email'] == '' || |
| 305 | 305 | !isset($details['token']) || |
| 306 | - $details['token'] == '' ) { |
|
| 306 | + $details['token'] == '') { |
|
| 307 | 307 | return false; |
| 308 | 308 | } |
| 309 | 309 | |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | $confirmurl = 'https://' . DOMAIN . '/E/' . $urltoken; |
| 316 | 316 | |
| 317 | 317 | // Arrays we need to send a templated email. |
| 318 | - $data = array ( |
|
| 318 | + $data = array( |
|
| 319 | 319 | 'to' => $details['email'], |
| 320 | 320 | 'template' => 'email_confirmation' |
| 321 | 321 | ); |
| 322 | 322 | |
| 323 | - $merge = array ( |
|
| 323 | + $merge = array( |
|
| 324 | 324 | 'CONFIRMURL' => $confirmurl |
| 325 | 325 | ); |
| 326 | 326 | |
@@ -358,12 +358,12 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | // Arrays we need to send a templated email. |
| 361 | - $data = array ( |
|
| 361 | + $data = array( |
|
| 362 | 362 | 'to' => $details['email'], |
| 363 | 363 | 'template' => 'join_confirmation' |
| 364 | 364 | ); |
| 365 | 365 | |
| 366 | - $merge = array ( |
|
| 366 | + $merge = array( |
|
| 367 | 367 | 'CONFIRMURL' => $confirmurl |
| 368 | 368 | ); |
| 369 | 369 | |
@@ -423,23 +423,23 @@ discard block |
||
| 423 | 423 | $this->email = $email; |
| 424 | 424 | for (;;) { |
| 425 | 425 | |
| 426 | - $pwd=null; |
|
| 427 | - $o=null; |
|
| 426 | + $pwd = null; |
|
| 427 | + $o = null; |
|
| 428 | 428 | |
| 429 | 429 | // Generates the password .... |
| 430 | - for ($x=0; $x < 6;) { |
|
| 431 | - $y = rand(1,1000); |
|
| 432 | - if($y>350 && $y<601) $d=chr(rand(48,57)); |
|
| 433 | - if($y<351) $d=chr(rand(65,90)); |
|
| 434 | - if($y>600) $d=chr(rand(97,122)); |
|
| 435 | - if ($d!=$o && !preg_match('#[O01lI]#', $d)) { |
|
| 436 | - $o=$d; $pwd.=$d; $x++; |
|
| 430 | + for ($x = 0; $x < 6;) { |
|
| 431 | + $y = rand(1, 1000); |
|
| 432 | + if ($y > 350 && $y < 601) $d = chr(rand(48, 57)); |
|
| 433 | + if ($y < 351) $d = chr(rand(65, 90)); |
|
| 434 | + if ($y > 600) $d = chr(rand(97, 122)); |
|
| 435 | + if ($d != $o && !preg_match('#[O01lI]#', $d)) { |
|
| 436 | + $o = $d; $pwd .= $d; $x++; |
|
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | // If the PW fits your purpose (e.g. this regexpression) return it, else make a new one |
| 441 | 441 | // (You can change this regular-expression how you want ....) |
| 442 | - if (preg_match("/^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+/",$pwd)) { |
|
| 442 | + if (preg_match("/^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+/", $pwd)) { |
|
| 443 | 443 | break; |
| 444 | 444 | } |
| 445 | 445 | |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | $passwordforDB = password_hash($pwd, PASSWORD_BCRYPT); |
| 459 | 459 | |
| 460 | - $q = $this->db->query ("UPDATE users SET password = :password WHERE email = :email", |
|
| 460 | + $q = $this->db->query("UPDATE users SET password = :password WHERE email = :email", |
|
| 461 | 461 | array( |
| 462 | 462 | ':password' => $passwordforDB, |
| 463 | 463 | ':email' => $email |
@@ -485,14 +485,14 @@ discard block |
||
| 485 | 485 | return false; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - $data = array ( |
|
| 488 | + $data = array( |
|
| 489 | 489 | 'to' => $this->email(), |
| 490 | 490 | 'template' => 'new_password' |
| 491 | 491 | ); |
| 492 | 492 | |
| 493 | 493 | $URL = new \MySociety\TheyWorkForYou\Url("userlogin"); |
| 494 | 494 | |
| 495 | - $merge = array ( |
|
| 495 | + $merge = array( |
|
| 496 | 496 | 'EMAIL' => $this->email(), |
| 497 | 497 | 'LOGINURL' => "https://" . DOMAIN . $URL->generate(), |
| 498 | 498 | 'PASSWORD' => $this->password() |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | public function facebook_id_exists($id, $return_id = false) { |
| 548 | 548 | // Returns true if there's a user with this facebook id. |
| 549 | 549 | |
| 550 | - if ($id!= "") { |
|
| 550 | + if ($id != "") { |
|
| 551 | 551 | $q = $this->db->query("SELECT user_id FROM users WHERE facebook_id = :id", array(':id' => $id))->first(); |
| 552 | 552 | if ($q) { |
| 553 | 553 | if ($return_id) { |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | /* Everyone */ return true; |
| 623 | 623 | |
| 624 | 624 | default: |
| 625 | - $PAGE->error_message ("You need to set permissions for '$action'!"); |
|
| 625 | + $PAGE->error_message("You need to set permissions for '$action'!"); |
|
| 626 | 626 | |
| 627 | 627 | return false; |
| 628 | 628 | |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | // Maybe there's a way of fetching these from the DB, |
| 641 | 641 | // so we don't duplicate them here...? |
| 642 | 642 | |
| 643 | - $statuses = array ("Viewer", "User", "Moderator", "Administrator", "Superuser"); |
|
| 643 | + $statuses = array("Viewer", "User", "Moderator", "Administrator", "Superuser"); |
|
| 644 | 644 | |
| 645 | 645 | return $statuses; |
| 646 | 646 | |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | return $details; |
| 793 | 793 | |
| 794 | 794 | } else { |
| 795 | - $PAGE->error_message ("Sorry, we were unable to update user id '" . _htmlentities($details["user_id"]) . "'"); |
|
| 795 | + $PAGE->error_message("Sorry, we were unable to update user id '" . _htmlentities($details["user_id"]) . "'"); |
|
| 796 | 796 | |
| 797 | 797 | return false; |
| 798 | 798 | } |
@@ -865,13 +865,13 @@ discard block |
||
| 865 | 865 | |
| 866 | 866 | if ($this->facebook_user) { |
| 867 | 867 | if (md5($this->facebook_token()) == $matches[2] && $this->deleted() == false) { |
| 868 | - twfy_debug ("THEUSER", "init SUCCESS: setting as logged in"); |
|
| 868 | + twfy_debug("THEUSER", "init SUCCESS: setting as logged in"); |
|
| 869 | 869 | $this->loggedin = true; |
| 870 | - } elseif (md5 ($this->facebook_token()) != $matches[2]) { |
|
| 871 | - twfy_debug ("THEUSER", "init FAILED: Facebook token doesn't match cookie"); |
|
| 870 | + } elseif (md5($this->facebook_token()) != $matches[2]) { |
|
| 871 | + twfy_debug("THEUSER", "init FAILED: Facebook token doesn't match cookie"); |
|
| 872 | 872 | $this->loggedin = false; |
| 873 | 873 | } else { |
| 874 | - twfy_debug ("THEUSER", "init FAILED: User is deleted"); |
|
| 874 | + twfy_debug("THEUSER", "init FAILED: User is deleted"); |
|
| 875 | 875 | $this->loggedin = false; |
| 876 | 876 | } |
| 877 | 877 | } else { |
@@ -884,30 +884,30 @@ discard block |
||
| 884 | 884 | // to need. Their preferences and saved things or something. |
| 885 | 885 | |
| 886 | 886 | |
| 887 | - twfy_debug ("THEUSER init SUCCEEDED", "setting as logged in"); |
|
| 887 | + twfy_debug("THEUSER init SUCCEEDED", "setting as logged in"); |
|
| 888 | 888 | $this->loggedin = true; |
| 889 | 889 | |
| 890 | - } elseif (md5 ($this->password()) != $matches[2]) { |
|
| 891 | - twfy_debug ("THEUSER init FAILED", "Password doesn't match cookie"); |
|
| 890 | + } elseif (md5($this->password()) != $matches[2]) { |
|
| 891 | + twfy_debug("THEUSER init FAILED", "Password doesn't match cookie"); |
|
| 892 | 892 | $this->loggedin = false; |
| 893 | 893 | } else { |
| 894 | - twfy_debug ("THEUSER init FAILED", "User is deleted"); |
|
| 894 | + twfy_debug("THEUSER init FAILED", "User is deleted"); |
|
| 895 | 895 | $this->loggedin = false; |
| 896 | 896 | } |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | } else { |
| 900 | - twfy_debug ("THEUSER init FAILED", "didn't get 1 row from db"); |
|
| 900 | + twfy_debug("THEUSER init FAILED", "didn't get 1 row from db"); |
|
| 901 | 901 | $this->loggedin = false; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | } else { |
| 905 | - twfy_debug ("THEUSER init FAILED", "cookie's user_id is not numeric"); |
|
| 905 | + twfy_debug("THEUSER init FAILED", "cookie's user_id is not numeric"); |
|
| 906 | 906 | $this->loggedin = false; |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | } else { |
| 910 | - twfy_debug ("THEUSER init FAILED", "cookie is not of the correct form"); |
|
| 910 | + twfy_debug("THEUSER init FAILED", "cookie is not of the correct form"); |
|
| 911 | 911 | $this->loggedin = false; |
| 912 | 912 | } |
| 913 | 913 | |
@@ -933,7 +933,7 @@ discard block |
||
| 933 | 933 | // Set last_visit to now. |
| 934 | 934 | $date_now = gmdate("Y-m-d H:i:s"); |
| 935 | 935 | $this->db->query("UPDATE users SET lastvisit = :lastvisit WHERE user_id = :user_id", |
| 936 | - [ ':lastvisit' => $date_now, ':user_id' => $this->user_id() ]); |
|
| 936 | + [':lastvisit' => $date_now, ':user_id' => $this->user_id()]); |
|
| 937 | 937 | |
| 938 | 938 | $this->lastvisit = $date_now; |
| 939 | 939 | } |
@@ -989,20 +989,20 @@ discard block |
||
| 989 | 989 | |
| 990 | 990 | } else { |
| 991 | 991 | // Failed. |
| 992 | - return array ("invalidemail" => $error_string); |
|
| 992 | + return array("invalidemail" => $error_string); |
|
| 993 | 993 | |
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | } else { |
| 997 | 997 | // Failed. |
| 998 | - return array ("invalidemail" => $error_string); |
|
| 998 | + return array("invalidemail" => $error_string); |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | public function has_postcode() { |
| 1004 | 1004 | $has_postcode = false; |
| 1005 | - if ( $this->isloggedin() && $this->postcode() != '' || $this->postcode_is_set() ) { |
|
| 1005 | + if ($this->isloggedin() && $this->postcode() != '' || $this->postcode_is_set()) { |
|
| 1006 | 1006 | $has_postcode = true; |
| 1007 | 1007 | } |
| 1008 | 1008 | return $has_postcode; |
@@ -1016,28 +1016,28 @@ discard block |
||
| 1016 | 1016 | twfy_debug("THEUSER", "Faceook login, facebook_id " . $this->facebook_id); |
| 1017 | 1017 | twfy_debug("THEUSER", "Faceook login, email" . $this->email); |
| 1018 | 1018 | if ($this->facebook_id() == "") { |
| 1019 | - $PAGE->error_message ("We don't have a facebook id for this user.", true); |
|
| 1019 | + $PAGE->error_message("We don't have a facebook id for this user.", true); |
|
| 1020 | 1020 | |
| 1021 | 1021 | return; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | twfy_debug("THEUSER", "Faceook login, facebook_token: " . $accessToken); |
| 1025 | 1025 | |
| 1026 | - $q = $this->db->query ("UPDATE users SET facebook_token = :token WHERE email = :email", |
|
| 1026 | + $q = $this->db->query("UPDATE users SET facebook_token = :token WHERE email = :email", |
|
| 1027 | 1027 | array( |
| 1028 | 1028 | ':token' => $accessToken, |
| 1029 | 1029 | ':email' => $this->email |
| 1030 | 1030 | )); |
| 1031 | 1031 | |
| 1032 | 1032 | if (!$q->success()) { |
| 1033 | - $PAGE->error_message ("There was a problem logging you in", true); |
|
| 1033 | + $PAGE->error_message("There was a problem logging you in", true); |
|
| 1034 | 1034 | twfy_debug("THEUSER", "Faceook login, failed to set accessToken"); |
| 1035 | 1035 | |
| 1036 | 1036 | return false; |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | // facebook login users probably don't have a password |
| 1040 | - $cookie = $this->user_id() . "." . md5 ($accessToken); |
|
| 1040 | + $cookie = $this->user_id() . "." . md5($accessToken); |
|
| 1041 | 1041 | twfy_debug("THEUSER", "Faceook login, cookie: " . $cookie); |
| 1042 | 1042 | |
| 1043 | 1043 | twfy_debug("USER", "logging in user from facebook " . $this->user_id); |
@@ -1069,21 +1069,21 @@ discard block |
||
| 1069 | 1069 | |
| 1070 | 1070 | // Various checks about the user - if they fail, we exit. |
| 1071 | 1071 | if ($this->user_id() == "" || $this->password == "") { |
| 1072 | - $PAGE->error_message ("We don't have the user_id or password to make the cookie.", true); |
|
| 1072 | + $PAGE->error_message("We don't have the user_id or password to make the cookie.", true); |
|
| 1073 | 1073 | |
| 1074 | 1074 | return; |
| 1075 | 1075 | } elseif ($this->deleted) { |
| 1076 | - $PAGE->error_message ("This user has been deleted.", true); |
|
| 1076 | + $PAGE->error_message("This user has been deleted.", true); |
|
| 1077 | 1077 | |
| 1078 | 1078 | return; |
| 1079 | 1079 | } elseif (!$this->confirmed) { |
| 1080 | - $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); |
|
| 1080 | + $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); |
|
| 1081 | 1081 | |
| 1082 | 1082 | return; |
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | // Reminder: $this->password is actually a hashed version of the plaintext pw. |
| 1086 | - $cookie = $this->user_id() . "." . md5 ($this->password()); |
|
| 1086 | + $cookie = $this->user_id() . "." . md5($this->password()); |
|
| 1087 | 1087 | |
| 1088 | 1088 | $this->_login($returl, $expire, $cookie); |
| 1089 | 1089 | } |
@@ -1099,7 +1099,7 @@ discard block |
||
| 1099 | 1099 | $cookie_expires = 0; |
| 1100 | 1100 | if ($expire == 'never') { |
| 1101 | 1101 | twfy_debug("THEUSER", "cookie never expires"); |
| 1102 | - $cookie_expires = time()+86400*365*20; |
|
| 1102 | + $cookie_expires = time() + 86400 * 365 * 20; |
|
| 1103 | 1103 | } elseif (is_int($expire) && $expire > time()) { |
| 1104 | 1104 | twfy_debug("THEUSER", "cookie expires at " . $expire); |
| 1105 | 1105 | $cookie_expires = $expire; |
@@ -1137,7 +1137,7 @@ discard block |
||
| 1137 | 1137 | } |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | - public function confirm_email($token, $redirect=true) { |
|
| 1140 | + public function confirm_email($token, $redirect = true) { |
|
| 1141 | 1141 | $arg = ''; |
| 1142 | 1142 | if (strstr($token, '::')) $arg = '::'; |
| 1143 | 1143 | if (strstr($token, '-')) $arg = '-'; |
@@ -1150,24 +1150,24 @@ discard block |
||
| 1150 | 1150 | FROM tokens |
| 1151 | 1151 | WHERE token = :token |
| 1152 | 1152 | AND type = 'E' |
| 1153 | - ", array (':token' => $registrationtoken))->first(); |
|
| 1153 | + ", array(':token' => $registrationtoken))->first(); |
|
| 1154 | 1154 | |
| 1155 | 1155 | if ($q) { |
| 1156 | 1156 | $expires = $q['expires']; |
| 1157 | 1157 | $expire_time = strtotime($expires); |
| 1158 | - if ( $expire_time < time() ) { |
|
| 1158 | + if ($expire_time < time()) { |
|
| 1159 | 1159 | global $PAGE; |
| 1160 | 1160 | if ($PAGE && $redirect) { |
| 1161 | - $PAGE->error_message ("Sorry, that token seems to have expired"); |
|
| 1161 | + $PAGE->error_message("Sorry, that token seems to have expired"); |
|
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | return false; |
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | - list( $user_id, $email ) = explode('::', $q['data']); |
|
| 1167 | + list($user_id, $email) = explode('::', $q['data']); |
|
| 1168 | 1168 | |
| 1169 | 1169 | // if we are logged in as someone else don't change the email |
| 1170 | - if ( $this->user_id() != 0 && $this->user_id() != $user_id ) { |
|
| 1170 | + if ($this->user_id() != 0 && $this->user_id() != $user_id) { |
|
| 1171 | 1171 | return false; |
| 1172 | 1172 | } |
| 1173 | 1173 | |
@@ -1316,7 +1316,7 @@ discard block |
||
| 1316 | 1316 | |
| 1317 | 1317 | twfy_debug("THEUSER", "User with ID found to confirm: " . $this->user_id()); |
| 1318 | 1318 | // We'll need these to be set before logging the user in. |
| 1319 | - $this->email = $q['email']; |
|
| 1319 | + $this->email = $q['email']; |
|
| 1320 | 1320 | |
| 1321 | 1321 | // Set that they're confirmed in the DB. |
| 1322 | 1322 | $r = $this->db->query("UPDATE users |
@@ -1363,14 +1363,14 @@ discard block |
||
| 1363 | 1363 | |
| 1364 | 1364 | $this->postcode = $pc; |
| 1365 | 1365 | if (!headers_sent()) // if in debug mode |
| 1366 | - setcookie (POSTCODE_COOKIE, $pc, time()+7*86400, "/", COOKIEDOMAIN); |
|
| 1366 | + setcookie(POSTCODE_COOKIE, $pc, time() + 7 * 86400, "/", COOKIEDOMAIN); |
|
| 1367 | 1367 | |
| 1368 | 1368 | twfy_debug('USER', "Set the cookie named '" . POSTCODE_COOKIE . " to '$pc' for " . COOKIEDOMAIN . " domain"); |
| 1369 | 1369 | } |
| 1370 | 1370 | |
| 1371 | 1371 | public function unset_postcode_cookie() { |
| 1372 | 1372 | if (!headers_sent()) // if in debug mode |
| 1373 | - setcookie (POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN); |
|
| 1373 | + setcookie(POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN); |
|
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | 1376 | // mostly here for updating from facebook where we do not need |
@@ -1383,8 +1383,8 @@ discard block |
||
| 1383 | 1383 | |
| 1384 | 1384 | // this is checked elsewhere but just in case we check here and |
| 1385 | 1385 | // bail out to be on the safe side |
| 1386 | - if ( isset($details['email'] ) ) { |
|
| 1387 | - if ( $details['email'] != $this->email() && $this->email_exists( $details['email'] ) ) { |
|
| 1386 | + if (isset($details['email'])) { |
|
| 1387 | + if ($details['email'] != $this->email() && $this->email_exists($details['email'])) { |
|
| 1388 | 1388 | return false; |
| 1389 | 1389 | } |
| 1390 | 1390 | } |
@@ -1432,8 +1432,8 @@ discard block |
||
| 1432 | 1432 | // this is checked elsewhere but just in case we check here and |
| 1433 | 1433 | // bail out to be on the safe side |
| 1434 | 1434 | $email = ''; |
| 1435 | - if ( isset($details['email'] ) ) { |
|
| 1436 | - if ( $details['email'] != $this->email() && $this->email_exists( $details['email'] ) ) { |
|
| 1435 | + if (isset($details['email'])) { |
|
| 1436 | + if ($details['email'] != $this->email() && $this->email_exists($details['email'])) { |
|
| 1437 | 1437 | return false; |
| 1438 | 1438 | } |
| 1439 | 1439 | $email = $details['email']; |
@@ -1459,7 +1459,7 @@ discard block |
||
| 1459 | 1459 | } |
| 1460 | 1460 | |
| 1461 | 1461 | if ($email && $email != $this->email) { |
| 1462 | - $token = substr( password_hash($email . microtime(), PASSWORD_BCRYPT), 29, 16 ); |
|
| 1462 | + $token = substr(password_hash($email . microtime(), PASSWORD_BCRYPT), 29, 16); |
|
| 1463 | 1463 | $data = $this->user_id() . '::' . $email; |
| 1464 | 1464 | $r = $this->db->query("INSERT INTO tokens |
| 1465 | 1465 | ( expires, token, type, data ) |
@@ -1476,7 +1476,7 @@ discard block |
||
| 1476 | 1476 | )); |
| 1477 | 1477 | |
| 1478 | 1478 | // send confirmation email here |
| 1479 | - if ( $r->success() ) { |
|
| 1479 | + if ($r->success()) { |
|
| 1480 | 1480 | $newdetails['email'] = $email; |
| 1481 | 1481 | $newdetails['token'] = $token; |
| 1482 | 1482 | if ($confirm_email) { |
@@ -27,11 +27,11 @@ |
||
| 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 | } |
@@ -19,14 +19,14 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | ) |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $this->searchstring = $argparser->construct_search_string(); |
| 20 | 20 | $this->searchkeyword = $argparser->searchkeyword; |
| 21 | 21 | |
| 22 | - if ( !$this->searchstring ) { |
|
| 22 | + if (!$this->searchstring) { |
|
| 23 | 23 | $data = $this->get_form_params($data); |
| 24 | 24 | $data['searchstring'] = ''; |
| 25 | 25 | $data['template'] = 'search/results'; |
@@ -28,14 +28,14 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | $this->searchstring = filter_user_input($this->searchstring, 'strict'); |
| 30 | 30 | $warnings = $this->validate_search_string(); |
| 31 | - if ( $warnings ) { |
|
| 31 | + if ($warnings) { |
|
| 32 | 32 | $data['warnings'] = $warnings; |
| 33 | 33 | $data['template'] = 'search/results'; |
| 34 | 34 | $data['searchstring'] = $this->searchstring; |
| 35 | 35 | $data = $this->get_form_params($data); |
| 36 | 36 | return $data; |
| 37 | 37 | } else { |
| 38 | - if (get_http_var('o')=='p') { |
|
| 38 | + if (get_http_var('o') == 'p') { |
|
| 39 | 39 | $search = new Search\ByUsage(); |
| 40 | 40 | $data = $search->search($this->searchstring); |
| 41 | 41 | $data['template'] = 'search/by-person'; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $data['person_name'] = $MEMBER->full_name(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ( isset($data['info']['spelling_correction']) ) { |
|
| 55 | + if (isset($data['info']['spelling_correction'])) { |
|
| 56 | 56 | $data['info']['spelling_correction_display'] = $this->prettifySearchString($data['info']['spelling_correction']); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -144,15 +144,15 @@ discard block |
||
| 144 | 144 | $data['search_keyword'] = $this->searchkeyword; |
| 145 | 145 | |
| 146 | 146 | $is_adv = false; |
| 147 | - foreach ( array('to', 'from', 'person', 'section', 'column', 'phrase', 'exclude' ) as $var ) { |
|
| 147 | + foreach (array('to', 'from', 'person', 'section', 'column', 'phrase', 'exclude') as $var) { |
|
| 148 | 148 | $key = "search_$var"; |
| 149 | - $data[$key] = get_http_var( $var ); |
|
| 150 | - if ( $data[$key] ) { |
|
| 149 | + $data[$key] = get_http_var($var); |
|
| 150 | + if ($data[$key]) { |
|
| 151 | 151 | $is_adv = true; |
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if ( isset($data['search_section']) ) { |
|
| 155 | + if (isset($data['search_section'])) { |
|
| 156 | 156 | $data['search_section_pretty'] = $this->prettify_search_section($data['search_section']); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -162,16 +162,16 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | private function set_wtt_options($data) { |
| 164 | 164 | $data['wtt'] = ''; |
| 165 | - if ( $wtt = get_http_var('wtt') ) { |
|
| 165 | + if ($wtt = get_http_var('wtt')) { |
|
| 166 | 166 | $data['wtt'] = $wtt; |
| 167 | - if ( $wtt == 2 && $pid = get_http_var('pid') ) { |
|
| 167 | + if ($wtt == 2 && $pid = get_http_var('pid')) { |
|
| 168 | 168 | $data['pid'] = null; |
| 169 | 169 | try { |
| 170 | 170 | $lord = new Member(array('person_id' => $pid, 'house' => 2)); |
| 171 | - } catch ( MemberException $e ) { |
|
| 171 | + } catch (MemberException $e) { |
|
| 172 | 172 | return $data; |
| 173 | 173 | } |
| 174 | - if ( $lord->valid ) { |
|
| 174 | + if ($lord->valid) { |
|
| 175 | 175 | $data['pid'] = $pid; |
| 176 | 176 | $data['wtt_lord_name'] = $lord->full_name(); |
| 177 | 177 | } |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | $url->insert(array('q' => $value)); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if ( $params ) { |
|
| 200 | - if ( get_http_var('house') ) { |
|
| 199 | + if ($params) { |
|
| 200 | + if (get_http_var('house')) { |
|
| 201 | 201 | $url->insert(array('house' => get_http_var('house'))); |
| 202 | 202 | } |
| 203 | - if ( get_http_var('wtt') ) { |
|
| 203 | + if (get_http_var('wtt')) { |
|
| 204 | 204 | $url->insert(array('wtt' => get_http_var('wtt'))); |
| 205 | 205 | } |
| 206 | 206 | } else { |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | global $DATA, $this_page; |
| 215 | 215 | |
| 216 | 216 | $pagetitle = ''; |
| 217 | - if ( isset($data['search_type']) && $data['search_type'] == 'person' ) { |
|
| 217 | + if (isset($data['search_type']) && $data['search_type'] == 'person') { |
|
| 218 | 218 | if (isset($data['wtt']) && $data['wtt'] > 0) { |
| 219 | 219 | $pagetitle = 'League table of Lords who say ' . $data['pagetitle']; |
| 220 | 220 | } else { |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | public function getDataSet() |
| 13 | 13 | { |
| 14 | - return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/member.xml'); |
|
| 14 | + return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/member.xml'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | public function getDataSet() |
| 13 | 13 | { |
| 14 | - return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/topics.xml'); |
|
| 14 | + return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/topics.xml'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | private function fetch_topics_page($vars) |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | public function getDataSet() |
| 13 | 13 | { |
| 14 | - return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/people.xml'); |
|
| 14 | + return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/people.xml'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | public function getDataSet() |
| 13 | 13 | { |
| 14 | - return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/hansard.xml'); |
|
| 14 | + return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/hansard.xml'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | public function getDataSet() |
| 13 | 13 | { |
| 14 | - return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/glossary.xml'); |
|
| 14 | + return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/glossary.xml'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |