@@ -18,34 +18,34 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class FakeGlobalStateProvider extends GlobalStateProvider implements IGlobalStateProvider |
| 20 | 20 | { |
| 21 | - var $server = array(); |
|
| 22 | - var $get = array(); |
|
| 23 | - var $post = array(); |
|
| 24 | - var $session = array(); |
|
| 25 | - var $cookie = array(); |
|
| 21 | + var $server = array(); |
|
| 22 | + var $get = array(); |
|
| 23 | + var $post = array(); |
|
| 24 | + var $session = array(); |
|
| 25 | + var $cookie = array(); |
|
| 26 | 26 | |
| 27 | - public function &getServerSuperGlobal() |
|
| 28 | - { |
|
| 29 | - return $this->server; |
|
| 30 | - } |
|
| 27 | + public function &getServerSuperGlobal() |
|
| 28 | + { |
|
| 29 | + return $this->server; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function &getGetSuperGlobal() |
|
| 33 | - { |
|
| 34 | - return $this->get; |
|
| 35 | - } |
|
| 32 | + public function &getGetSuperGlobal() |
|
| 33 | + { |
|
| 34 | + return $this->get; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function &getPostSuperGlobal() |
|
| 38 | - { |
|
| 39 | - return $this->post; |
|
| 40 | - } |
|
| 37 | + public function &getPostSuperGlobal() |
|
| 38 | + { |
|
| 39 | + return $this->post; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function &getSessionSuperGlobal() |
|
| 43 | - { |
|
| 44 | - return $this->session; |
|
| 45 | - } |
|
| 42 | + public function &getSessionSuperGlobal() |
|
| 43 | + { |
|
| 44 | + return $this->session; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function &getCookieSuperGlobal() |
|
| 48 | - { |
|
| 49 | - return $this->cookie; |
|
| 50 | - } |
|
| 47 | + public function &getCookieSuperGlobal() |
|
| 48 | + { |
|
| 49 | + return $this->cookie; |
|
| 50 | + } |
|
| 51 | 51 | } |
| 52 | 52 | \ No newline at end of file |
@@ -22,156 +22,156 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class XffTrustProvider implements IXffTrustProvider |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * Array of IP addresses which are TRUSTED proxies |
|
| 27 | - * @var string[] |
|
| 28 | - */ |
|
| 29 | - private $trustedCache; |
|
| 30 | - /** |
|
| 31 | - * Array of IP addresses which are UNTRUSTED proxies |
|
| 32 | - * @var string[] |
|
| 33 | - */ |
|
| 34 | - private $untrustedCache = array(); |
|
| 35 | - /** @var PDOStatement */ |
|
| 36 | - private $trustedQuery; |
|
| 37 | - /** |
|
| 38 | - * @var PdoDatabase |
|
| 39 | - */ |
|
| 40 | - private $database; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Creates a new instance of the trust provider |
|
| 44 | - * |
|
| 45 | - * @param string[] $squidIpList List of IP addresses to pre-approve |
|
| 46 | - * @param PdoDatabase $database |
|
| 47 | - */ |
|
| 48 | - public function __construct($squidIpList, PdoDatabase $database) |
|
| 49 | - { |
|
| 50 | - $this->trustedCache = $squidIpList; |
|
| 51 | - $this->database = $database; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Returns a value if the IP address is a trusted proxy |
|
| 56 | - * |
|
| 57 | - * @param string $ip |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function isTrusted($ip) |
|
| 62 | - { |
|
| 63 | - if (in_array($ip, $this->trustedCache)) { |
|
| 64 | - return true; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if (in_array($ip, $this->untrustedCache)) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if ($this->trustedQuery === null) { |
|
| 72 | - $query = "SELECT COUNT(id) FROM xfftrustcache WHERE ip = :ip;"; |
|
| 73 | - $this->trustedQuery = $this->database->prepare($query); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $this->trustedQuery->execute(array(":ip" => $ip)); |
|
| 77 | - $result = $this->trustedQuery->fetchColumn(); |
|
| 78 | - $this->trustedQuery->closeCursor(); |
|
| 79 | - |
|
| 80 | - if ($result == 0) { |
|
| 81 | - $this->untrustedCache[] = $ip; |
|
| 82 | - |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($result >= 1) { |
|
| 87 | - $this->trustedCache[] = $ip; |
|
| 88 | - |
|
| 89 | - return true; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // something weird has happened if we've got here. |
|
| 93 | - // default to untrusted. |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Gets the last trusted IP in the proxy chain. |
|
| 99 | - * |
|
| 100 | - * @param string $ip The IP address from REMOTE_ADDR |
|
| 101 | - * @param string $proxyIp The contents of the XFF header. |
|
| 102 | - * |
|
| 103 | - * @return string Trusted source IP address |
|
| 104 | - */ |
|
| 105 | - public function getTrustedClientIp($ip, $proxyIp) |
|
| 106 | - { |
|
| 107 | - $clientIpAddress = $ip; |
|
| 108 | - if ($proxyIp) { |
|
| 109 | - $ipList = explode(",", $proxyIp); |
|
| 110 | - $ipList[] = $clientIpAddress; |
|
| 111 | - $ipList = array_reverse($ipList); |
|
| 112 | - |
|
| 113 | - foreach ($ipList as $ipNumber => $ipAddress) { |
|
| 114 | - if ($this->isTrusted(trim($ipAddress)) && $ipNumber < (count($ipList) - 1)) { |
|
| 115 | - continue; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $clientIpAddress = $ipAddress; |
|
| 119 | - break; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $clientIpAddress; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them. |
|
| 128 | - * |
|
| 129 | - * @param array $haystack |
|
| 130 | - * @param string $ip |
|
| 131 | - * |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function ipInRange($haystack, $ip) |
|
| 135 | - { |
|
| 136 | - $needle = ip2long($ip); |
|
| 137 | - |
|
| 138 | - foreach ($haystack as $low => $high) { |
|
| 139 | - if (ip2long($low) <= $needle && ip2long($high) >= $needle) { |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Explodes a CIDR range into an array of addresses |
|
| 149 | - * |
|
| 150 | - * @param string $range A CIDR-format range |
|
| 151 | - * |
|
| 152 | - * @return array An array containing every IP address in the range |
|
| 153 | - */ |
|
| 154 | - public function explodeCidr($range) |
|
| 155 | - { |
|
| 156 | - $cidrData = explode('/', $range); |
|
| 157 | - |
|
| 158 | - if (!isset($cidrData[1])) { |
|
| 159 | - return array($range); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $blow = ( |
|
| 163 | - str_pad(decbin(ip2long($cidrData[0])), 32, "0", STR_PAD_LEFT) & |
|
| 164 | - str_pad(str_pad("", $cidrData[1], "1"), 32, "0") |
|
| 165 | - ); |
|
| 166 | - $bhigh = ($blow | str_pad(str_pad("", $cidrData[1], "0"), 32, "1")); |
|
| 167 | - |
|
| 168 | - $list = array(); |
|
| 169 | - |
|
| 170 | - $bindecBHigh = bindec($bhigh); |
|
| 171 | - for ($x = bindec($blow); $x <= $bindecBHigh; $x++) { |
|
| 172 | - $list[] = long2ip($x); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $list; |
|
| 176 | - } |
|
| 25 | + /** |
|
| 26 | + * Array of IP addresses which are TRUSTED proxies |
|
| 27 | + * @var string[] |
|
| 28 | + */ |
|
| 29 | + private $trustedCache; |
|
| 30 | + /** |
|
| 31 | + * Array of IP addresses which are UNTRUSTED proxies |
|
| 32 | + * @var string[] |
|
| 33 | + */ |
|
| 34 | + private $untrustedCache = array(); |
|
| 35 | + /** @var PDOStatement */ |
|
| 36 | + private $trustedQuery; |
|
| 37 | + /** |
|
| 38 | + * @var PdoDatabase |
|
| 39 | + */ |
|
| 40 | + private $database; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Creates a new instance of the trust provider |
|
| 44 | + * |
|
| 45 | + * @param string[] $squidIpList List of IP addresses to pre-approve |
|
| 46 | + * @param PdoDatabase $database |
|
| 47 | + */ |
|
| 48 | + public function __construct($squidIpList, PdoDatabase $database) |
|
| 49 | + { |
|
| 50 | + $this->trustedCache = $squidIpList; |
|
| 51 | + $this->database = $database; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Returns a value if the IP address is a trusted proxy |
|
| 56 | + * |
|
| 57 | + * @param string $ip |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function isTrusted($ip) |
|
| 62 | + { |
|
| 63 | + if (in_array($ip, $this->trustedCache)) { |
|
| 64 | + return true; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if (in_array($ip, $this->untrustedCache)) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if ($this->trustedQuery === null) { |
|
| 72 | + $query = "SELECT COUNT(id) FROM xfftrustcache WHERE ip = :ip;"; |
|
| 73 | + $this->trustedQuery = $this->database->prepare($query); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $this->trustedQuery->execute(array(":ip" => $ip)); |
|
| 77 | + $result = $this->trustedQuery->fetchColumn(); |
|
| 78 | + $this->trustedQuery->closeCursor(); |
|
| 79 | + |
|
| 80 | + if ($result == 0) { |
|
| 81 | + $this->untrustedCache[] = $ip; |
|
| 82 | + |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($result >= 1) { |
|
| 87 | + $this->trustedCache[] = $ip; |
|
| 88 | + |
|
| 89 | + return true; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // something weird has happened if we've got here. |
|
| 93 | + // default to untrusted. |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Gets the last trusted IP in the proxy chain. |
|
| 99 | + * |
|
| 100 | + * @param string $ip The IP address from REMOTE_ADDR |
|
| 101 | + * @param string $proxyIp The contents of the XFF header. |
|
| 102 | + * |
|
| 103 | + * @return string Trusted source IP address |
|
| 104 | + */ |
|
| 105 | + public function getTrustedClientIp($ip, $proxyIp) |
|
| 106 | + { |
|
| 107 | + $clientIpAddress = $ip; |
|
| 108 | + if ($proxyIp) { |
|
| 109 | + $ipList = explode(",", $proxyIp); |
|
| 110 | + $ipList[] = $clientIpAddress; |
|
| 111 | + $ipList = array_reverse($ipList); |
|
| 112 | + |
|
| 113 | + foreach ($ipList as $ipNumber => $ipAddress) { |
|
| 114 | + if ($this->isTrusted(trim($ipAddress)) && $ipNumber < (count($ipList) - 1)) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $clientIpAddress = $ipAddress; |
|
| 119 | + break; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $clientIpAddress; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them. |
|
| 128 | + * |
|
| 129 | + * @param array $haystack |
|
| 130 | + * @param string $ip |
|
| 131 | + * |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function ipInRange($haystack, $ip) |
|
| 135 | + { |
|
| 136 | + $needle = ip2long($ip); |
|
| 137 | + |
|
| 138 | + foreach ($haystack as $low => $high) { |
|
| 139 | + if (ip2long($low) <= $needle && ip2long($high) >= $needle) { |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Explodes a CIDR range into an array of addresses |
|
| 149 | + * |
|
| 150 | + * @param string $range A CIDR-format range |
|
| 151 | + * |
|
| 152 | + * @return array An array containing every IP address in the range |
|
| 153 | + */ |
|
| 154 | + public function explodeCidr($range) |
|
| 155 | + { |
|
| 156 | + $cidrData = explode('/', $range); |
|
| 157 | + |
|
| 158 | + if (!isset($cidrData[1])) { |
|
| 159 | + return array($range); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $blow = ( |
|
| 163 | + str_pad(decbin(ip2long($cidrData[0])), 32, "0", STR_PAD_LEFT) & |
|
| 164 | + str_pad(str_pad("", $cidrData[1], "1"), 32, "0") |
|
| 165 | + ); |
|
| 166 | + $bhigh = ($blow | str_pad(str_pad("", $cidrData[1], "0"), 32, "1")); |
|
| 167 | + |
|
| 168 | + $list = array(); |
|
| 169 | + |
|
| 170 | + $bindecBHigh = bindec($bhigh); |
|
| 171 | + for ($x = bindec($blow); $x <= $bindecBHigh; $x++) { |
|
| 172 | + $list[] = long2ip($x); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $list; |
|
| 176 | + } |
|
| 177 | 177 | } |
@@ -21,107 +21,107 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class IpLocationProvider implements ILocationProvider |
| 23 | 23 | { |
| 24 | - /** @var string */ |
|
| 25 | - private $apiKey; |
|
| 26 | - /** @var PdoDatabase */ |
|
| 27 | - private $database; |
|
| 28 | - /** @var HttpHelper */ |
|
| 29 | - private $httpHelper; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * IpLocationProvider constructor. |
|
| 33 | - * |
|
| 34 | - * @param PdoDatabase $database |
|
| 35 | - * @param string $apiKey |
|
| 36 | - * @param HttpHelper $httpHelper |
|
| 37 | - */ |
|
| 38 | - public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper) |
|
| 39 | - { |
|
| 40 | - $this->database = $database; |
|
| 41 | - $this->apiKey = $apiKey; |
|
| 42 | - $this->httpHelper = $httpHelper; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param string $address |
|
| 47 | - * |
|
| 48 | - * @return array|null |
|
| 49 | - * @throws Exception |
|
| 50 | - * @throws OptimisticLockFailedException |
|
| 51 | - */ |
|
| 52 | - public function getIpLocation($address) |
|
| 53 | - { |
|
| 54 | - $address = trim($address); |
|
| 55 | - |
|
| 56 | - // lets look in our database first. |
|
| 57 | - $location = GeoLocation::getByAddress($address, $this->database, true); |
|
| 58 | - |
|
| 59 | - if ($location != null) { |
|
| 60 | - // touch cache timer |
|
| 61 | - $location->save(); |
|
| 62 | - |
|
| 63 | - return $location->getData(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // OK, it's not there, let's do an IP2Location lookup. |
|
| 67 | - $result = $this->getResult($address); |
|
| 68 | - |
|
| 69 | - if ($result != null) { |
|
| 70 | - $location = new GeoLocation(); |
|
| 71 | - $location->setDatabase($this->database); |
|
| 72 | - $location->setAddress($address); |
|
| 73 | - $location->setData($result); |
|
| 74 | - $location->save(); |
|
| 75 | - |
|
| 76 | - return $result; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - return null; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // adapted from http://www.ipinfodb.com/ip_location_api.php |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param string $ip |
|
| 86 | - * |
|
| 87 | - * @return array|null |
|
| 88 | - */ |
|
| 89 | - private function getResult($ip) |
|
| 90 | - { |
|
| 91 | - try { |
|
| 92 | - if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
| 93 | - $xml = $this->httpHelper->get($this->getApiBase(), array( |
|
| 94 | - 'key' => $this->apiKey, |
|
| 95 | - 'ip' => $ip, |
|
| 96 | - 'format' => 'xml', |
|
| 97 | - )); |
|
| 98 | - |
|
| 99 | - $response = @new SimpleXMLElement($xml); |
|
| 100 | - |
|
| 101 | - $result = array(); |
|
| 102 | - |
|
| 103 | - foreach ($response as $field => $value) { |
|
| 104 | - $result[(string)$field] = (string)$value; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $result; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - catch (Exception $ex) { |
|
| 111 | - return null; |
|
| 112 | - |
|
| 113 | - // LOGME: do something smart here, or wherever we use this value. |
|
| 114 | - // This is just a temp hack to squash errors on the UI for now. |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return null; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - protected function getApiBase() |
|
| 124 | - { |
|
| 125 | - return "http://api.ipinfodb.com/v3/ip-city/"; |
|
| 126 | - } |
|
| 24 | + /** @var string */ |
|
| 25 | + private $apiKey; |
|
| 26 | + /** @var PdoDatabase */ |
|
| 27 | + private $database; |
|
| 28 | + /** @var HttpHelper */ |
|
| 29 | + private $httpHelper; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * IpLocationProvider constructor. |
|
| 33 | + * |
|
| 34 | + * @param PdoDatabase $database |
|
| 35 | + * @param string $apiKey |
|
| 36 | + * @param HttpHelper $httpHelper |
|
| 37 | + */ |
|
| 38 | + public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper) |
|
| 39 | + { |
|
| 40 | + $this->database = $database; |
|
| 41 | + $this->apiKey = $apiKey; |
|
| 42 | + $this->httpHelper = $httpHelper; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param string $address |
|
| 47 | + * |
|
| 48 | + * @return array|null |
|
| 49 | + * @throws Exception |
|
| 50 | + * @throws OptimisticLockFailedException |
|
| 51 | + */ |
|
| 52 | + public function getIpLocation($address) |
|
| 53 | + { |
|
| 54 | + $address = trim($address); |
|
| 55 | + |
|
| 56 | + // lets look in our database first. |
|
| 57 | + $location = GeoLocation::getByAddress($address, $this->database, true); |
|
| 58 | + |
|
| 59 | + if ($location != null) { |
|
| 60 | + // touch cache timer |
|
| 61 | + $location->save(); |
|
| 62 | + |
|
| 63 | + return $location->getData(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // OK, it's not there, let's do an IP2Location lookup. |
|
| 67 | + $result = $this->getResult($address); |
|
| 68 | + |
|
| 69 | + if ($result != null) { |
|
| 70 | + $location = new GeoLocation(); |
|
| 71 | + $location->setDatabase($this->database); |
|
| 72 | + $location->setAddress($address); |
|
| 73 | + $location->setData($result); |
|
| 74 | + $location->save(); |
|
| 75 | + |
|
| 76 | + return $result; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + return null; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // adapted from http://www.ipinfodb.com/ip_location_api.php |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param string $ip |
|
| 86 | + * |
|
| 87 | + * @return array|null |
|
| 88 | + */ |
|
| 89 | + private function getResult($ip) |
|
| 90 | + { |
|
| 91 | + try { |
|
| 92 | + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
| 93 | + $xml = $this->httpHelper->get($this->getApiBase(), array( |
|
| 94 | + 'key' => $this->apiKey, |
|
| 95 | + 'ip' => $ip, |
|
| 96 | + 'format' => 'xml', |
|
| 97 | + )); |
|
| 98 | + |
|
| 99 | + $response = @new SimpleXMLElement($xml); |
|
| 100 | + |
|
| 101 | + $result = array(); |
|
| 102 | + |
|
| 103 | + foreach ($response as $field => $value) { |
|
| 104 | + $result[(string)$field] = (string)$value; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $result; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + catch (Exception $ex) { |
|
| 111 | + return null; |
|
| 112 | + |
|
| 113 | + // LOGME: do something smart here, or wherever we use this value. |
|
| 114 | + // This is just a temp hack to squash errors on the UI for now. |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return null; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + protected function getApiBase() |
|
| 124 | + { |
|
| 125 | + return "http://api.ipinfodb.com/v3/ip-city/"; |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -26,133 +26,133 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | class IdentificationVerifier |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia |
|
| 31 | - * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard. Note that URL encoding |
|
| 32 | - * of these values is *not* necessary; this is done automatically. |
|
| 33 | - * |
|
| 34 | - * @var string[] |
|
| 35 | - * @category Security-Critical |
|
| 36 | - */ |
|
| 37 | - private static $apiQueryParameters = array( |
|
| 38 | - 'action' => 'query', |
|
| 39 | - 'format' => 'json', |
|
| 40 | - 'prop' => 'links', |
|
| 41 | - // Populated from SiteConfiguration->getIdentificationNoticeboardPage |
|
| 42 | - 'titles' => '', |
|
| 43 | - // Username of the user to be checked, with User: prefix, goes here! Set in isIdentifiedOnWiki() |
|
| 44 | - 'pltitles' => '', |
|
| 45 | - ); |
|
| 46 | - /** @var HttpHelper */ |
|
| 47 | - private $httpHelper; |
|
| 48 | - /** @var SiteConfiguration */ |
|
| 49 | - private $siteConfiguration; |
|
| 50 | - /** @var PdoDatabase */ |
|
| 51 | - private $dbObject; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * IdentificationVerifier constructor. |
|
| 55 | - * |
|
| 56 | - * @param HttpHelper $httpHelper |
|
| 57 | - * @param SiteConfiguration $siteConfiguration |
|
| 58 | - * @param PdoDatabase $dbObject |
|
| 59 | - */ |
|
| 60 | - public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
| 61 | - { |
|
| 62 | - $this->httpHelper = $httpHelper; |
|
| 63 | - $this->siteConfiguration = $siteConfiguration; |
|
| 64 | - $this->dbObject = $dbObject; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Checks if the given user is identified to the Wikimedia Foundation. |
|
| 69 | - * |
|
| 70 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 71 | - * |
|
| 72 | - * @return bool |
|
| 73 | - * @category Security-Critical |
|
| 74 | - * @throws EnvironmentException |
|
| 75 | - */ |
|
| 76 | - public function isUserIdentified($onWikiName) |
|
| 77 | - { |
|
| 78 | - if ($this->checkIdentificationCache($onWikiName)) { |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - if ($this->isIdentifiedOnWiki($onWikiName)) { |
|
| 83 | - $this->cacheIdentificationStatus($onWikiName); |
|
| 84 | - |
|
| 85 | - return true; |
|
| 86 | - } |
|
| 87 | - else { |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Checks if the given user has a valid entry in the idcache table. |
|
| 95 | - * |
|
| 96 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 97 | - * |
|
| 98 | - * @return bool |
|
| 99 | - * @category Security-Critical |
|
| 100 | - */ |
|
| 101 | - private function checkIdentificationCache($onWikiName) |
|
| 102 | - { |
|
| 103 | - $interval = $this->siteConfiguration->getIdentificationCacheExpiry(); |
|
| 104 | - |
|
| 105 | - $query = <<<SQL |
|
| 29 | + /** |
|
| 30 | + * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia |
|
| 31 | + * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard. Note that URL encoding |
|
| 32 | + * of these values is *not* necessary; this is done automatically. |
|
| 33 | + * |
|
| 34 | + * @var string[] |
|
| 35 | + * @category Security-Critical |
|
| 36 | + */ |
|
| 37 | + private static $apiQueryParameters = array( |
|
| 38 | + 'action' => 'query', |
|
| 39 | + 'format' => 'json', |
|
| 40 | + 'prop' => 'links', |
|
| 41 | + // Populated from SiteConfiguration->getIdentificationNoticeboardPage |
|
| 42 | + 'titles' => '', |
|
| 43 | + // Username of the user to be checked, with User: prefix, goes here! Set in isIdentifiedOnWiki() |
|
| 44 | + 'pltitles' => '', |
|
| 45 | + ); |
|
| 46 | + /** @var HttpHelper */ |
|
| 47 | + private $httpHelper; |
|
| 48 | + /** @var SiteConfiguration */ |
|
| 49 | + private $siteConfiguration; |
|
| 50 | + /** @var PdoDatabase */ |
|
| 51 | + private $dbObject; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * IdentificationVerifier constructor. |
|
| 55 | + * |
|
| 56 | + * @param HttpHelper $httpHelper |
|
| 57 | + * @param SiteConfiguration $siteConfiguration |
|
| 58 | + * @param PdoDatabase $dbObject |
|
| 59 | + */ |
|
| 60 | + public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
| 61 | + { |
|
| 62 | + $this->httpHelper = $httpHelper; |
|
| 63 | + $this->siteConfiguration = $siteConfiguration; |
|
| 64 | + $this->dbObject = $dbObject; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Checks if the given user is identified to the Wikimedia Foundation. |
|
| 69 | + * |
|
| 70 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 71 | + * |
|
| 72 | + * @return bool |
|
| 73 | + * @category Security-Critical |
|
| 74 | + * @throws EnvironmentException |
|
| 75 | + */ |
|
| 76 | + public function isUserIdentified($onWikiName) |
|
| 77 | + { |
|
| 78 | + if ($this->checkIdentificationCache($onWikiName)) { |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + if ($this->isIdentifiedOnWiki($onWikiName)) { |
|
| 83 | + $this->cacheIdentificationStatus($onWikiName); |
|
| 84 | + |
|
| 85 | + return true; |
|
| 86 | + } |
|
| 87 | + else { |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Checks if the given user has a valid entry in the idcache table. |
|
| 95 | + * |
|
| 96 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 97 | + * |
|
| 98 | + * @return bool |
|
| 99 | + * @category Security-Critical |
|
| 100 | + */ |
|
| 101 | + private function checkIdentificationCache($onWikiName) |
|
| 102 | + { |
|
| 103 | + $interval = $this->siteConfiguration->getIdentificationCacheExpiry(); |
|
| 104 | + |
|
| 105 | + $query = <<<SQL |
|
| 106 | 106 | SELECT COUNT(`id`) |
| 107 | 107 | FROM `idcache` |
| 108 | 108 | WHERE `onwikiusername` = :onwikiname |
| 109 | 109 | AND DATE_ADD(`checktime`, INTERVAL {$interval}) >= NOW(); |
| 110 | 110 | SQL; |
| 111 | - $stmt = $this->dbObject->prepare($query); |
|
| 112 | - $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
| 113 | - $stmt->execute(); |
|
| 114 | - |
|
| 115 | - // Guaranteed by the query to only return a single row with a single column |
|
| 116 | - $results = $stmt->fetch(PDO::FETCH_NUM); |
|
| 117 | - |
|
| 118 | - // I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a |
|
| 119 | - // unique key - but meh. |
|
| 120 | - return $results[0] != 0; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the |
|
| 125 | - * idcache table. Meant to be called periodically by a maintenance script. |
|
| 126 | - * |
|
| 127 | - * @param SiteConfiguration $siteConfiguration |
|
| 128 | - * @param PdoDatabase $dbObject |
|
| 129 | - * |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
| 133 | - { |
|
| 134 | - $interval = $siteConfiguration->getIdentificationCacheExpiry(); |
|
| 135 | - |
|
| 136 | - $query = <<<SQL |
|
| 111 | + $stmt = $this->dbObject->prepare($query); |
|
| 112 | + $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
| 113 | + $stmt->execute(); |
|
| 114 | + |
|
| 115 | + // Guaranteed by the query to only return a single row with a single column |
|
| 116 | + $results = $stmt->fetch(PDO::FETCH_NUM); |
|
| 117 | + |
|
| 118 | + // I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a |
|
| 119 | + // unique key - but meh. |
|
| 120 | + return $results[0] != 0; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the |
|
| 125 | + * idcache table. Meant to be called periodically by a maintenance script. |
|
| 126 | + * |
|
| 127 | + * @param SiteConfiguration $siteConfiguration |
|
| 128 | + * @param PdoDatabase $dbObject |
|
| 129 | + * |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
| 133 | + { |
|
| 134 | + $interval = $siteConfiguration->getIdentificationCacheExpiry(); |
|
| 135 | + |
|
| 136 | + $query = <<<SQL |
|
| 137 | 137 | DELETE FROM `idcache` |
| 138 | 138 | WHERE DATE_ADD(`checktime`, INTERVAL {$interval}) < NOW(); |
| 139 | 139 | SQL; |
| 140 | - $dbObject->prepare($query)->execute(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified. This |
|
| 145 | - * is so we don't have to hit the API every single time we check. The cache entry is valid for as long as specified |
|
| 146 | - * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()). |
|
| 147 | - * |
|
| 148 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 149 | - * |
|
| 150 | - * @return void |
|
| 151 | - * @category Security-Critical |
|
| 152 | - */ |
|
| 153 | - private function cacheIdentificationStatus($onWikiName) |
|
| 154 | - { |
|
| 155 | - $query = <<<SQL |
|
| 140 | + $dbObject->prepare($query)->execute(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified. This |
|
| 145 | + * is so we don't have to hit the API every single time we check. The cache entry is valid for as long as specified |
|
| 146 | + * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()). |
|
| 147 | + * |
|
| 148 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 149 | + * |
|
| 150 | + * @return void |
|
| 151 | + * @category Security-Critical |
|
| 152 | + */ |
|
| 153 | + private function cacheIdentificationStatus($onWikiName) |
|
| 154 | + { |
|
| 155 | + $query = <<<SQL |
|
| 156 | 156 | INSERT INTO `idcache` |
| 157 | 157 | (`onwikiusername`) |
| 158 | 158 | VALUES |
@@ -161,45 +161,45 @@ discard block |
||
| 161 | 161 | `onwikiusername` = VALUES(`onwikiusername`), |
| 162 | 162 | `checktime` = CURRENT_TIMESTAMP; |
| 163 | 163 | SQL; |
| 164 | - $stmt = $this->dbObject->prepare($query); |
|
| 165 | - $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
| 166 | - $stmt->execute(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard. |
|
| 171 | - * |
|
| 172 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 173 | - * |
|
| 174 | - * @return bool |
|
| 175 | - * @throws EnvironmentException |
|
| 176 | - * @category Security-Critical |
|
| 177 | - */ |
|
| 178 | - private function isIdentifiedOnWiki($onWikiName) |
|
| 179 | - { |
|
| 180 | - $strings = new StringFunctions(); |
|
| 181 | - |
|
| 182 | - // First character of Wikipedia usernames is always capitalized. |
|
| 183 | - $onWikiName = $strings->upperCaseFirst($onWikiName); |
|
| 184 | - |
|
| 185 | - $parameters = self::$apiQueryParameters; |
|
| 186 | - $parameters['pltitles'] = "User:" . $onWikiName; |
|
| 187 | - $parameters['titles'] = $this->siteConfiguration->getIdentificationNoticeboardPage(); |
|
| 188 | - |
|
| 189 | - try { |
|
| 190 | - $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
|
| 191 | - $response = $this->httpHelper->get($endpoint, $parameters); |
|
| 192 | - $response = json_decode($response, true); |
|
| 193 | - } catch (CurlException $ex) { |
|
| 194 | - // failed getting identification status, so throw a nicer error. |
|
| 195 | - $message = 'Could not contact metawiki API to determine user\' identification status. ' |
|
| 196 | - . 'This is probably a transient error, so please try again.'; |
|
| 197 | - |
|
| 198 | - throw new EnvironmentException($message); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $page = @array_pop($response['query']['pages']); |
|
| 202 | - |
|
| 203 | - return @$page['links'][0]['title'] === "User:" . $onWikiName; |
|
| 204 | - } |
|
| 164 | + $stmt = $this->dbObject->prepare($query); |
|
| 165 | + $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
| 166 | + $stmt->execute(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard. |
|
| 171 | + * |
|
| 172 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 173 | + * |
|
| 174 | + * @return bool |
|
| 175 | + * @throws EnvironmentException |
|
| 176 | + * @category Security-Critical |
|
| 177 | + */ |
|
| 178 | + private function isIdentifiedOnWiki($onWikiName) |
|
| 179 | + { |
|
| 180 | + $strings = new StringFunctions(); |
|
| 181 | + |
|
| 182 | + // First character of Wikipedia usernames is always capitalized. |
|
| 183 | + $onWikiName = $strings->upperCaseFirst($onWikiName); |
|
| 184 | + |
|
| 185 | + $parameters = self::$apiQueryParameters; |
|
| 186 | + $parameters['pltitles'] = "User:" . $onWikiName; |
|
| 187 | + $parameters['titles'] = $this->siteConfiguration->getIdentificationNoticeboardPage(); |
|
| 188 | + |
|
| 189 | + try { |
|
| 190 | + $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
|
| 191 | + $response = $this->httpHelper->get($endpoint, $parameters); |
|
| 192 | + $response = json_decode($response, true); |
|
| 193 | + } catch (CurlException $ex) { |
|
| 194 | + // failed getting identification status, so throw a nicer error. |
|
| 195 | + $message = 'Could not contact metawiki API to determine user\' identification status. ' |
|
| 196 | + . 'This is probably a transient error, so please try again.'; |
|
| 197 | + |
|
| 198 | + throw new EnvironmentException($message); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $page = @array_pop($response['query']['pages']); |
|
| 202 | + |
|
| 203 | + return @$page['links'][0]['title'] === "User:" . $onWikiName; |
|
| 204 | + } |
|
| 205 | 205 | } |
@@ -77,14 +77,12 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | if ($this->checkIdentificationCache($onWikiName)) { |
| 79 | 79 | return true; |
| 80 | - } |
|
| 81 | - else { |
|
| 80 | + } else { |
|
| 82 | 81 | if ($this->isIdentifiedOnWiki($onWikiName)) { |
| 83 | 82 | $this->cacheIdentificationStatus($onWikiName); |
| 84 | 83 | |
| 85 | 84 | return true; |
| 86 | - } |
|
| 87 | - else { |
|
| 85 | + } else { |
|
| 88 | 86 | return false; |
| 89 | 87 | } |
| 90 | 88 | } |
@@ -190,7 +188,8 @@ discard block |
||
| 190 | 188 | $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
| 191 | 189 | $response = $this->httpHelper->get($endpoint, $parameters); |
| 192 | 190 | $response = json_decode($response, true); |
| 193 | - } catch (CurlException $ex) { |
|
| 191 | + } |
|
| 192 | + catch (CurlException $ex) { |
|
| 194 | 193 | // failed getting identification status, so throw a nicer error. |
| 195 | 194 | $message = 'Could not contact metawiki API to determine user\' identification status. ' |
| 196 | 195 | . 'This is probably a transient error, so please try again.'; |
@@ -21,141 +21,141 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class SessionAlert |
| 23 | 23 | { |
| 24 | - private $message; |
|
| 25 | - private $title; |
|
| 26 | - private $type; |
|
| 27 | - private $closable; |
|
| 28 | - private $block; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param string $message |
|
| 32 | - * @param string $title |
|
| 33 | - * @param string $type |
|
| 34 | - * @param bool $closable |
|
| 35 | - * @param bool $block |
|
| 36 | - */ |
|
| 37 | - public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
| 38 | - { |
|
| 39 | - $this->message = $message; |
|
| 40 | - $this->title = $title; |
|
| 41 | - $this->type = $type; |
|
| 42 | - $this->closable = $closable; |
|
| 43 | - $this->block = $block; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Shows a quick one-liner message |
|
| 48 | - * |
|
| 49 | - * @param string $message |
|
| 50 | - * @param string $type |
|
| 51 | - */ |
|
| 52 | - public static function quick($message, $type = "alert-info") |
|
| 53 | - { |
|
| 54 | - self::append(new SessionAlert($message, "", $type, true, false)); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param SessionAlert $alert |
|
| 59 | - */ |
|
| 60 | - public static function append(SessionAlert $alert) |
|
| 61 | - { |
|
| 62 | - $data = WebRequest::getSessionAlertData(); |
|
| 63 | - $data[] = serialize($alert); |
|
| 64 | - WebRequest::setSessionAlertData($data); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Shows a quick one-liner success message |
|
| 69 | - * |
|
| 70 | - * @param string $message |
|
| 71 | - */ |
|
| 72 | - public static function success($message) |
|
| 73 | - { |
|
| 74 | - self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Shows a quick one-liner warning message |
|
| 79 | - * |
|
| 80 | - * @param string $message |
|
| 81 | - * @param string $title |
|
| 82 | - */ |
|
| 83 | - public static function warning($message, $title = "Warning!") |
|
| 84 | - { |
|
| 85 | - self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Shows a quick one-liner error message |
|
| 90 | - * |
|
| 91 | - * @param string $message |
|
| 92 | - * @param string $title |
|
| 93 | - */ |
|
| 94 | - public static function error($message, $title = "Error!") |
|
| 95 | - { |
|
| 96 | - self::append(new SessionAlert($message, $title, "alert-danger", true, true)); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Retrieves the alerts which have been saved to the session |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - public static function getAlerts() |
|
| 104 | - { |
|
| 105 | - $alertData = array(); |
|
| 106 | - |
|
| 107 | - foreach (WebRequest::getSessionAlertData() as $a) { |
|
| 108 | - $alertData[] = unserialize($a); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $alertData; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Clears the alerts from the session |
|
| 116 | - */ |
|
| 117 | - public static function clearAlerts() |
|
| 118 | - { |
|
| 119 | - WebRequest::clearSessionAlertData(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return boolean |
|
| 124 | - */ |
|
| 125 | - public function isBlock() |
|
| 126 | - { |
|
| 127 | - return $this->block; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return boolean |
|
| 132 | - */ |
|
| 133 | - public function isClosable() |
|
| 134 | - { |
|
| 135 | - return $this->closable; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function getType() |
|
| 142 | - { |
|
| 143 | - return $this->type; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function getTitle() |
|
| 150 | - { |
|
| 151 | - return $this->title; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function getMessage() |
|
| 158 | - { |
|
| 159 | - return $this->message; |
|
| 160 | - } |
|
| 24 | + private $message; |
|
| 25 | + private $title; |
|
| 26 | + private $type; |
|
| 27 | + private $closable; |
|
| 28 | + private $block; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param string $message |
|
| 32 | + * @param string $title |
|
| 33 | + * @param string $type |
|
| 34 | + * @param bool $closable |
|
| 35 | + * @param bool $block |
|
| 36 | + */ |
|
| 37 | + public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
| 38 | + { |
|
| 39 | + $this->message = $message; |
|
| 40 | + $this->title = $title; |
|
| 41 | + $this->type = $type; |
|
| 42 | + $this->closable = $closable; |
|
| 43 | + $this->block = $block; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Shows a quick one-liner message |
|
| 48 | + * |
|
| 49 | + * @param string $message |
|
| 50 | + * @param string $type |
|
| 51 | + */ |
|
| 52 | + public static function quick($message, $type = "alert-info") |
|
| 53 | + { |
|
| 54 | + self::append(new SessionAlert($message, "", $type, true, false)); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param SessionAlert $alert |
|
| 59 | + */ |
|
| 60 | + public static function append(SessionAlert $alert) |
|
| 61 | + { |
|
| 62 | + $data = WebRequest::getSessionAlertData(); |
|
| 63 | + $data[] = serialize($alert); |
|
| 64 | + WebRequest::setSessionAlertData($data); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Shows a quick one-liner success message |
|
| 69 | + * |
|
| 70 | + * @param string $message |
|
| 71 | + */ |
|
| 72 | + public static function success($message) |
|
| 73 | + { |
|
| 74 | + self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Shows a quick one-liner warning message |
|
| 79 | + * |
|
| 80 | + * @param string $message |
|
| 81 | + * @param string $title |
|
| 82 | + */ |
|
| 83 | + public static function warning($message, $title = "Warning!") |
|
| 84 | + { |
|
| 85 | + self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Shows a quick one-liner error message |
|
| 90 | + * |
|
| 91 | + * @param string $message |
|
| 92 | + * @param string $title |
|
| 93 | + */ |
|
| 94 | + public static function error($message, $title = "Error!") |
|
| 95 | + { |
|
| 96 | + self::append(new SessionAlert($message, $title, "alert-danger", true, true)); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Retrieves the alerts which have been saved to the session |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + public static function getAlerts() |
|
| 104 | + { |
|
| 105 | + $alertData = array(); |
|
| 106 | + |
|
| 107 | + foreach (WebRequest::getSessionAlertData() as $a) { |
|
| 108 | + $alertData[] = unserialize($a); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $alertData; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Clears the alerts from the session |
|
| 116 | + */ |
|
| 117 | + public static function clearAlerts() |
|
| 118 | + { |
|
| 119 | + WebRequest::clearSessionAlertData(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return boolean |
|
| 124 | + */ |
|
| 125 | + public function isBlock() |
|
| 126 | + { |
|
| 127 | + return $this->block; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return boolean |
|
| 132 | + */ |
|
| 133 | + public function isClosable() |
|
| 134 | + { |
|
| 135 | + return $this->closable; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function getType() |
|
| 142 | + { |
|
| 143 | + return $this->type; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function getTitle() |
|
| 150 | + { |
|
| 151 | + return $this->title; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function getMessage() |
|
| 158 | + { |
|
| 159 | + return $this->message; |
|
| 160 | + } |
|
| 161 | 161 | } |
@@ -16,14 +16,14 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class RequestList |
| 18 | 18 | { |
| 19 | - public $requests; |
|
| 20 | - public $showPrivateData; |
|
| 21 | - public $dataClearEmail; |
|
| 22 | - public $dataClearIp; |
|
| 23 | - public $relatedEmailRequests; |
|
| 24 | - public $relatedIpRequests; |
|
| 25 | - public $requestTrustedIp; |
|
| 26 | - public $canBan; |
|
| 27 | - public $canBreakReservation; |
|
| 28 | - public $userList; |
|
| 19 | + public $requests; |
|
| 20 | + public $showPrivateData; |
|
| 21 | + public $dataClearEmail; |
|
| 22 | + public $dataClearIp; |
|
| 23 | + public $relatedEmailRequests; |
|
| 24 | + public $relatedIpRequests; |
|
| 25 | + public $requestTrustedIp; |
|
| 26 | + public $canBan; |
|
| 27 | + public $canBreakReservation; |
|
| 28 | + public $userList; |
|
| 29 | 29 | } |
@@ -22,49 +22,49 @@ |
||
| 22 | 22 | |
| 23 | 23 | class ApiRequestRouter implements IRequestRouter |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @return string[] |
|
| 27 | - */ |
|
| 28 | - public static function getActionList() |
|
| 29 | - { |
|
| 30 | - return array("count", "status", "stats", "help", "monitor"); |
|
| 31 | - } |
|
| 25 | + /** |
|
| 26 | + * @return string[] |
|
| 27 | + */ |
|
| 28 | + public static function getActionList() |
|
| 29 | + { |
|
| 30 | + return array("count", "status", "stats", "help", "monitor"); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @return IRoutedTask |
|
| 35 | - * @throws Exception |
|
| 36 | - */ |
|
| 37 | - public function route() |
|
| 38 | - { |
|
| 39 | - $requestAction = WebRequest::getString('action'); |
|
| 33 | + /** |
|
| 34 | + * @return IRoutedTask |
|
| 35 | + * @throws Exception |
|
| 36 | + */ |
|
| 37 | + public function route() |
|
| 38 | + { |
|
| 39 | + $requestAction = WebRequest::getString('action'); |
|
| 40 | 40 | |
| 41 | - switch ($requestAction) { |
|
| 42 | - case "count": |
|
| 43 | - $result = new CountAction(); |
|
| 44 | - break; |
|
| 45 | - case "status": |
|
| 46 | - $result = new StatusAction(); |
|
| 47 | - break; |
|
| 48 | - case "stats": |
|
| 49 | - $result = new StatsAction(); |
|
| 50 | - break; |
|
| 51 | - case "help": |
|
| 52 | - $result = new HelpAction(); |
|
| 53 | - break; |
|
| 54 | - case "monitor": |
|
| 55 | - $result = new MonitorAction(); |
|
| 56 | - break; |
|
| 57 | - case "users": |
|
| 58 | - $result = new JsUsersAction(); |
|
| 59 | - break; |
|
| 60 | - case "templates": |
|
| 61 | - $result = new JsTemplateConfirmsAction(); |
|
| 62 | - break; |
|
| 63 | - default: |
|
| 64 | - $result = new UnknownAction(); |
|
| 65 | - break; |
|
| 66 | - } |
|
| 41 | + switch ($requestAction) { |
|
| 42 | + case "count": |
|
| 43 | + $result = new CountAction(); |
|
| 44 | + break; |
|
| 45 | + case "status": |
|
| 46 | + $result = new StatusAction(); |
|
| 47 | + break; |
|
| 48 | + case "stats": |
|
| 49 | + $result = new StatsAction(); |
|
| 50 | + break; |
|
| 51 | + case "help": |
|
| 52 | + $result = new HelpAction(); |
|
| 53 | + break; |
|
| 54 | + case "monitor": |
|
| 55 | + $result = new MonitorAction(); |
|
| 56 | + break; |
|
| 57 | + case "users": |
|
| 58 | + $result = new JsUsersAction(); |
|
| 59 | + break; |
|
| 60 | + case "templates": |
|
| 61 | + $result = new JsTemplateConfirmsAction(); |
|
| 62 | + break; |
|
| 63 | + default: |
|
| 64 | + $result = new UnknownAction(); |
|
| 65 | + break; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return $result; |
|
| 69 | - } |
|
| 68 | + return $result; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class OAuthRequestRouter extends RequestRouter |
| 19 | 19 | { |
| 20 | - protected function getRouteFromPath($pathInfo) |
|
| 21 | - { |
|
| 22 | - // Hardcode the route for this entry point |
|
| 23 | - return array(PageOAuthCallback::class, 'authorise'); |
|
| 24 | - } |
|
| 20 | + protected function getRouteFromPath($pathInfo) |
|
| 21 | + { |
|
| 22 | + // Hardcode the route for this entry point |
|
| 23 | + return array(PageOAuthCallback::class, 'authorise'); |
|
| 24 | + } |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -16,51 +16,51 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | class OAuthIdentity extends DataObject |
| 18 | 18 | { |
| 19 | - #region Fields |
|
| 20 | - /** @var int */ |
|
| 21 | - private $user; |
|
| 22 | - /** @var string */ |
|
| 23 | - private $iss; |
|
| 24 | - /** @var int */ |
|
| 25 | - private $sub; |
|
| 26 | - /** @var string */ |
|
| 27 | - private $aud; |
|
| 28 | - /** @var int */ |
|
| 29 | - private $exp; |
|
| 30 | - /** @var int */ |
|
| 31 | - private $iat; |
|
| 32 | - /** @var string */ |
|
| 33 | - private $username; |
|
| 34 | - /** @var int */ |
|
| 35 | - private $editcount; |
|
| 36 | - /** @var int */ |
|
| 37 | - private $confirmed_email; |
|
| 38 | - /** @var int */ |
|
| 39 | - private $blocked; |
|
| 40 | - /** @var string */ |
|
| 41 | - private $registered; |
|
| 42 | - /** @var int */ |
|
| 43 | - private $checkuser; |
|
| 44 | - /** @var int */ |
|
| 45 | - private $grantbasic; |
|
| 46 | - /** @var int */ |
|
| 47 | - private $grantcreateaccount; |
|
| 48 | - /** @var int */ |
|
| 49 | - private $granthighvolume; |
|
| 50 | - /** @var int */ |
|
| 51 | - private $grantcreateeditmovepage; |
|
| 52 | - #endregion |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Saves a data object to the database, either updating or inserting a record. |
|
| 56 | - * @return void |
|
| 57 | - * @throws Exception |
|
| 58 | - * @throws OptimisticLockFailedException |
|
| 59 | - */ |
|
| 60 | - public function save() |
|
| 61 | - { |
|
| 62 | - if ($this->isNew()) { |
|
| 63 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 19 | + #region Fields |
|
| 20 | + /** @var int */ |
|
| 21 | + private $user; |
|
| 22 | + /** @var string */ |
|
| 23 | + private $iss; |
|
| 24 | + /** @var int */ |
|
| 25 | + private $sub; |
|
| 26 | + /** @var string */ |
|
| 27 | + private $aud; |
|
| 28 | + /** @var int */ |
|
| 29 | + private $exp; |
|
| 30 | + /** @var int */ |
|
| 31 | + private $iat; |
|
| 32 | + /** @var string */ |
|
| 33 | + private $username; |
|
| 34 | + /** @var int */ |
|
| 35 | + private $editcount; |
|
| 36 | + /** @var int */ |
|
| 37 | + private $confirmed_email; |
|
| 38 | + /** @var int */ |
|
| 39 | + private $blocked; |
|
| 40 | + /** @var string */ |
|
| 41 | + private $registered; |
|
| 42 | + /** @var int */ |
|
| 43 | + private $checkuser; |
|
| 44 | + /** @var int */ |
|
| 45 | + private $grantbasic; |
|
| 46 | + /** @var int */ |
|
| 47 | + private $grantcreateaccount; |
|
| 48 | + /** @var int */ |
|
| 49 | + private $granthighvolume; |
|
| 50 | + /** @var int */ |
|
| 51 | + private $grantcreateeditmovepage; |
|
| 52 | + #endregion |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Saves a data object to the database, either updating or inserting a record. |
|
| 56 | + * @return void |
|
| 57 | + * @throws Exception |
|
| 58 | + * @throws OptimisticLockFailedException |
|
| 59 | + */ |
|
| 60 | + public function save() |
|
| 61 | + { |
|
| 62 | + if ($this->isNew()) { |
|
| 63 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 64 | 64 | INSERT INTO oauthidentity ( |
| 65 | 65 | user, iss, sub, aud, exp, iat, username, editcount, confirmed_email, blocked, registered, checkuser, |
| 66 | 66 | grantbasic, grantcreateaccount, granthighvolume, grantcreateeditmovepage |
@@ -69,34 +69,34 @@ discard block |
||
| 69 | 69 | :checkuser, :grantbasic, :grantcreateaccount, :granthighvolume, :grantcreateeditmovepage |
| 70 | 70 | ) |
| 71 | 71 | SQL |
| 72 | - ); |
|
| 73 | - |
|
| 74 | - $statement->bindValue(':user', $this->user); |
|
| 75 | - $statement->bindValue(':iss', $this->iss); |
|
| 76 | - $statement->bindValue(':sub', $this->sub); |
|
| 77 | - $statement->bindValue(':aud', $this->aud); |
|
| 78 | - $statement->bindValue(':exp', $this->exp); |
|
| 79 | - $statement->bindValue(':iat', $this->iat); |
|
| 80 | - $statement->bindValue(':username', $this->username); |
|
| 81 | - $statement->bindValue(':editcount', $this->editcount); |
|
| 82 | - $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
| 83 | - $statement->bindValue(':blocked', $this->blocked); |
|
| 84 | - $statement->bindValue(':registered', $this->registered); |
|
| 85 | - $statement->bindValue(':checkuser', $this->checkuser); |
|
| 86 | - $statement->bindValue(':grantbasic', $this->grantbasic); |
|
| 87 | - $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
| 88 | - $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
| 89 | - $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
| 90 | - |
|
| 91 | - if ($statement->execute()) { |
|
| 92 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 93 | - } |
|
| 94 | - else { |
|
| 95 | - throw new Exception($statement->errorInfo()); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - else { |
|
| 99 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 72 | + ); |
|
| 73 | + |
|
| 74 | + $statement->bindValue(':user', $this->user); |
|
| 75 | + $statement->bindValue(':iss', $this->iss); |
|
| 76 | + $statement->bindValue(':sub', $this->sub); |
|
| 77 | + $statement->bindValue(':aud', $this->aud); |
|
| 78 | + $statement->bindValue(':exp', $this->exp); |
|
| 79 | + $statement->bindValue(':iat', $this->iat); |
|
| 80 | + $statement->bindValue(':username', $this->username); |
|
| 81 | + $statement->bindValue(':editcount', $this->editcount); |
|
| 82 | + $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
| 83 | + $statement->bindValue(':blocked', $this->blocked); |
|
| 84 | + $statement->bindValue(':registered', $this->registered); |
|
| 85 | + $statement->bindValue(':checkuser', $this->checkuser); |
|
| 86 | + $statement->bindValue(':grantbasic', $this->grantbasic); |
|
| 87 | + $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
| 88 | + $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
| 89 | + $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
| 90 | + |
|
| 91 | + if ($statement->execute()) { |
|
| 92 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 93 | + } |
|
| 94 | + else { |
|
| 95 | + throw new Exception($statement->errorInfo()); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + else { |
|
| 99 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 100 | 100 | UPDATE oauthidentity SET |
| 101 | 101 | iss = :iss |
| 102 | 102 | , sub = :sub |
@@ -116,211 +116,211 @@ discard block |
||
| 116 | 116 | , updateversion = updateversion + 1 |
| 117 | 117 | WHERE id = :id AND updateversion = :updateversion |
| 118 | 118 | SQL |
| 119 | - ); |
|
| 120 | - |
|
| 121 | - $statement->bindValue(':iss', $this->iss); |
|
| 122 | - $statement->bindValue(':sub', $this->sub); |
|
| 123 | - $statement->bindValue(':aud', $this->aud); |
|
| 124 | - $statement->bindValue(':exp', $this->exp); |
|
| 125 | - $statement->bindValue(':iat', $this->iat); |
|
| 126 | - $statement->bindValue(':username', $this->username); |
|
| 127 | - $statement->bindValue(':editcount', $this->editcount); |
|
| 128 | - $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
| 129 | - $statement->bindValue(':blocked', $this->blocked); |
|
| 130 | - $statement->bindValue(':registered', $this->registered); |
|
| 131 | - $statement->bindValue(':checkuser', $this->checkuser); |
|
| 132 | - $statement->bindValue(':grantbasic', $this->grantbasic); |
|
| 133 | - $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
| 134 | - $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
| 135 | - $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
| 136 | - |
|
| 137 | - $statement->bindValue(':id', $this->id); |
|
| 138 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 139 | - |
|
| 140 | - if (!$statement->execute()) { |
|
| 141 | - throw new Exception($statement->errorInfo()); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ($statement->rowCount() !== 1) { |
|
| 145 | - throw new OptimisticLockFailedException(); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $this->updateversion++; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - #region Properties |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return int |
|
| 156 | - */ |
|
| 157 | - public function getUserId() |
|
| 158 | - { |
|
| 159 | - return $this->user; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param int $user |
|
| 164 | - */ |
|
| 165 | - public function setUserId($user) |
|
| 166 | - { |
|
| 167 | - $this->user = $user; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 173 | - public function getIssuer() |
|
| 174 | - { |
|
| 175 | - return $this->iss; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return int |
|
| 180 | - */ |
|
| 181 | - public function getSubject() |
|
| 182 | - { |
|
| 183 | - return $this->sub; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function getAudience() |
|
| 190 | - { |
|
| 191 | - return $this->aud; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @return int |
|
| 196 | - */ |
|
| 197 | - public function getExpirationTime() |
|
| 198 | - { |
|
| 199 | - return $this->exp; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @return int |
|
| 204 | - */ |
|
| 205 | - public function getIssuedAtTime() |
|
| 206 | - { |
|
| 207 | - return $this->iat; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @return string |
|
| 212 | - */ |
|
| 213 | - public function getUsername() |
|
| 214 | - { |
|
| 215 | - return $this->username; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * @return int |
|
| 220 | - */ |
|
| 221 | - public function getEditCount() |
|
| 222 | - { |
|
| 223 | - return $this->editcount; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return bool |
|
| 228 | - */ |
|
| 229 | - public function getConfirmedEmail() |
|
| 230 | - { |
|
| 231 | - return $this->confirmed_email == 1; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @return bool |
|
| 236 | - */ |
|
| 237 | - public function getBlocked() |
|
| 238 | - { |
|
| 239 | - return $this->blocked == 1; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function getRegistered() |
|
| 246 | - { |
|
| 247 | - return $this->registered; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function getRegistrationDate() |
|
| 251 | - { |
|
| 252 | - return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r'); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - public function getAccountAge() |
|
| 256 | - { |
|
| 257 | - $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered); |
|
| 258 | - $interval = $regDate->diff(new DateTimeImmutable(), true); |
|
| 259 | - |
|
| 260 | - return $interval->days; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @return bool |
|
| 265 | - */ |
|
| 266 | - public function getCheckuser() |
|
| 267 | - { |
|
| 268 | - return $this->checkuser == 1; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @return bool |
|
| 273 | - */ |
|
| 274 | - public function getGrantBasic() |
|
| 275 | - { |
|
| 276 | - return $this->grantbasic == 1; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @return bool |
|
| 281 | - */ |
|
| 282 | - public function getGrantCreateAccount() |
|
| 283 | - { |
|
| 284 | - return $this->grantcreateaccount == 1; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @return bool |
|
| 289 | - */ |
|
| 290 | - public function getGrantHighVolume() |
|
| 291 | - { |
|
| 292 | - return $this->granthighvolume == 1; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @return bool |
|
| 297 | - */ |
|
| 298 | - public function getGrantCreateEditMovePage() |
|
| 299 | - { |
|
| 300 | - return $this->grantcreateeditmovepage == 1; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - #endregion Properties |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Populates the fields of this instance from a provided JSON Web Token |
|
| 307 | - * |
|
| 308 | - * @param stdClass $jwt |
|
| 309 | - */ |
|
| 310 | - public function populate($jwt) |
|
| 311 | - { |
|
| 312 | - $this->iss = $jwt->iss; |
|
| 313 | - $this->sub = $jwt->sub; |
|
| 314 | - $this->aud = $jwt->aud; |
|
| 315 | - $this->exp = $jwt->exp; |
|
| 316 | - $this->iat = $jwt->iat; |
|
| 317 | - $this->username = $jwt->username; |
|
| 318 | - $this->editcount = $jwt->editcount; |
|
| 319 | - $this->confirmed_email = $jwt->confirmed_email ? 1 : 0; |
|
| 320 | - $this->blocked = $jwt->blocked ? 1 : 0; |
|
| 321 | - $this->registered = $jwt->registered; |
|
| 322 | - |
|
| 323 | - /* |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + $statement->bindValue(':iss', $this->iss); |
|
| 122 | + $statement->bindValue(':sub', $this->sub); |
|
| 123 | + $statement->bindValue(':aud', $this->aud); |
|
| 124 | + $statement->bindValue(':exp', $this->exp); |
|
| 125 | + $statement->bindValue(':iat', $this->iat); |
|
| 126 | + $statement->bindValue(':username', $this->username); |
|
| 127 | + $statement->bindValue(':editcount', $this->editcount); |
|
| 128 | + $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
| 129 | + $statement->bindValue(':blocked', $this->blocked); |
|
| 130 | + $statement->bindValue(':registered', $this->registered); |
|
| 131 | + $statement->bindValue(':checkuser', $this->checkuser); |
|
| 132 | + $statement->bindValue(':grantbasic', $this->grantbasic); |
|
| 133 | + $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
| 134 | + $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
| 135 | + $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
| 136 | + |
|
| 137 | + $statement->bindValue(':id', $this->id); |
|
| 138 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 139 | + |
|
| 140 | + if (!$statement->execute()) { |
|
| 141 | + throw new Exception($statement->errorInfo()); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ($statement->rowCount() !== 1) { |
|
| 145 | + throw new OptimisticLockFailedException(); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $this->updateversion++; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + #region Properties |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return int |
|
| 156 | + */ |
|
| 157 | + public function getUserId() |
|
| 158 | + { |
|
| 159 | + return $this->user; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param int $user |
|
| 164 | + */ |
|
| 165 | + public function setUserId($user) |
|
| 166 | + { |
|
| 167 | + $this->user = $user; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | + public function getIssuer() |
|
| 174 | + { |
|
| 175 | + return $this->iss; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return int |
|
| 180 | + */ |
|
| 181 | + public function getSubject() |
|
| 182 | + { |
|
| 183 | + return $this->sub; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function getAudience() |
|
| 190 | + { |
|
| 191 | + return $this->aud; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @return int |
|
| 196 | + */ |
|
| 197 | + public function getExpirationTime() |
|
| 198 | + { |
|
| 199 | + return $this->exp; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @return int |
|
| 204 | + */ |
|
| 205 | + public function getIssuedAtTime() |
|
| 206 | + { |
|
| 207 | + return $this->iat; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @return string |
|
| 212 | + */ |
|
| 213 | + public function getUsername() |
|
| 214 | + { |
|
| 215 | + return $this->username; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @return int |
|
| 220 | + */ |
|
| 221 | + public function getEditCount() |
|
| 222 | + { |
|
| 223 | + return $this->editcount; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return bool |
|
| 228 | + */ |
|
| 229 | + public function getConfirmedEmail() |
|
| 230 | + { |
|
| 231 | + return $this->confirmed_email == 1; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @return bool |
|
| 236 | + */ |
|
| 237 | + public function getBlocked() |
|
| 238 | + { |
|
| 239 | + return $this->blocked == 1; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function getRegistered() |
|
| 246 | + { |
|
| 247 | + return $this->registered; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function getRegistrationDate() |
|
| 251 | + { |
|
| 252 | + return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r'); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + public function getAccountAge() |
|
| 256 | + { |
|
| 257 | + $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered); |
|
| 258 | + $interval = $regDate->diff(new DateTimeImmutable(), true); |
|
| 259 | + |
|
| 260 | + return $interval->days; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * @return bool |
|
| 265 | + */ |
|
| 266 | + public function getCheckuser() |
|
| 267 | + { |
|
| 268 | + return $this->checkuser == 1; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @return bool |
|
| 273 | + */ |
|
| 274 | + public function getGrantBasic() |
|
| 275 | + { |
|
| 276 | + return $this->grantbasic == 1; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @return bool |
|
| 281 | + */ |
|
| 282 | + public function getGrantCreateAccount() |
|
| 283 | + { |
|
| 284 | + return $this->grantcreateaccount == 1; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @return bool |
|
| 289 | + */ |
|
| 290 | + public function getGrantHighVolume() |
|
| 291 | + { |
|
| 292 | + return $this->granthighvolume == 1; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @return bool |
|
| 297 | + */ |
|
| 298 | + public function getGrantCreateEditMovePage() |
|
| 299 | + { |
|
| 300 | + return $this->grantcreateeditmovepage == 1; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + #endregion Properties |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Populates the fields of this instance from a provided JSON Web Token |
|
| 307 | + * |
|
| 308 | + * @param stdClass $jwt |
|
| 309 | + */ |
|
| 310 | + public function populate($jwt) |
|
| 311 | + { |
|
| 312 | + $this->iss = $jwt->iss; |
|
| 313 | + $this->sub = $jwt->sub; |
|
| 314 | + $this->aud = $jwt->aud; |
|
| 315 | + $this->exp = $jwt->exp; |
|
| 316 | + $this->iat = $jwt->iat; |
|
| 317 | + $this->username = $jwt->username; |
|
| 318 | + $this->editcount = $jwt->editcount; |
|
| 319 | + $this->confirmed_email = $jwt->confirmed_email ? 1 : 0; |
|
| 320 | + $this->blocked = $jwt->blocked ? 1 : 0; |
|
| 321 | + $this->registered = $jwt->registered; |
|
| 322 | + |
|
| 323 | + /* |
|
| 324 | 324 | * Rights we need: |
| 325 | 325 | * Account creation |
| 326 | 326 | * createaccount => createaccount |
@@ -342,11 +342,11 @@ discard block |
||
| 342 | 342 | * Any antispoof conflicts will still have to be resolved manually using the normal creation form. |
| 343 | 343 | */ |
| 344 | 344 | |
| 345 | - $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0; |
|
| 346 | - $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0; |
|
| 347 | - $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0; |
|
| 348 | - $this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0; |
|
| 345 | + $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0; |
|
| 346 | + $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0; |
|
| 347 | + $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0; |
|
| 348 | + $this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0; |
|
| 349 | 349 | |
| 350 | - $this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0; |
|
| 351 | - } |
|
| 350 | + $this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0; |
|
| 351 | + } |
|
| 352 | 352 | } |
@@ -90,12 +90,10 @@ |
||
| 90 | 90 | |
| 91 | 91 | if ($statement->execute()) { |
| 92 | 92 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 93 | - } |
|
| 94 | - else { |
|
| 93 | + } else { |
|
| 95 | 94 | throw new Exception($statement->errorInfo()); |
| 96 | 95 | } |
| 97 | - } |
|
| 98 | - else { |
|
| 96 | + } else { |
|
| 99 | 97 | $statement = $this->dbObject->prepare(<<<SQL |
| 100 | 98 | UPDATE oauthidentity SET |
| 101 | 99 | iss = :iss |