@@ -125,7 +125,7 @@ |
||
| 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> |
@@ -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 = ""; // 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 |
||
| 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 |
||
| 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, so |
| 230 | 230 | // replace them. And double slash would be treated as single and |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | $r = $this->db->query("UPDATE users |
| 238 | 238 | SET registrationtoken = :registrationtoken |
| 239 | 239 | WHERE user_id = :user_id |
| 240 | - ", array ( |
|
| 240 | + ", array( |
|
| 241 | 241 | ':registrationtoken' => $this->registrationtoken, |
| 242 | 242 | ':user_id' => $this->user_id |
| 243 | 243 | )); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | public function add_facebook_id($facebook_id) { |
| 287 | - $q = $this->db->query ("UPDATE users SET facebook_id = :facebook_id WHERE email = :email", |
|
| 287 | + $q = $this->db->query("UPDATE users SET facebook_id = :facebook_id WHERE email = :email", |
|
| 288 | 288 | array( |
| 289 | 289 | ':facebook_id' => $facebook_id, |
| 290 | 290 | ':email' => $this->email |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | !isset($details['email']) || |
| 306 | 306 | $details['email'] == '' || |
| 307 | 307 | !isset($details['token']) || |
| 308 | - $details['token'] == '' ) { |
|
| 308 | + $details['token'] == '') { |
|
| 309 | 309 | return false; |
| 310 | 310 | } |
| 311 | 311 | |
@@ -317,12 +317,12 @@ discard block |
||
| 317 | 317 | $confirmurl = 'https://' . DOMAIN . '/E/' . $urltoken; |
| 318 | 318 | |
| 319 | 319 | // Arrays we need to send a templated email. |
| 320 | - $data = array ( |
|
| 320 | + $data = array( |
|
| 321 | 321 | 'to' => $details['email'], |
| 322 | 322 | 'template' => 'email_confirmation' |
| 323 | 323 | ); |
| 324 | 324 | |
| 325 | - $merge = array ( |
|
| 325 | + $merge = array( |
|
| 326 | 326 | 'FIRSTNAME' => $details['firstname'], |
| 327 | 327 | 'LASTNAME' => $details['lastname'], |
| 328 | 328 | 'CONFIRMURL' => $confirmurl |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Arrays we need to send a templated email. |
| 365 | - $data = array ( |
|
| 365 | + $data = array( |
|
| 366 | 366 | 'to' => $details['email'], |
| 367 | 367 | 'template' => 'join_confirmation' |
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - $merge = array ( |
|
| 370 | + $merge = array( |
|
| 371 | 371 | 'FIRSTNAME' => $details['firstname'], |
| 372 | 372 | 'LASTNAME' => $details['lastname'], |
| 373 | 373 | 'CONFIRMURL' => $confirmurl |
@@ -429,23 +429,23 @@ discard block |
||
| 429 | 429 | $this->email = $email; |
| 430 | 430 | for (;;) { |
| 431 | 431 | |
| 432 | - $pwd=null; |
|
| 433 | - $o=null; |
|
| 432 | + $pwd = null; |
|
| 433 | + $o = null; |
|
| 434 | 434 | |
| 435 | 435 | // Generates the password .... |
| 436 | - for ($x=0; $x < 6;) { |
|
| 437 | - $y = rand(1,1000); |
|
| 438 | - if($y>350 && $y<601) $d=chr(rand(48,57)); |
|
| 439 | - if($y<351) $d=chr(rand(65,90)); |
|
| 440 | - if($y>600) $d=chr(rand(97,122)); |
|
| 441 | - if ($d!=$o && !preg_match('#[O01lI]#', $d)) { |
|
| 442 | - $o=$d; $pwd.=$d; $x++; |
|
| 436 | + for ($x = 0; $x < 6;) { |
|
| 437 | + $y = rand(1, 1000); |
|
| 438 | + if ($y > 350 && $y < 601) $d = chr(rand(48, 57)); |
|
| 439 | + if ($y < 351) $d = chr(rand(65, 90)); |
|
| 440 | + if ($y > 600) $d = chr(rand(97, 122)); |
|
| 441 | + if ($d != $o && !preg_match('#[O01lI]#', $d)) { |
|
| 442 | + $o = $d; $pwd .= $d; $x++; |
|
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | // If the PW fits your purpose (e.g. this regexpression) return it, else make a new one |
| 447 | 447 | // (You can change this regular-expression how you want ....) |
| 448 | - if (preg_match("/^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+/",$pwd)) { |
|
| 448 | + if (preg_match("/^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+/", $pwd)) { |
|
| 449 | 449 | break; |
| 450 | 450 | } |
| 451 | 451 | |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | |
| 464 | 464 | $passwordforDB = password_hash($pwd, PASSWORD_BCRYPT); |
| 465 | 465 | |
| 466 | - $q = $this->db->query ("UPDATE users SET password = :password WHERE email = :email", |
|
| 466 | + $q = $this->db->query("UPDATE users SET password = :password WHERE email = :email", |
|
| 467 | 467 | array( |
| 468 | 468 | ':password' => $passwordforDB, |
| 469 | 469 | ':email' => $email |
@@ -491,14 +491,14 @@ discard block |
||
| 491 | 491 | return false; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - $data = array ( |
|
| 494 | + $data = array( |
|
| 495 | 495 | 'to' => $this->email(), |
| 496 | 496 | 'template' => 'new_password' |
| 497 | 497 | ); |
| 498 | 498 | |
| 499 | 499 | $URL = new \MySociety\TheyWorkForYou\Url("userlogin"); |
| 500 | 500 | |
| 501 | - $merge = array ( |
|
| 501 | + $merge = array( |
|
| 502 | 502 | 'EMAIL' => $this->email(), |
| 503 | 503 | 'LOGINURL' => "https://" . DOMAIN . $URL->generate(), |
| 504 | 504 | 'PASSWORD' => $this->password() |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | public function facebook_id_exists($id, $return_id = false) { |
| 554 | 554 | // Returns true if there's a user with this facebook id. |
| 555 | 555 | |
| 556 | - if ($id!= "") { |
|
| 556 | + if ($id != "") { |
|
| 557 | 557 | $q = $this->db->query("SELECT user_id FROM users WHERE facebook_id = :id", array(':id' => $id))->first(); |
| 558 | 558 | if ($q) { |
| 559 | 559 | if ($return_id) { |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | /* Everyone */ return true; |
| 629 | 629 | |
| 630 | 630 | default: |
| 631 | - $PAGE->error_message ("You need to set permissions for '$action'!"); |
|
| 631 | + $PAGE->error_message("You need to set permissions for '$action'!"); |
|
| 632 | 632 | |
| 633 | 633 | return false; |
| 634 | 634 | |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | // Maybe there's a way of fetching these from the DB, |
| 647 | 647 | // so we don't duplicate them here...? |
| 648 | 648 | |
| 649 | - $statuses = array ("Viewer", "User", "Moderator", "Administrator", "Superuser"); |
|
| 649 | + $statuses = array("Viewer", "User", "Moderator", "Administrator", "Superuser"); |
|
| 650 | 650 | |
| 651 | 651 | return $statuses; |
| 652 | 652 | |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | return $details; |
| 802 | 802 | |
| 803 | 803 | } else { |
| 804 | - $PAGE->error_message ("Sorry, we were unable to update user id '" . _htmlentities($details["user_id"]) . "'"); |
|
| 804 | + $PAGE->error_message("Sorry, we were unable to update user id '" . _htmlentities($details["user_id"]) . "'"); |
|
| 805 | 805 | |
| 806 | 806 | return false; |
| 807 | 807 | } |
@@ -874,13 +874,13 @@ discard block |
||
| 874 | 874 | |
| 875 | 875 | if ($this->facebook_user) { |
| 876 | 876 | if (md5($this->facebook_token()) == $matches[2] && $this->deleted() == false) { |
| 877 | - twfy_debug ("THEUSER", "init SUCCESS: setting as logged in"); |
|
| 877 | + twfy_debug("THEUSER", "init SUCCESS: setting as logged in"); |
|
| 878 | 878 | $this->loggedin = true; |
| 879 | - } elseif (md5 ($this->facebook_token()) != $matches[2]) { |
|
| 880 | - twfy_debug ("THEUSER", "init FAILED: Facebook token doesn't match cookie"); |
|
| 879 | + } elseif (md5($this->facebook_token()) != $matches[2]) { |
|
| 880 | + twfy_debug("THEUSER", "init FAILED: Facebook token doesn't match cookie"); |
|
| 881 | 881 | $this->loggedin = false; |
| 882 | 882 | } else { |
| 883 | - twfy_debug ("THEUSER", "init FAILED: User is deleted"); |
|
| 883 | + twfy_debug("THEUSER", "init FAILED: User is deleted"); |
|
| 884 | 884 | $this->loggedin = false; |
| 885 | 885 | } |
| 886 | 886 | } else { |
@@ -893,30 +893,30 @@ discard block |
||
| 893 | 893 | // to need. Their preferences and saved things or something. |
| 894 | 894 | |
| 895 | 895 | |
| 896 | - twfy_debug ("THEUSER init SUCCEEDED", "setting as logged in"); |
|
| 896 | + twfy_debug("THEUSER init SUCCEEDED", "setting as logged in"); |
|
| 897 | 897 | $this->loggedin = true; |
| 898 | 898 | |
| 899 | - } elseif (md5 ($this->password()) != $matches[2]) { |
|
| 900 | - twfy_debug ("THEUSER init FAILED", "Password doesn't match cookie"); |
|
| 899 | + } elseif (md5($this->password()) != $matches[2]) { |
|
| 900 | + twfy_debug("THEUSER init FAILED", "Password doesn't match cookie"); |
|
| 901 | 901 | $this->loggedin = false; |
| 902 | 902 | } else { |
| 903 | - twfy_debug ("THEUSER init FAILED", "User is deleted"); |
|
| 903 | + twfy_debug("THEUSER init FAILED", "User is deleted"); |
|
| 904 | 904 | $this->loggedin = false; |
| 905 | 905 | } |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | } else { |
| 909 | - twfy_debug ("THEUSER init FAILED", "didn't get 1 row from db"); |
|
| 909 | + twfy_debug("THEUSER init FAILED", "didn't get 1 row from db"); |
|
| 910 | 910 | $this->loggedin = false; |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | } else { |
| 914 | - twfy_debug ("THEUSER init FAILED", "cookie's user_id is not numeric"); |
|
| 914 | + twfy_debug("THEUSER init FAILED", "cookie's user_id is not numeric"); |
|
| 915 | 915 | $this->loggedin = false; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | } else { |
| 919 | - twfy_debug ("THEUSER init FAILED", "cookie is not of the correct form"); |
|
| 919 | + twfy_debug("THEUSER init FAILED", "cookie is not of the correct form"); |
|
| 920 | 920 | $this->loggedin = false; |
| 921 | 921 | } |
| 922 | 922 | |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | // Set last_visit to now. |
| 943 | 943 | $date_now = gmdate("Y-m-d H:i:s"); |
| 944 | 944 | $this->db->query("UPDATE users SET lastvisit = :lastvisit WHERE user_id = :user_id", |
| 945 | - [ ':lastvisit' => $date_now, ':user_id' => $this->user_id() ]); |
|
| 945 | + [':lastvisit' => $date_now, ':user_id' => $this->user_id()]); |
|
| 946 | 946 | |
| 947 | 947 | $this->lastvisit = $date_now; |
| 948 | 948 | } |
@@ -998,55 +998,55 @@ discard block |
||
| 998 | 998 | |
| 999 | 999 | } else { |
| 1000 | 1000 | // Failed. |
| 1001 | - return array ("invalidemail" => $error_string); |
|
| 1001 | + return array("invalidemail" => $error_string); |
|
| 1002 | 1002 | |
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | } else { |
| 1006 | 1006 | // Failed. |
| 1007 | - return array ("invalidemail" => $error_string); |
|
| 1007 | + return array("invalidemail" => $error_string); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | public function has_postcode() { |
| 1013 | 1013 | $has_postcode = false; |
| 1014 | - if ( $this->isloggedin() && $this->postcode() != '' || $this->postcode_is_set() ) { |
|
| 1014 | + if ($this->isloggedin() && $this->postcode() != '' || $this->postcode_is_set()) { |
|
| 1015 | 1015 | $has_postcode = true; |
| 1016 | 1016 | } |
| 1017 | 1017 | return $has_postcode; |
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | 1020 | |
| 1021 | - public function facebook_login($returl="", $expire, $accessToken) { |
|
| 1021 | + public function facebook_login($returl = "", $expire, $accessToken) { |
|
| 1022 | 1022 | global $PAGE; |
| 1023 | 1023 | |
| 1024 | 1024 | twfy_debug("THEUSER", "Faceook login, user_id " . $this->user_id); |
| 1025 | 1025 | twfy_debug("THEUSER", "Faceook login, facebook_id " . $this->facebook_id); |
| 1026 | 1026 | twfy_debug("THEUSER", "Faceook login, email" . $this->email); |
| 1027 | 1027 | if ($this->facebook_id() == "") { |
| 1028 | - $PAGE->error_message ("We don't have a facebook id for this user.", true); |
|
| 1028 | + $PAGE->error_message("We don't have a facebook id for this user.", true); |
|
| 1029 | 1029 | |
| 1030 | 1030 | return; |
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | twfy_debug("THEUSER", "Faceook login, facebook_token: " . $accessToken); |
| 1034 | 1034 | |
| 1035 | - $q = $this->db->query ("UPDATE users SET facebook_token = :token WHERE email = :email", |
|
| 1035 | + $q = $this->db->query("UPDATE users SET facebook_token = :token WHERE email = :email", |
|
| 1036 | 1036 | array( |
| 1037 | 1037 | ':token' => $accessToken, |
| 1038 | 1038 | ':email' => $this->email |
| 1039 | 1039 | )); |
| 1040 | 1040 | |
| 1041 | 1041 | if (!$q->success()) { |
| 1042 | - $PAGE->error_message ("There was a problem logging you in", true); |
|
| 1042 | + $PAGE->error_message("There was a problem logging you in", true); |
|
| 1043 | 1043 | twfy_debug("THEUSER", "Faceook login, failed to set accessToken"); |
| 1044 | 1044 | |
| 1045 | 1045 | return false; |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | // facebook login users probably don't have a password |
| 1049 | - $cookie = $this->user_id() . "." . md5 ($accessToken); |
|
| 1049 | + $cookie = $this->user_id() . "." . md5($accessToken); |
|
| 1050 | 1050 | twfy_debug("THEUSER", "Faceook login, cookie: " . $cookie); |
| 1051 | 1051 | |
| 1052 | 1052 | twfy_debug("USER", "logging in user from facebook " . $this->user_id); |
@@ -1056,7 +1056,7 @@ discard block |
||
| 1056 | 1056 | return true; |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - public function login($returl="", $expire) { |
|
| 1059 | + public function login($returl = "", $expire) { |
|
| 1060 | 1060 | |
| 1061 | 1061 | // This is used to log the user in. Duh. |
| 1062 | 1062 | // You should already have checked the user's email and password using |
@@ -1078,21 +1078,21 @@ discard block |
||
| 1078 | 1078 | |
| 1079 | 1079 | // Various checks about the user - if they fail, we exit. |
| 1080 | 1080 | if ($this->user_id() == "" || $this->password == "") { |
| 1081 | - $PAGE->error_message ("We don't have the user_id or password to make the cookie.", true); |
|
| 1081 | + $PAGE->error_message("We don't have the user_id or password to make the cookie.", true); |
|
| 1082 | 1082 | |
| 1083 | 1083 | return; |
| 1084 | 1084 | } elseif ($this->deleted) { |
| 1085 | - $PAGE->error_message ("This user has been deleted.", true); |
|
| 1085 | + $PAGE->error_message("This user has been deleted.", true); |
|
| 1086 | 1086 | |
| 1087 | 1087 | return; |
| 1088 | 1088 | } elseif (!$this->confirmed) { |
| 1089 | - $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 | + $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); |
|
| 1090 | 1090 | |
| 1091 | 1091 | return; |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | // Reminder: $this->password is actually a hashed version of the plaintext pw. |
| 1095 | - $cookie = $this->user_id() . "." . md5 ($this->password()); |
|
| 1095 | + $cookie = $this->user_id() . "." . md5($this->password()); |
|
| 1096 | 1096 | |
| 1097 | 1097 | $this->_login($returl, $expire, $cookie); |
| 1098 | 1098 | } |
@@ -1108,7 +1108,7 @@ discard block |
||
| 1108 | 1108 | $cookie_expires = 0; |
| 1109 | 1109 | if ($expire == 'never') { |
| 1110 | 1110 | twfy_debug("THEUSER", "cookie never expires"); |
| 1111 | - $cookie_expires = time()+86400*365*20; |
|
| 1111 | + $cookie_expires = time() + 86400 * 365 * 20; |
|
| 1112 | 1112 | } elseif (is_int($expire) && $expire > time()) { |
| 1113 | 1113 | twfy_debug("THEUSER", "cookie expires at " . $expire); |
| 1114 | 1114 | $cookie_expires = $expire; |
@@ -1146,7 +1146,7 @@ discard block |
||
| 1146 | 1146 | } |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | - public function confirm_email($token, $redirect=true) { |
|
| 1149 | + public function confirm_email($token, $redirect = true) { |
|
| 1150 | 1150 | $arg = ''; |
| 1151 | 1151 | if (strstr($token, '::')) $arg = '::'; |
| 1152 | 1152 | if (strstr($token, '-')) $arg = '-'; |
@@ -1159,24 +1159,24 @@ discard block |
||
| 1159 | 1159 | FROM tokens |
| 1160 | 1160 | WHERE token = :token |
| 1161 | 1161 | AND type = 'E' |
| 1162 | - ", array (':token' => $registrationtoken))->first(); |
|
| 1162 | + ", array(':token' => $registrationtoken))->first(); |
|
| 1163 | 1163 | |
| 1164 | 1164 | if ($q) { |
| 1165 | 1165 | $expires = $q['expires']; |
| 1166 | 1166 | $expire_time = strtotime($expires); |
| 1167 | - if ( $expire_time < time() ) { |
|
| 1167 | + if ($expire_time < time()) { |
|
| 1168 | 1168 | global $PAGE; |
| 1169 | 1169 | if ($PAGE && $redirect) { |
| 1170 | - $PAGE->error_message ("Sorry, that token seems to have expired"); |
|
| 1170 | + $PAGE->error_message("Sorry, that token seems to have expired"); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | return false; |
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | - list( $user_id, $email ) = explode('::', $q['data']); |
|
| 1176 | + list($user_id, $email) = explode('::', $q['data']); |
|
| 1177 | 1177 | |
| 1178 | 1178 | // if we are logged in as someone else don't change the email |
| 1179 | - if ( $this->user_id() != 0 && $this->user_id() != $user_id ) { |
|
| 1179 | + if ($this->user_id() != 0 && $this->user_id() != $user_id) { |
|
| 1180 | 1180 | return false; |
| 1181 | 1181 | } |
| 1182 | 1182 | |
@@ -1325,7 +1325,7 @@ discard block |
||
| 1325 | 1325 | |
| 1326 | 1326 | twfy_debug("THEUSER", "User with ID found to confirm: " . $this->user_id()); |
| 1327 | 1327 | // We'll need these to be set before logging the user in. |
| 1328 | - $this->email = $q['email']; |
|
| 1328 | + $this->email = $q['email']; |
|
| 1329 | 1329 | |
| 1330 | 1330 | // Set that they're confirmed in the DB. |
| 1331 | 1331 | $r = $this->db->query("UPDATE users |
@@ -1372,14 +1372,14 @@ discard block |
||
| 1372 | 1372 | |
| 1373 | 1373 | $this->postcode = $pc; |
| 1374 | 1374 | if (!headers_sent()) // if in debug mode |
| 1375 | - setcookie (POSTCODE_COOKIE, $pc, time()+7*86400, "/", COOKIEDOMAIN); |
|
| 1375 | + setcookie(POSTCODE_COOKIE, $pc, time() + 7 * 86400, "/", COOKIEDOMAIN); |
|
| 1376 | 1376 | |
| 1377 | 1377 | twfy_debug('USER', "Set the cookie named '" . POSTCODE_COOKIE . " to '$pc' for " . COOKIEDOMAIN . " domain"); |
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | 1380 | public function unset_postcode_cookie() { |
| 1381 | 1381 | if (!headers_sent()) // if in debug mode |
| 1382 | - setcookie (POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN); |
|
| 1382 | + setcookie(POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN); |
|
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | 1385 | // mostly here for updating from facebook where we do not need |
@@ -1392,8 +1392,8 @@ discard block |
||
| 1392 | 1392 | |
| 1393 | 1393 | // this is checked elsewhere but just in case we check here and |
| 1394 | 1394 | // bail out to be on the safe side |
| 1395 | - if ( isset($details['email'] ) ) { |
|
| 1396 | - if ( $details['email'] != $this->email() && $this->email_exists( $details['email'] ) ) { |
|
| 1395 | + if (isset($details['email'])) { |
|
| 1396 | + if ($details['email'] != $this->email() && $this->email_exists($details['email'])) { |
|
| 1397 | 1397 | return false; |
| 1398 | 1398 | } |
| 1399 | 1399 | } |
@@ -1441,8 +1441,8 @@ discard block |
||
| 1441 | 1441 | // this is checked elsewhere but just in case we check here and |
| 1442 | 1442 | // bail out to be on the safe side |
| 1443 | 1443 | $email = ''; |
| 1444 | - if ( isset($details['email'] ) ) { |
|
| 1445 | - if ( $details['email'] != $this->email() && $this->email_exists( $details['email'] ) ) { |
|
| 1444 | + if (isset($details['email'])) { |
|
| 1445 | + if ($details['email'] != $this->email() && $this->email_exists($details['email'])) { |
|
| 1446 | 1446 | return false; |
| 1447 | 1447 | } |
| 1448 | 1448 | $email = $details['email']; |
@@ -1469,7 +1469,7 @@ discard block |
||
| 1469 | 1469 | } |
| 1470 | 1470 | |
| 1471 | 1471 | if ($email && $email != $this->email) { |
| 1472 | - $token = substr( password_hash($email . microtime(), PASSWORD_BCRYPT), 29, 16 ); |
|
| 1472 | + $token = substr(password_hash($email . microtime(), PASSWORD_BCRYPT), 29, 16); |
|
| 1473 | 1473 | $data = $this->user_id() . '::' . $email; |
| 1474 | 1474 | $r = $this->db->query("INSERT INTO tokens |
| 1475 | 1475 | ( expires, token, type, data ) |
@@ -1486,7 +1486,7 @@ discard block |
||
| 1486 | 1486 | )); |
| 1487 | 1487 | |
| 1488 | 1488 | // send confirmation email here |
| 1489 | - if ( $r->success() ) { |
|
| 1489 | + if ($r->success()) { |
|
| 1490 | 1490 | $newdetails['email'] = $email; |
| 1491 | 1491 | $newdetails['token'] = $token; |
| 1492 | 1492 | 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 | ) |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function set($key, $value, $timeout = 3600) { |
| 28 | 28 | if (class_exists('\Memcached')) { |
| 29 | - self::$memcache->set(OPTION_TWFY_DB_NAME.':'.$key, $value, $timeout); |
|
| 29 | + self::$memcache->set(OPTION_TWFY_DB_NAME . ':' . $key, $value, $timeout); |
|
| 30 | 30 | } else { |
| 31 | - self::$memcache->set(OPTION_TWFY_DB_NAME.':'.$key, $value, MEMCACHE_COMPRESSED, $timeout); |
|
| 31 | + self::$memcache->set(OPTION_TWFY_DB_NAME . ':' . $key, $value, MEMCACHE_COMPRESSED, $timeout); |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | // see http://php.net/manual/en/memcache.get.php#112056 for explanation of this |
| 37 | 37 | $was_found = false; |
| 38 | 38 | if (class_exists('\Memcached')) { |
| 39 | - $value = self::$memcache->get(OPTION_TWFY_DB_NAME.':'.$key, null, $was_found); |
|
| 39 | + $value = self::$memcache->get(OPTION_TWFY_DB_NAME . ':' . $key, null, $was_found); |
|
| 40 | 40 | } else { |
| 41 | - $value = self::$memcache->get(OPTION_TWFY_DB_NAME.':'.$key, $was_found); |
|
| 41 | + $value = self::$memcache->get(OPTION_TWFY_DB_NAME . ':' . $key, $was_found); |
|
| 42 | 42 | } |
| 43 | 43 | if ($was_found === false) { |
| 44 | 44 | return false; // mmmmm |
@@ -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 { |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | public static function dbConnect() { |
| 15 | - $connstr = 'host='.OPTION_BBC_DB_HOST.' port='.OPTION_BBC_DB_PORT.' dbname='.OPTION_BBC_DB_NAME.' user='.OPTION_BBC_DB_USER.' password='.OPTION_BBC_DB_PASS; |
|
| 15 | + $connstr = 'host=' . OPTION_BBC_DB_HOST . ' port=' . OPTION_BBC_DB_PORT . ' dbname=' . OPTION_BBC_DB_NAME . ' user=' . OPTION_BBC_DB_USER . ' password=' . OPTION_BBC_DB_PASS; |
|
| 16 | 16 | $videodb = pg_connect($connstr); |
| 17 | 17 | |
| 18 | 18 | return $videodb; |
@@ -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) |