@@ -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 |
@@ -15,187 +15,187 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class Credential extends DataObject |
| 17 | 17 | { |
| 18 | - /** @var int */ |
|
| 19 | - private $user; |
|
| 20 | - /** @var int */ |
|
| 21 | - private $factor; |
|
| 22 | - /** @var string */ |
|
| 23 | - private $type; |
|
| 24 | - /** @var string */ |
|
| 25 | - private $data; |
|
| 26 | - /** @var int */ |
|
| 27 | - private $version; |
|
| 28 | - private $timeout; |
|
| 29 | - /** @var int */ |
|
| 30 | - private $disabled = 0; |
|
| 31 | - /** @var int */ |
|
| 32 | - private $priority; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return int |
|
| 36 | - */ |
|
| 37 | - public function getUserId() |
|
| 38 | - { |
|
| 39 | - return $this->user; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param int $user |
|
| 44 | - */ |
|
| 45 | - public function setUserId($user) |
|
| 46 | - { |
|
| 47 | - $this->user = $user; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return int |
|
| 52 | - */ |
|
| 53 | - public function getFactor() |
|
| 54 | - { |
|
| 55 | - return $this->factor; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param int $factor |
|
| 60 | - */ |
|
| 61 | - public function setFactor($factor) |
|
| 62 | - { |
|
| 63 | - $this->factor = $factor; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function getType() |
|
| 70 | - { |
|
| 71 | - return $this->type; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param string $type |
|
| 76 | - */ |
|
| 77 | - public function setType($type) |
|
| 78 | - { |
|
| 79 | - $this->type = $type; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function getData() |
|
| 86 | - { |
|
| 87 | - return $this->data; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param string $data |
|
| 92 | - */ |
|
| 93 | - public function setData($data) |
|
| 94 | - { |
|
| 95 | - $this->data = $data; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - public function getVersion() |
|
| 102 | - { |
|
| 103 | - return $this->version; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @param int $version |
|
| 108 | - */ |
|
| 109 | - public function setVersion($version) |
|
| 110 | - { |
|
| 111 | - $this->version = $version; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @return mixed |
|
| 116 | - */ |
|
| 117 | - public function getTimeout() |
|
| 118 | - { |
|
| 119 | - if ($this->timeout === null) { |
|
| 120 | - return null; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return new DateTimeImmutable($this->timeout); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param mixed $timeout |
|
| 128 | - */ |
|
| 129 | - public function setTimeout(DateTimeImmutable $timeout = null) |
|
| 130 | - { |
|
| 131 | - if ($timeout === null) { |
|
| 132 | - $this->timeout = null; |
|
| 133 | - } |
|
| 134 | - else { |
|
| 135 | - $this->timeout = $timeout->format('Y-m-d H:i:s'); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return int |
|
| 141 | - */ |
|
| 142 | - public function getDisabled() |
|
| 143 | - { |
|
| 144 | - return $this->disabled; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param int $disabled |
|
| 149 | - */ |
|
| 150 | - public function setDisabled($disabled) |
|
| 151 | - { |
|
| 152 | - $this->disabled = $disabled; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @return int |
|
| 157 | - */ |
|
| 158 | - public function getPriority() |
|
| 159 | - { |
|
| 160 | - return $this->priority; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param int $priority |
|
| 165 | - */ |
|
| 166 | - public function setPriority($priority) |
|
| 167 | - { |
|
| 168 | - $this->priority = $priority; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function save() |
|
| 172 | - { |
|
| 173 | - if ($this->isNew()) { |
|
| 174 | - // insert |
|
| 175 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 18 | + /** @var int */ |
|
| 19 | + private $user; |
|
| 20 | + /** @var int */ |
|
| 21 | + private $factor; |
|
| 22 | + /** @var string */ |
|
| 23 | + private $type; |
|
| 24 | + /** @var string */ |
|
| 25 | + private $data; |
|
| 26 | + /** @var int */ |
|
| 27 | + private $version; |
|
| 28 | + private $timeout; |
|
| 29 | + /** @var int */ |
|
| 30 | + private $disabled = 0; |
|
| 31 | + /** @var int */ |
|
| 32 | + private $priority; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return int |
|
| 36 | + */ |
|
| 37 | + public function getUserId() |
|
| 38 | + { |
|
| 39 | + return $this->user; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param int $user |
|
| 44 | + */ |
|
| 45 | + public function setUserId($user) |
|
| 46 | + { |
|
| 47 | + $this->user = $user; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return int |
|
| 52 | + */ |
|
| 53 | + public function getFactor() |
|
| 54 | + { |
|
| 55 | + return $this->factor; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param int $factor |
|
| 60 | + */ |
|
| 61 | + public function setFactor($factor) |
|
| 62 | + { |
|
| 63 | + $this->factor = $factor; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function getType() |
|
| 70 | + { |
|
| 71 | + return $this->type; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param string $type |
|
| 76 | + */ |
|
| 77 | + public function setType($type) |
|
| 78 | + { |
|
| 79 | + $this->type = $type; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function getData() |
|
| 86 | + { |
|
| 87 | + return $this->data; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param string $data |
|
| 92 | + */ |
|
| 93 | + public function setData($data) |
|
| 94 | + { |
|
| 95 | + $this->data = $data; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + public function getVersion() |
|
| 102 | + { |
|
| 103 | + return $this->version; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @param int $version |
|
| 108 | + */ |
|
| 109 | + public function setVersion($version) |
|
| 110 | + { |
|
| 111 | + $this->version = $version; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @return mixed |
|
| 116 | + */ |
|
| 117 | + public function getTimeout() |
|
| 118 | + { |
|
| 119 | + if ($this->timeout === null) { |
|
| 120 | + return null; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return new DateTimeImmutable($this->timeout); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param mixed $timeout |
|
| 128 | + */ |
|
| 129 | + public function setTimeout(DateTimeImmutable $timeout = null) |
|
| 130 | + { |
|
| 131 | + if ($timeout === null) { |
|
| 132 | + $this->timeout = null; |
|
| 133 | + } |
|
| 134 | + else { |
|
| 135 | + $this->timeout = $timeout->format('Y-m-d H:i:s'); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return int |
|
| 141 | + */ |
|
| 142 | + public function getDisabled() |
|
| 143 | + { |
|
| 144 | + return $this->disabled; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param int $disabled |
|
| 149 | + */ |
|
| 150 | + public function setDisabled($disabled) |
|
| 151 | + { |
|
| 152 | + $this->disabled = $disabled; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @return int |
|
| 157 | + */ |
|
| 158 | + public function getPriority() |
|
| 159 | + { |
|
| 160 | + return $this->priority; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param int $priority |
|
| 165 | + */ |
|
| 166 | + public function setPriority($priority) |
|
| 167 | + { |
|
| 168 | + $this->priority = $priority; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function save() |
|
| 172 | + { |
|
| 173 | + if ($this->isNew()) { |
|
| 174 | + // insert |
|
| 175 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 176 | 176 | INSERT INTO credential ( updateversion, user, factor, type, data, version, timeout, disabled, priority ) |
| 177 | 177 | VALUES ( 0, :user, :factor, :type, :data, :version, :timeout, :disabled, :priority ); |
| 178 | 178 | SQL |
| 179 | - ); |
|
| 180 | - $statement->bindValue(":user", $this->user); |
|
| 181 | - $statement->bindValue(":factor", $this->factor); |
|
| 182 | - $statement->bindValue(":type", $this->type); |
|
| 183 | - $statement->bindValue(":data", $this->data); |
|
| 184 | - $statement->bindValue(":version", $this->version); |
|
| 185 | - $statement->bindValue(":timeout", $this->timeout); |
|
| 186 | - $statement->bindValue(":disabled", $this->disabled); |
|
| 187 | - $statement->bindValue(":priority", $this->priority); |
|
| 188 | - |
|
| 189 | - if ($statement->execute()) { |
|
| 190 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 191 | - } |
|
| 192 | - else { |
|
| 193 | - throw new Exception($statement->errorInfo()); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - else { |
|
| 197 | - // update |
|
| 198 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 179 | + ); |
|
| 180 | + $statement->bindValue(":user", $this->user); |
|
| 181 | + $statement->bindValue(":factor", $this->factor); |
|
| 182 | + $statement->bindValue(":type", $this->type); |
|
| 183 | + $statement->bindValue(":data", $this->data); |
|
| 184 | + $statement->bindValue(":version", $this->version); |
|
| 185 | + $statement->bindValue(":timeout", $this->timeout); |
|
| 186 | + $statement->bindValue(":disabled", $this->disabled); |
|
| 187 | + $statement->bindValue(":priority", $this->priority); |
|
| 188 | + |
|
| 189 | + if ($statement->execute()) { |
|
| 190 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 191 | + } |
|
| 192 | + else { |
|
| 193 | + throw new Exception($statement->errorInfo()); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + else { |
|
| 197 | + // update |
|
| 198 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 199 | 199 | UPDATE credential |
| 200 | 200 | SET factor = :factor |
| 201 | 201 | , data = :data |
@@ -206,27 +206,27 @@ discard block |
||
| 206 | 206 | , updateversion = updateversion + 1 |
| 207 | 207 | WHERE id = :id AND updateversion = :updateversion; |
| 208 | 208 | SQL |
| 209 | - ); |
|
| 209 | + ); |
|
| 210 | 210 | |
| 211 | - $statement->bindValue(':id', $this->id); |
|
| 212 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 211 | + $statement->bindValue(':id', $this->id); |
|
| 212 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 213 | 213 | |
| 214 | - $statement->bindValue(":factor", $this->factor); |
|
| 215 | - $statement->bindValue(":data", $this->data); |
|
| 216 | - $statement->bindValue(":version", $this->version); |
|
| 217 | - $statement->bindValue(":timeout", $this->timeout); |
|
| 218 | - $statement->bindValue(":disabled", $this->disabled); |
|
| 219 | - $statement->bindValue(":priority", $this->priority); |
|
| 214 | + $statement->bindValue(":factor", $this->factor); |
|
| 215 | + $statement->bindValue(":data", $this->data); |
|
| 216 | + $statement->bindValue(":version", $this->version); |
|
| 217 | + $statement->bindValue(":timeout", $this->timeout); |
|
| 218 | + $statement->bindValue(":disabled", $this->disabled); |
|
| 219 | + $statement->bindValue(":priority", $this->priority); |
|
| 220 | 220 | |
| 221 | - if (!$statement->execute()) { |
|
| 222 | - throw new Exception($statement->errorInfo()); |
|
| 223 | - } |
|
| 221 | + if (!$statement->execute()) { |
|
| 222 | + throw new Exception($statement->errorInfo()); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - if ($statement->rowCount() !== 1) { |
|
| 226 | - throw new OptimisticLockFailedException(); |
|
| 227 | - } |
|
| 225 | + if ($statement->rowCount() !== 1) { |
|
| 226 | + throw new OptimisticLockFailedException(); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - $this->updateversion++; |
|
| 230 | - } |
|
| 231 | - } |
|
| 229 | + $this->updateversion++; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | } |
| 233 | 233 | \ No newline at end of file |
@@ -130,8 +130,7 @@ discard block |
||
| 130 | 130 | { |
| 131 | 131 | if ($timeout === null) { |
| 132 | 132 | $this->timeout = null; |
| 133 | - } |
|
| 134 | - else { |
|
| 133 | + } else { |
|
| 135 | 134 | $this->timeout = $timeout->format('Y-m-d H:i:s'); |
| 136 | 135 | } |
| 137 | 136 | } |
@@ -188,12 +187,10 @@ discard block |
||
| 188 | 187 | |
| 189 | 188 | if ($statement->execute()) { |
| 190 | 189 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 191 | - } |
|
| 192 | - else { |
|
| 190 | + } else { |
|
| 193 | 191 | throw new Exception($statement->errorInfo()); |
| 194 | 192 | } |
| 195 | - } |
|
| 196 | - else { |
|
| 193 | + } else { |
|
| 197 | 194 | // update |
| 198 | 195 | $statement = $this->dbObject->prepare(<<<SQL |
| 199 | 196 | UPDATE credential |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | class JobQueue extends DataObject |
| 19 | 19 | { |
| 20 | - /* |
|
| 20 | + /* |
|
| 21 | 21 | * Status workflow is this: |
| 22 | 22 | * |
| 23 | 23 | * 1) Ready. The job has been added to the queue |
@@ -26,78 +26,78 @@ discard block |
||
| 26 | 26 | * 3) Complete / Failed. The job has been processed |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | - const STATUS_READY = 'ready'; |
|
| 30 | - const STATUS_WAITING = 'waiting'; |
|
| 31 | - const STATUS_RUNNING = 'running'; |
|
| 32 | - const STATUS_COMPLETE = 'complete'; |
|
| 33 | - const STATUS_CANCELLED = 'cancelled'; |
|
| 34 | - const STATUS_FAILED = 'failed'; |
|
| 35 | - const STATUS_HELD = 'held'; |
|
| 36 | - |
|
| 37 | - /** @var string */ |
|
| 38 | - private $task; |
|
| 39 | - /** @var int */ |
|
| 40 | - private $user; |
|
| 41 | - /** @var int */ |
|
| 42 | - private $request; |
|
| 43 | - /** @var int */ |
|
| 44 | - private $emailtemplate; |
|
| 45 | - /** @var string */ |
|
| 46 | - private $status; |
|
| 47 | - /** @var string */ |
|
| 48 | - private $enqueue; |
|
| 49 | - /** @var string */ |
|
| 50 | - private $parameters; |
|
| 51 | - /** @var string */ |
|
| 52 | - private $error; |
|
| 53 | - /** @var int */ |
|
| 54 | - private $acknowledged; |
|
| 55 | - /** @var int */ |
|
| 56 | - private $parent; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * This feels like the least bad place to put this method. |
|
| 60 | - */ |
|
| 61 | - public static function getTaskDescriptions() { |
|
| 62 | - return array( |
|
| 63 | - BotCreationTask::class => 'Create account (via bot)', |
|
| 64 | - UserCreationTask::class => 'Create account (via OAuth)', |
|
| 65 | - WelcomeUserTask::class => 'Welcome user', |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Saves a data object to the database, either updating or inserting a record. |
|
| 71 | - * @return void |
|
| 72 | - * @throws Exception |
|
| 73 | - * @throws OptimisticLockFailedException |
|
| 74 | - */ |
|
| 75 | - public function save() |
|
| 76 | - { |
|
| 77 | - if ($this->isNew()) { |
|
| 78 | - // insert |
|
| 79 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 29 | + const STATUS_READY = 'ready'; |
|
| 30 | + const STATUS_WAITING = 'waiting'; |
|
| 31 | + const STATUS_RUNNING = 'running'; |
|
| 32 | + const STATUS_COMPLETE = 'complete'; |
|
| 33 | + const STATUS_CANCELLED = 'cancelled'; |
|
| 34 | + const STATUS_FAILED = 'failed'; |
|
| 35 | + const STATUS_HELD = 'held'; |
|
| 36 | + |
|
| 37 | + /** @var string */ |
|
| 38 | + private $task; |
|
| 39 | + /** @var int */ |
|
| 40 | + private $user; |
|
| 41 | + /** @var int */ |
|
| 42 | + private $request; |
|
| 43 | + /** @var int */ |
|
| 44 | + private $emailtemplate; |
|
| 45 | + /** @var string */ |
|
| 46 | + private $status; |
|
| 47 | + /** @var string */ |
|
| 48 | + private $enqueue; |
|
| 49 | + /** @var string */ |
|
| 50 | + private $parameters; |
|
| 51 | + /** @var string */ |
|
| 52 | + private $error; |
|
| 53 | + /** @var int */ |
|
| 54 | + private $acknowledged; |
|
| 55 | + /** @var int */ |
|
| 56 | + private $parent; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * This feels like the least bad place to put this method. |
|
| 60 | + */ |
|
| 61 | + public static function getTaskDescriptions() { |
|
| 62 | + return array( |
|
| 63 | + BotCreationTask::class => 'Create account (via bot)', |
|
| 64 | + UserCreationTask::class => 'Create account (via OAuth)', |
|
| 65 | + WelcomeUserTask::class => 'Welcome user', |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Saves a data object to the database, either updating or inserting a record. |
|
| 71 | + * @return void |
|
| 72 | + * @throws Exception |
|
| 73 | + * @throws OptimisticLockFailedException |
|
| 74 | + */ |
|
| 75 | + public function save() |
|
| 76 | + { |
|
| 77 | + if ($this->isNew()) { |
|
| 78 | + // insert |
|
| 79 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 80 | 80 | INSERT INTO jobqueue (task, user, request, emailtemplate, parameters, parent) |
| 81 | 81 | VALUES (:task, :user, :request, :emailtemplate, :parameters, :parent) |
| 82 | 82 | SQL |
| 83 | - ); |
|
| 84 | - $statement->bindValue(":task", $this->task); |
|
| 85 | - $statement->bindValue(":user", $this->user); |
|
| 86 | - $statement->bindValue(":request", $this->request); |
|
| 87 | - $statement->bindValue(":emailtemplate", $this->emailtemplate); |
|
| 88 | - $statement->bindValue(":parameters", $this->parameters); |
|
| 89 | - $statement->bindValue(":parent", $this->parent); |
|
| 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 | - // update |
|
| 100 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 83 | + ); |
|
| 84 | + $statement->bindValue(":task", $this->task); |
|
| 85 | + $statement->bindValue(":user", $this->user); |
|
| 86 | + $statement->bindValue(":request", $this->request); |
|
| 87 | + $statement->bindValue(":emailtemplate", $this->emailtemplate); |
|
| 88 | + $statement->bindValue(":parameters", $this->parameters); |
|
| 89 | + $statement->bindValue(":parent", $this->parent); |
|
| 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 | + // update |
|
| 100 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 101 | 101 | UPDATE jobqueue SET |
| 102 | 102 | status = :status |
| 103 | 103 | , error = :error |
@@ -105,187 +105,187 @@ discard block |
||
| 105 | 105 | , updateversion = updateversion + 1 |
| 106 | 106 | WHERE id = :id AND updateversion = :updateversion; |
| 107 | 107 | SQL |
| 108 | - ); |
|
| 109 | - |
|
| 110 | - $statement->bindValue(":id", $this->id); |
|
| 111 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
| 112 | - |
|
| 113 | - $statement->bindValue(":status", $this->status); |
|
| 114 | - $statement->bindValue(":error", $this->error); |
|
| 115 | - $statement->bindValue(":ack", $this->acknowledged); |
|
| 116 | - |
|
| 117 | - if (!$statement->execute()) { |
|
| 118 | - throw new Exception($statement->errorInfo()); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ($statement->rowCount() !== 1) { |
|
| 122 | - throw new OptimisticLockFailedException(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $this->updateversion++; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - #region Properties |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function getTask() |
|
| 135 | - { |
|
| 136 | - return $this->task; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $task |
|
| 141 | - */ |
|
| 142 | - public function setTask($task) |
|
| 143 | - { |
|
| 144 | - $this->task = $task; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return int |
|
| 149 | - */ |
|
| 150 | - public function getTriggerUserId() |
|
| 151 | - { |
|
| 152 | - return $this->user; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param int $user |
|
| 157 | - */ |
|
| 158 | - public function setTriggerUserId($user) |
|
| 159 | - { |
|
| 160 | - $this->user = $user; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @return int |
|
| 165 | - */ |
|
| 166 | - public function getRequest() |
|
| 167 | - { |
|
| 168 | - return $this->request; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param int $request |
|
| 173 | - */ |
|
| 174 | - public function setRequest($request) |
|
| 175 | - { |
|
| 176 | - $this->request = $request; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function getStatus() |
|
| 183 | - { |
|
| 184 | - return $this->status; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @param string $status |
|
| 189 | - */ |
|
| 190 | - public function setStatus($status) |
|
| 191 | - { |
|
| 192 | - $this->status = $status; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @return string |
|
| 197 | - */ |
|
| 198 | - public function getEnqueue() |
|
| 199 | - { |
|
| 200 | - return $this->enqueue; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param string $enqueue |
|
| 205 | - */ |
|
| 206 | - public function setEnqueue($enqueue) |
|
| 207 | - { |
|
| 208 | - $this->enqueue = $enqueue; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public function getParameters() |
|
| 215 | - { |
|
| 216 | - return $this->parameters; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param string $parameters |
|
| 221 | - */ |
|
| 222 | - public function setParameters($parameters) |
|
| 223 | - { |
|
| 224 | - $this->parameters = $parameters; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @return mixed |
|
| 229 | - */ |
|
| 230 | - public function getError() |
|
| 231 | - { |
|
| 232 | - return $this->error; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @param mixed $error |
|
| 237 | - */ |
|
| 238 | - public function setError($error) |
|
| 239 | - { |
|
| 240 | - $this->error = $error; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @return int |
|
| 245 | - */ |
|
| 246 | - public function getAcknowledged() |
|
| 247 | - { |
|
| 248 | - return $this->acknowledged; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @param int $acknowledged |
|
| 253 | - */ |
|
| 254 | - public function setAcknowledged($acknowledged) |
|
| 255 | - { |
|
| 256 | - $this->acknowledged = $acknowledged; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return int |
|
| 261 | - */ |
|
| 262 | - public function getParent() |
|
| 263 | - { |
|
| 264 | - return $this->parent; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @param int $parent |
|
| 269 | - */ |
|
| 270 | - public function setParent($parent) |
|
| 271 | - { |
|
| 272 | - $this->parent = $parent; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @return int |
|
| 277 | - */ |
|
| 278 | - public function getEmailTemplate() |
|
| 279 | - { |
|
| 280 | - return $this->emailtemplate; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @param int $emailTemplate |
|
| 285 | - */ |
|
| 286 | - public function setEmailTemplate($emailTemplate) |
|
| 287 | - { |
|
| 288 | - $this->emailtemplate = $emailTemplate; |
|
| 289 | - } |
|
| 290 | - #endregion |
|
| 108 | + ); |
|
| 109 | + |
|
| 110 | + $statement->bindValue(":id", $this->id); |
|
| 111 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
| 112 | + |
|
| 113 | + $statement->bindValue(":status", $this->status); |
|
| 114 | + $statement->bindValue(":error", $this->error); |
|
| 115 | + $statement->bindValue(":ack", $this->acknowledged); |
|
| 116 | + |
|
| 117 | + if (!$statement->execute()) { |
|
| 118 | + throw new Exception($statement->errorInfo()); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ($statement->rowCount() !== 1) { |
|
| 122 | + throw new OptimisticLockFailedException(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $this->updateversion++; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + #region Properties |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function getTask() |
|
| 135 | + { |
|
| 136 | + return $this->task; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $task |
|
| 141 | + */ |
|
| 142 | + public function setTask($task) |
|
| 143 | + { |
|
| 144 | + $this->task = $task; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return int |
|
| 149 | + */ |
|
| 150 | + public function getTriggerUserId() |
|
| 151 | + { |
|
| 152 | + return $this->user; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param int $user |
|
| 157 | + */ |
|
| 158 | + public function setTriggerUserId($user) |
|
| 159 | + { |
|
| 160 | + $this->user = $user; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @return int |
|
| 165 | + */ |
|
| 166 | + public function getRequest() |
|
| 167 | + { |
|
| 168 | + return $this->request; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param int $request |
|
| 173 | + */ |
|
| 174 | + public function setRequest($request) |
|
| 175 | + { |
|
| 176 | + $this->request = $request; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function getStatus() |
|
| 183 | + { |
|
| 184 | + return $this->status; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @param string $status |
|
| 189 | + */ |
|
| 190 | + public function setStatus($status) |
|
| 191 | + { |
|
| 192 | + $this->status = $status; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @return string |
|
| 197 | + */ |
|
| 198 | + public function getEnqueue() |
|
| 199 | + { |
|
| 200 | + return $this->enqueue; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param string $enqueue |
|
| 205 | + */ |
|
| 206 | + public function setEnqueue($enqueue) |
|
| 207 | + { |
|
| 208 | + $this->enqueue = $enqueue; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public function getParameters() |
|
| 215 | + { |
|
| 216 | + return $this->parameters; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param string $parameters |
|
| 221 | + */ |
|
| 222 | + public function setParameters($parameters) |
|
| 223 | + { |
|
| 224 | + $this->parameters = $parameters; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @return mixed |
|
| 229 | + */ |
|
| 230 | + public function getError() |
|
| 231 | + { |
|
| 232 | + return $this->error; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @param mixed $error |
|
| 237 | + */ |
|
| 238 | + public function setError($error) |
|
| 239 | + { |
|
| 240 | + $this->error = $error; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @return int |
|
| 245 | + */ |
|
| 246 | + public function getAcknowledged() |
|
| 247 | + { |
|
| 248 | + return $this->acknowledged; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @param int $acknowledged |
|
| 253 | + */ |
|
| 254 | + public function setAcknowledged($acknowledged) |
|
| 255 | + { |
|
| 256 | + $this->acknowledged = $acknowledged; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return int |
|
| 261 | + */ |
|
| 262 | + public function getParent() |
|
| 263 | + { |
|
| 264 | + return $this->parent; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @param int $parent |
|
| 269 | + */ |
|
| 270 | + public function setParent($parent) |
|
| 271 | + { |
|
| 272 | + $this->parent = $parent; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @return int |
|
| 277 | + */ |
|
| 278 | + public function getEmailTemplate() |
|
| 279 | + { |
|
| 280 | + return $this->emailtemplate; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @param int $emailTemplate |
|
| 285 | + */ |
|
| 286 | + public function setEmailTemplate($emailTemplate) |
|
| 287 | + { |
|
| 288 | + $this->emailtemplate = $emailTemplate; |
|
| 289 | + } |
|
| 290 | + #endregion |
|
| 291 | 291 | } |
| 292 | 292 | \ No newline at end of file |
@@ -58,7 +58,8 @@ discard block |
||
| 58 | 58 | /** |
| 59 | 59 | * This feels like the least bad place to put this method. |
| 60 | 60 | */ |
| 61 | - public static function getTaskDescriptions() { |
|
| 61 | + public static function getTaskDescriptions() |
|
| 62 | + { |
|
| 62 | 63 | return array( |
| 63 | 64 | BotCreationTask::class => 'Create account (via bot)', |
| 64 | 65 | UserCreationTask::class => 'Create account (via OAuth)', |
@@ -90,12 +91,10 @@ discard block |
||
| 90 | 91 | |
| 91 | 92 | if ($statement->execute()) { |
| 92 | 93 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 93 | - } |
|
| 94 | - else { |
|
| 94 | + } else { |
|
| 95 | 95 | throw new Exception($statement->errorInfo()); |
| 96 | 96 | } |
| 97 | - } |
|
| 98 | - else { |
|
| 97 | + } else { |
|
| 99 | 98 | // update |
| 100 | 99 | $statement = $this->dbObject->prepare(<<<SQL |
| 101 | 100 | UPDATE jobqueue SET |
@@ -14,42 +14,42 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | class OAuthToken extends DataObject |
| 16 | 16 | { |
| 17 | - /** @var int */ |
|
| 18 | - private $user; |
|
| 19 | - /** @var string */ |
|
| 20 | - private $token; |
|
| 21 | - /** @var string */ |
|
| 22 | - private $secret; |
|
| 23 | - /** @var string */ |
|
| 24 | - private $type; |
|
| 25 | - /** @var string */ |
|
| 26 | - private $expiry; |
|
| 27 | - |
|
| 28 | - public function save() |
|
| 29 | - { |
|
| 30 | - if ($this->isNew()) { |
|
| 31 | - // insert |
|
| 32 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 17 | + /** @var int */ |
|
| 18 | + private $user; |
|
| 19 | + /** @var string */ |
|
| 20 | + private $token; |
|
| 21 | + /** @var string */ |
|
| 22 | + private $secret; |
|
| 23 | + /** @var string */ |
|
| 24 | + private $type; |
|
| 25 | + /** @var string */ |
|
| 26 | + private $expiry; |
|
| 27 | + |
|
| 28 | + public function save() |
|
| 29 | + { |
|
| 30 | + if ($this->isNew()) { |
|
| 31 | + // insert |
|
| 32 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 33 | 33 | INSERT INTO oauthtoken ( user, token, secret, type, expiry ) |
| 34 | 34 | VALUES ( :user, :token, :secret, :type, :expiry ); |
| 35 | 35 | SQL |
| 36 | - ); |
|
| 37 | - $statement->bindValue(":user", $this->user); |
|
| 38 | - $statement->bindValue(":token", $this->token); |
|
| 39 | - $statement->bindValue(":secret", $this->secret); |
|
| 40 | - $statement->bindValue(":type", $this->type); |
|
| 41 | - $statement->bindValue(":expiry", $this->expiry); |
|
| 42 | - |
|
| 43 | - if ($statement->execute()) { |
|
| 44 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 45 | - } |
|
| 46 | - else { |
|
| 47 | - throw new Exception($statement->errorInfo()); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - else { |
|
| 51 | - // update |
|
| 52 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 36 | + ); |
|
| 37 | + $statement->bindValue(":user", $this->user); |
|
| 38 | + $statement->bindValue(":token", $this->token); |
|
| 39 | + $statement->bindValue(":secret", $this->secret); |
|
| 40 | + $statement->bindValue(":type", $this->type); |
|
| 41 | + $statement->bindValue(":expiry", $this->expiry); |
|
| 42 | + |
|
| 43 | + if ($statement->execute()) { |
|
| 44 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 45 | + } |
|
| 46 | + else { |
|
| 47 | + throw new Exception($statement->errorInfo()); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + else { |
|
| 51 | + // update |
|
| 52 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 53 | 53 | UPDATE oauthtoken |
| 54 | 54 | SET token = :token |
| 55 | 55 | , secret = :secret |
@@ -58,109 +58,109 @@ discard block |
||
| 58 | 58 | , updateversion = updateversion + 1 |
| 59 | 59 | WHERE id = :id AND updateversion = :updateversion; |
| 60 | 60 | SQL |
| 61 | - ); |
|
| 62 | - |
|
| 63 | - $statement->bindValue(':id', $this->id); |
|
| 64 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 65 | - |
|
| 66 | - $statement->bindValue(":token", $this->token); |
|
| 67 | - $statement->bindValue(":secret", $this->secret); |
|
| 68 | - $statement->bindValue(":type", $this->type); |
|
| 69 | - $statement->bindValue(":expiry", $this->expiry); |
|
| 70 | - |
|
| 71 | - if (!$statement->execute()) { |
|
| 72 | - throw new Exception($statement->errorInfo()); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if ($statement->rowCount() !== 1) { |
|
| 76 | - throw new OptimisticLockFailedException(); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $this->updateversion++; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - #region properties |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return mixed |
|
| 87 | - */ |
|
| 88 | - public function getUserId() |
|
| 89 | - { |
|
| 90 | - return $this->user; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param mixed $user |
|
| 95 | - */ |
|
| 96 | - public function setUserId($user) |
|
| 97 | - { |
|
| 98 | - $this->user = $user; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return mixed |
|
| 103 | - */ |
|
| 104 | - public function getToken() |
|
| 105 | - { |
|
| 106 | - return $this->token; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param mixed $token |
|
| 111 | - */ |
|
| 112 | - public function setToken($token) |
|
| 113 | - { |
|
| 114 | - $this->token = $token; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return mixed |
|
| 119 | - */ |
|
| 120 | - public function getSecret() |
|
| 121 | - { |
|
| 122 | - return $this->secret; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param mixed $secret |
|
| 127 | - */ |
|
| 128 | - public function setSecret($secret) |
|
| 129 | - { |
|
| 130 | - $this->secret = $secret; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @return mixed |
|
| 135 | - */ |
|
| 136 | - public function getType() |
|
| 137 | - { |
|
| 138 | - return $this->type; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param mixed $type |
|
| 143 | - */ |
|
| 144 | - public function setType($type) |
|
| 145 | - { |
|
| 146 | - $this->type = $type; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public function getExpiry() |
|
| 153 | - { |
|
| 154 | - return $this->expiry; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param string $expiry |
|
| 159 | - */ |
|
| 160 | - public function setExpiry($expiry) |
|
| 161 | - { |
|
| 162 | - $this->expiry = $expiry; |
|
| 163 | - } |
|
| 164 | - #endregion |
|
| 61 | + ); |
|
| 62 | + |
|
| 63 | + $statement->bindValue(':id', $this->id); |
|
| 64 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 65 | + |
|
| 66 | + $statement->bindValue(":token", $this->token); |
|
| 67 | + $statement->bindValue(":secret", $this->secret); |
|
| 68 | + $statement->bindValue(":type", $this->type); |
|
| 69 | + $statement->bindValue(":expiry", $this->expiry); |
|
| 70 | + |
|
| 71 | + if (!$statement->execute()) { |
|
| 72 | + throw new Exception($statement->errorInfo()); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if ($statement->rowCount() !== 1) { |
|
| 76 | + throw new OptimisticLockFailedException(); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $this->updateversion++; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + #region properties |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return mixed |
|
| 87 | + */ |
|
| 88 | + public function getUserId() |
|
| 89 | + { |
|
| 90 | + return $this->user; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param mixed $user |
|
| 95 | + */ |
|
| 96 | + public function setUserId($user) |
|
| 97 | + { |
|
| 98 | + $this->user = $user; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return mixed |
|
| 103 | + */ |
|
| 104 | + public function getToken() |
|
| 105 | + { |
|
| 106 | + return $this->token; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param mixed $token |
|
| 111 | + */ |
|
| 112 | + public function setToken($token) |
|
| 113 | + { |
|
| 114 | + $this->token = $token; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return mixed |
|
| 119 | + */ |
|
| 120 | + public function getSecret() |
|
| 121 | + { |
|
| 122 | + return $this->secret; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param mixed $secret |
|
| 127 | + */ |
|
| 128 | + public function setSecret($secret) |
|
| 129 | + { |
|
| 130 | + $this->secret = $secret; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @return mixed |
|
| 135 | + */ |
|
| 136 | + public function getType() |
|
| 137 | + { |
|
| 138 | + return $this->type; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param mixed $type |
|
| 143 | + */ |
|
| 144 | + public function setType($type) |
|
| 145 | + { |
|
| 146 | + $this->type = $type; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public function getExpiry() |
|
| 153 | + { |
|
| 154 | + return $this->expiry; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param string $expiry |
|
| 159 | + */ |
|
| 160 | + public function setExpiry($expiry) |
|
| 161 | + { |
|
| 162 | + $this->expiry = $expiry; |
|
| 163 | + } |
|
| 164 | + #endregion |
|
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | \ No newline at end of file |
@@ -42,12 +42,10 @@ |
||
| 42 | 42 | |
| 43 | 43 | if ($statement->execute()) { |
| 44 | 44 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 45 | - } |
|
| 46 | - else { |
|
| 45 | + } else { |
|
| 47 | 46 | throw new Exception($statement->errorInfo()); |
| 48 | 47 | } |
| 49 | - } |
|
| 50 | - else { |
|
| 48 | + } else { |
|
| 51 | 49 | // update |
| 52 | 50 | $statement = $this->dbObject->prepare(<<<SQL |
| 53 | 51 | UPDATE oauthtoken |
@@ -64,12 +64,10 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | if ($user === false) { |
| 66 | 66 | self::$currentUser = new CommunityUser(); |
| 67 | - } |
|
| 68 | - else { |
|
| 67 | + } else { |
|
| 69 | 68 | self::$currentUser = $user; |
| 70 | 69 | } |
| 71 | - } |
|
| 72 | - else { |
|
| 70 | + } else { |
|
| 73 | 71 | $anonymousCoward = new CommunityUser(); |
| 74 | 72 | |
| 75 | 73 | self::$currentUser = $anonymousCoward; |
@@ -203,12 +201,10 @@ discard block |
||
| 203 | 201 | |
| 204 | 202 | if ($statement->execute()) { |
| 205 | 203 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 206 | - } |
|
| 207 | - else { |
|
| 204 | + } else { |
|
| 208 | 205 | throw new Exception($statement->errorInfo()); |
| 209 | 206 | } |
| 210 | - } |
|
| 211 | - else { |
|
| 207 | + } else { |
|
| 212 | 208 | // update |
| 213 | 209 | $statement = $this->dbObject->prepare(<<<SQL |
| 214 | 210 | UPDATE `user` SET |
@@ -533,12 +529,10 @@ discard block |
||
| 533 | 529 | if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
| 534 | 530 | // User forced to unidentified in the database. |
| 535 | 531 | return false; |
| 536 | - } |
|
| 537 | - elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 532 | + } elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 538 | 533 | // User forced to identified in the database. |
| 539 | 534 | return true; |
| 540 | - } |
|
| 541 | - else { |
|
| 535 | + } else { |
|
| 542 | 536 | // User not forced to any particular identified status; consult IdentificationVerifier |
| 543 | 537 | return $iv->isUserIdentified($this->getOnWikiName()); |
| 544 | 538 | } |
@@ -549,7 +543,8 @@ discard block |
||
| 549 | 543 | * |
| 550 | 544 | * @return bool|null |
| 551 | 545 | */ |
| 552 | - public function getForceIdentified() { |
|
| 546 | + public function getForceIdentified() |
|
| 547 | + { |
|
| 553 | 548 | return $this->forceidentified; |
| 554 | 549 | } |
| 555 | 550 | |
@@ -21,160 +21,160 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class User extends DataObject |
| 23 | 23 | { |
| 24 | - const STATUS_ACTIVE = 'Active'; |
|
| 25 | - const STATUS_SUSPENDED = 'Suspended'; |
|
| 26 | - const STATUS_DECLINED = 'Declined'; |
|
| 27 | - const STATUS_NEW = 'New'; |
|
| 28 | - const CREATION_MANUAL = 0; |
|
| 29 | - const CREATION_OAUTH = 1; |
|
| 30 | - const CREATION_BOT = 2; |
|
| 31 | - private $username; |
|
| 32 | - private $email; |
|
| 33 | - private $status = self::STATUS_NEW; |
|
| 34 | - private $onwikiname; |
|
| 35 | - private $welcome_sig = ""; |
|
| 36 | - private $lastactive = "0000-00-00 00:00:00"; |
|
| 37 | - private $forcelogout = 0; |
|
| 38 | - private $forceidentified = null; |
|
| 39 | - private $welcome_template = 0; |
|
| 40 | - private $abortpref = 0; |
|
| 41 | - private $confirmationdiff = 0; |
|
| 42 | - private $emailsig = ""; |
|
| 43 | - private $creationmode = 0; |
|
| 44 | - private $skin = "auto"; |
|
| 45 | - /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
| 46 | - private static $currentUser; |
|
| 47 | - #region Object load methods |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Gets the currently logged in user |
|
| 51 | - * |
|
| 52 | - * @param PdoDatabase $database |
|
| 53 | - * |
|
| 54 | - * @return User|CommunityUser |
|
| 55 | - */ |
|
| 56 | - public static function getCurrent(PdoDatabase $database) |
|
| 57 | - { |
|
| 58 | - if (self::$currentUser === null) { |
|
| 59 | - $sessionId = WebRequest::getSessionUserId(); |
|
| 60 | - |
|
| 61 | - if ($sessionId !== null) { |
|
| 62 | - /** @var User $user */ |
|
| 63 | - $user = self::getById($sessionId, $database); |
|
| 64 | - |
|
| 65 | - if ($user === false) { |
|
| 66 | - self::$currentUser = new CommunityUser(); |
|
| 67 | - } |
|
| 68 | - else { |
|
| 69 | - self::$currentUser = $user; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - else { |
|
| 73 | - $anonymousCoward = new CommunityUser(); |
|
| 74 | - |
|
| 75 | - self::$currentUser = $anonymousCoward; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - return self::$currentUser; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Gets a user by their user ID |
|
| 84 | - * |
|
| 85 | - * Pass -1 to get the community user. |
|
| 86 | - * |
|
| 87 | - * @param int|null $id |
|
| 88 | - * @param PdoDatabase $database |
|
| 89 | - * |
|
| 90 | - * @return User|false |
|
| 91 | - */ |
|
| 92 | - public static function getById($id, PdoDatabase $database) |
|
| 93 | - { |
|
| 94 | - if ($id === null || $id == -1) { |
|
| 95 | - return new CommunityUser(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** @var User|false $user */ |
|
| 99 | - $user = parent::getById($id, $database); |
|
| 100 | - |
|
| 101 | - return $user; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return CommunityUser |
|
| 106 | - */ |
|
| 107 | - public static function getCommunity() |
|
| 108 | - { |
|
| 109 | - return new CommunityUser(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Gets a user by their username |
|
| 114 | - * |
|
| 115 | - * @param string $username |
|
| 116 | - * @param PdoDatabase $database |
|
| 117 | - * |
|
| 118 | - * @return CommunityUser|User|false |
|
| 119 | - */ |
|
| 120 | - public static function getByUsername($username, PdoDatabase $database) |
|
| 121 | - { |
|
| 122 | - global $communityUsername; |
|
| 123 | - if ($username == $communityUsername) { |
|
| 124 | - return new CommunityUser(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
| 128 | - $statement->bindValue(":id", $username); |
|
| 129 | - |
|
| 130 | - $statement->execute(); |
|
| 131 | - |
|
| 132 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 133 | - |
|
| 134 | - if ($resultObject != false) { |
|
| 135 | - $resultObject->setDatabase($database); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $resultObject; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Gets a user by their on-wiki username. |
|
| 143 | - * |
|
| 144 | - * @param string $username |
|
| 145 | - * @param PdoDatabase $database |
|
| 146 | - * |
|
| 147 | - * @return User|false |
|
| 148 | - */ |
|
| 149 | - public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
| 150 | - { |
|
| 151 | - $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
| 152 | - $statement->bindValue(":id", $username); |
|
| 153 | - $statement->execute(); |
|
| 154 | - |
|
| 155 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 156 | - |
|
| 157 | - if ($resultObject != false) { |
|
| 158 | - $resultObject->setDatabase($database); |
|
| 159 | - |
|
| 160 | - return $resultObject; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - #endregion |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Saves the current object |
|
| 170 | - * |
|
| 171 | - * @throws Exception |
|
| 172 | - */ |
|
| 173 | - public function save() |
|
| 174 | - { |
|
| 175 | - if ($this->isNew()) { |
|
| 176 | - // insert |
|
| 177 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 24 | + const STATUS_ACTIVE = 'Active'; |
|
| 25 | + const STATUS_SUSPENDED = 'Suspended'; |
|
| 26 | + const STATUS_DECLINED = 'Declined'; |
|
| 27 | + const STATUS_NEW = 'New'; |
|
| 28 | + const CREATION_MANUAL = 0; |
|
| 29 | + const CREATION_OAUTH = 1; |
|
| 30 | + const CREATION_BOT = 2; |
|
| 31 | + private $username; |
|
| 32 | + private $email; |
|
| 33 | + private $status = self::STATUS_NEW; |
|
| 34 | + private $onwikiname; |
|
| 35 | + private $welcome_sig = ""; |
|
| 36 | + private $lastactive = "0000-00-00 00:00:00"; |
|
| 37 | + private $forcelogout = 0; |
|
| 38 | + private $forceidentified = null; |
|
| 39 | + private $welcome_template = 0; |
|
| 40 | + private $abortpref = 0; |
|
| 41 | + private $confirmationdiff = 0; |
|
| 42 | + private $emailsig = ""; |
|
| 43 | + private $creationmode = 0; |
|
| 44 | + private $skin = "auto"; |
|
| 45 | + /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
| 46 | + private static $currentUser; |
|
| 47 | + #region Object load methods |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Gets the currently logged in user |
|
| 51 | + * |
|
| 52 | + * @param PdoDatabase $database |
|
| 53 | + * |
|
| 54 | + * @return User|CommunityUser |
|
| 55 | + */ |
|
| 56 | + public static function getCurrent(PdoDatabase $database) |
|
| 57 | + { |
|
| 58 | + if (self::$currentUser === null) { |
|
| 59 | + $sessionId = WebRequest::getSessionUserId(); |
|
| 60 | + |
|
| 61 | + if ($sessionId !== null) { |
|
| 62 | + /** @var User $user */ |
|
| 63 | + $user = self::getById($sessionId, $database); |
|
| 64 | + |
|
| 65 | + if ($user === false) { |
|
| 66 | + self::$currentUser = new CommunityUser(); |
|
| 67 | + } |
|
| 68 | + else { |
|
| 69 | + self::$currentUser = $user; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + else { |
|
| 73 | + $anonymousCoward = new CommunityUser(); |
|
| 74 | + |
|
| 75 | + self::$currentUser = $anonymousCoward; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + return self::$currentUser; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Gets a user by their user ID |
|
| 84 | + * |
|
| 85 | + * Pass -1 to get the community user. |
|
| 86 | + * |
|
| 87 | + * @param int|null $id |
|
| 88 | + * @param PdoDatabase $database |
|
| 89 | + * |
|
| 90 | + * @return User|false |
|
| 91 | + */ |
|
| 92 | + public static function getById($id, PdoDatabase $database) |
|
| 93 | + { |
|
| 94 | + if ($id === null || $id == -1) { |
|
| 95 | + return new CommunityUser(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** @var User|false $user */ |
|
| 99 | + $user = parent::getById($id, $database); |
|
| 100 | + |
|
| 101 | + return $user; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return CommunityUser |
|
| 106 | + */ |
|
| 107 | + public static function getCommunity() |
|
| 108 | + { |
|
| 109 | + return new CommunityUser(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Gets a user by their username |
|
| 114 | + * |
|
| 115 | + * @param string $username |
|
| 116 | + * @param PdoDatabase $database |
|
| 117 | + * |
|
| 118 | + * @return CommunityUser|User|false |
|
| 119 | + */ |
|
| 120 | + public static function getByUsername($username, PdoDatabase $database) |
|
| 121 | + { |
|
| 122 | + global $communityUsername; |
|
| 123 | + if ($username == $communityUsername) { |
|
| 124 | + return new CommunityUser(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
| 128 | + $statement->bindValue(":id", $username); |
|
| 129 | + |
|
| 130 | + $statement->execute(); |
|
| 131 | + |
|
| 132 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 133 | + |
|
| 134 | + if ($resultObject != false) { |
|
| 135 | + $resultObject->setDatabase($database); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $resultObject; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Gets a user by their on-wiki username. |
|
| 143 | + * |
|
| 144 | + * @param string $username |
|
| 145 | + * @param PdoDatabase $database |
|
| 146 | + * |
|
| 147 | + * @return User|false |
|
| 148 | + */ |
|
| 149 | + public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
| 150 | + { |
|
| 151 | + $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
| 152 | + $statement->bindValue(":id", $username); |
|
| 153 | + $statement->execute(); |
|
| 154 | + |
|
| 155 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 156 | + |
|
| 157 | + if ($resultObject != false) { |
|
| 158 | + $resultObject->setDatabase($database); |
|
| 159 | + |
|
| 160 | + return $resultObject; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + #endregion |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Saves the current object |
|
| 170 | + * |
|
| 171 | + * @throws Exception |
|
| 172 | + */ |
|
| 173 | + public function save() |
|
| 174 | + { |
|
| 175 | + if ($this->isNew()) { |
|
| 176 | + // insert |
|
| 177 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 178 | 178 | INSERT INTO `user` ( |
| 179 | 179 | username, email, status, onwikiname, welcome_sig, |
| 180 | 180 | lastactive, forcelogout, forceidentified, |
@@ -185,32 +185,32 @@ discard block |
||
| 185 | 185 | :welcome_template, :abortpref, :confirmationdiff, :emailsig, :creationmode, :skin |
| 186 | 186 | ); |
| 187 | 187 | SQL |
| 188 | - ); |
|
| 189 | - $statement->bindValue(":username", $this->username); |
|
| 190 | - $statement->bindValue(":email", $this->email); |
|
| 191 | - $statement->bindValue(":status", $this->status); |
|
| 192 | - $statement->bindValue(":onwikiname", $this->onwikiname); |
|
| 193 | - $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
| 194 | - $statement->bindValue(":lastactive", $this->lastactive); |
|
| 195 | - $statement->bindValue(":forcelogout", $this->forcelogout); |
|
| 196 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 197 | - $statement->bindValue(":welcome_template", $this->welcome_template); |
|
| 198 | - $statement->bindValue(":abortpref", $this->abortpref); |
|
| 199 | - $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
| 200 | - $statement->bindValue(":emailsig", $this->emailsig); |
|
| 201 | - $statement->bindValue(":creationmode", $this->creationmode); |
|
| 202 | - $statement->bindValue(":skin", $this->skin); |
|
| 203 | - |
|
| 204 | - if ($statement->execute()) { |
|
| 205 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 206 | - } |
|
| 207 | - else { |
|
| 208 | - throw new Exception($statement->errorInfo()); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - else { |
|
| 212 | - // update |
|
| 213 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 188 | + ); |
|
| 189 | + $statement->bindValue(":username", $this->username); |
|
| 190 | + $statement->bindValue(":email", $this->email); |
|
| 191 | + $statement->bindValue(":status", $this->status); |
|
| 192 | + $statement->bindValue(":onwikiname", $this->onwikiname); |
|
| 193 | + $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
| 194 | + $statement->bindValue(":lastactive", $this->lastactive); |
|
| 195 | + $statement->bindValue(":forcelogout", $this->forcelogout); |
|
| 196 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 197 | + $statement->bindValue(":welcome_template", $this->welcome_template); |
|
| 198 | + $statement->bindValue(":abortpref", $this->abortpref); |
|
| 199 | + $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
| 200 | + $statement->bindValue(":emailsig", $this->emailsig); |
|
| 201 | + $statement->bindValue(":creationmode", $this->creationmode); |
|
| 202 | + $statement->bindValue(":skin", $this->skin); |
|
| 203 | + |
|
| 204 | + if ($statement->execute()) { |
|
| 205 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 206 | + } |
|
| 207 | + else { |
|
| 208 | + throw new Exception($statement->errorInfo()); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + else { |
|
| 212 | + // update |
|
| 213 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 214 | 214 | UPDATE `user` SET |
| 215 | 215 | username = :username, email = :email, |
| 216 | 216 | status = :status, |
@@ -223,379 +223,379 @@ discard block |
||
| 223 | 223 | updateversion = updateversion + 1 |
| 224 | 224 | WHERE id = :id AND updateversion = :updateversion; |
| 225 | 225 | SQL |
| 226 | - ); |
|
| 227 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 228 | - |
|
| 229 | - $statement->bindValue(':id', $this->id); |
|
| 230 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 231 | - |
|
| 232 | - $statement->bindValue(':username', $this->username); |
|
| 233 | - $statement->bindValue(':email', $this->email); |
|
| 234 | - $statement->bindValue(':status', $this->status); |
|
| 235 | - $statement->bindValue(':onwikiname', $this->onwikiname); |
|
| 236 | - $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
| 237 | - $statement->bindValue(':lastactive', $this->lastactive); |
|
| 238 | - $statement->bindValue(':forcelogout', $this->forcelogout); |
|
| 239 | - $statement->bindValue(':forceidentified', $this->forceidentified); |
|
| 240 | - $statement->bindValue(':welcome_template', $this->welcome_template); |
|
| 241 | - $statement->bindValue(':abortpref', $this->abortpref); |
|
| 242 | - $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
| 243 | - $statement->bindValue(':emailsig', $this->emailsig); |
|
| 244 | - $statement->bindValue(':creationmode', $this->creationmode); |
|
| 245 | - $statement->bindValue(':skin', $this->skin); |
|
| 246 | - |
|
| 247 | - if (!$statement->execute()) { |
|
| 248 | - throw new Exception($statement->errorInfo()); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - if ($statement->rowCount() !== 1) { |
|
| 252 | - throw new OptimisticLockFailedException(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $this->updateversion++; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - #region properties |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Gets the tool username |
|
| 263 | - * @return string |
|
| 264 | - */ |
|
| 265 | - public function getUsername() |
|
| 266 | - { |
|
| 267 | - return $this->username; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Sets the tool username |
|
| 272 | - * |
|
| 273 | - * @param string $username |
|
| 274 | - */ |
|
| 275 | - public function setUsername($username) |
|
| 276 | - { |
|
| 277 | - $this->username = $username; |
|
| 278 | - |
|
| 279 | - // If this isn't a brand new user, then it's a rename, force the logout |
|
| 280 | - if (!$this->isNew()) { |
|
| 281 | - $this->forcelogout = 1; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Gets the user's email address |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - public function getEmail() |
|
| 290 | - { |
|
| 291 | - return $this->email; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Sets the user's email address |
|
| 296 | - * |
|
| 297 | - * @param string $email |
|
| 298 | - */ |
|
| 299 | - public function setEmail($email) |
|
| 300 | - { |
|
| 301 | - $this->email = $email; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 308 | - public function getStatus() |
|
| 309 | - { |
|
| 310 | - return $this->status; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @param string $status |
|
| 315 | - */ |
|
| 316 | - public function setStatus($status) |
|
| 317 | - { |
|
| 318 | - $this->status = $status; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Gets the user's on-wiki name |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - public function getOnWikiName() |
|
| 326 | - { |
|
| 327 | - return $this->onwikiname; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Sets the user's on-wiki name |
|
| 332 | - * |
|
| 333 | - * This can have interesting side-effects with OAuth. |
|
| 334 | - * |
|
| 335 | - * @param string $onWikiName |
|
| 336 | - */ |
|
| 337 | - public function setOnWikiName($onWikiName) |
|
| 338 | - { |
|
| 339 | - $this->onwikiname = $onWikiName; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Gets the welcome signature |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public function getWelcomeSig() |
|
| 347 | - { |
|
| 348 | - return $this->welcome_sig; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Sets the welcome signature |
|
| 353 | - * |
|
| 354 | - * @param string $welcomeSig |
|
| 355 | - */ |
|
| 356 | - public function setWelcomeSig($welcomeSig) |
|
| 357 | - { |
|
| 358 | - $this->welcome_sig = $welcomeSig; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Gets the last activity date for the user |
|
| 363 | - * |
|
| 364 | - * @return string |
|
| 365 | - * @todo This should probably return an instance of DateTime |
|
| 366 | - */ |
|
| 367 | - public function getLastActive() |
|
| 368 | - { |
|
| 369 | - return $this->lastactive; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Gets the user's forced logout status |
|
| 374 | - * |
|
| 375 | - * @return bool |
|
| 376 | - */ |
|
| 377 | - public function getForceLogout() |
|
| 378 | - { |
|
| 379 | - return $this->forcelogout == 1; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Sets the user's forced logout status |
|
| 384 | - * |
|
| 385 | - * @param bool $forceLogout |
|
| 386 | - */ |
|
| 387 | - public function setForceLogout($forceLogout) |
|
| 388 | - { |
|
| 389 | - $this->forcelogout = $forceLogout ? 1 : 0; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Returns the ID of the welcome template used. |
|
| 394 | - * @return int |
|
| 395 | - */ |
|
| 396 | - public function getWelcomeTemplate() |
|
| 397 | - { |
|
| 398 | - return $this->welcome_template; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Sets the ID of the welcome template used. |
|
| 403 | - * |
|
| 404 | - * @param int $welcomeTemplate |
|
| 405 | - */ |
|
| 406 | - public function setWelcomeTemplate($welcomeTemplate) |
|
| 407 | - { |
|
| 408 | - $this->welcome_template = $welcomeTemplate; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Gets the user's abort preference |
|
| 413 | - * @todo this is badly named too! Also a bool that's actually an int. |
|
| 414 | - * @return int |
|
| 415 | - */ |
|
| 416 | - public function getAbortPref() |
|
| 417 | - { |
|
| 418 | - return $this->abortpref; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Sets the user's abort preference |
|
| 423 | - * @todo rename, retype, and re-comment. |
|
| 424 | - * |
|
| 425 | - * @param int $abortPreference |
|
| 426 | - */ |
|
| 427 | - public function setAbortPref($abortPreference) |
|
| 428 | - { |
|
| 429 | - $this->abortpref = $abortPreference; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
| 434 | - * @return int the diff ID |
|
| 435 | - */ |
|
| 436 | - public function getConfirmationDiff() |
|
| 437 | - { |
|
| 438 | - return $this->confirmationdiff; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Sets the user's confirmation diff. |
|
| 443 | - * |
|
| 444 | - * @param int $confirmationDiff |
|
| 445 | - */ |
|
| 446 | - public function setConfirmationDiff($confirmationDiff) |
|
| 447 | - { |
|
| 448 | - $this->confirmationdiff = $confirmationDiff; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Gets the users' email signature used on outbound mail. |
|
| 453 | - * @todo rename me! |
|
| 454 | - * @return string |
|
| 455 | - */ |
|
| 456 | - public function getEmailSig() |
|
| 457 | - { |
|
| 458 | - return $this->emailsig; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Sets the user's email signature for outbound mail. |
|
| 463 | - * |
|
| 464 | - * @param string $emailSignature |
|
| 465 | - */ |
|
| 466 | - public function setEmailSig($emailSignature) |
|
| 467 | - { |
|
| 468 | - $this->emailsig = $emailSignature; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @return int |
|
| 473 | - */ |
|
| 474 | - public function getCreationMode() |
|
| 475 | - { |
|
| 476 | - return $this->creationmode; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * @param $creationMode int |
|
| 481 | - */ |
|
| 482 | - public function setCreationMode($creationMode) |
|
| 483 | - { |
|
| 484 | - $this->creationmode = $creationMode; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @return string |
|
| 489 | - */ |
|
| 490 | - public function getSkin() |
|
| 491 | - { |
|
| 492 | - return $this->skin; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * @param $skin string |
|
| 497 | - */ |
|
| 498 | - public function setSkin($skin) |
|
| 499 | - { |
|
| 500 | - $this->skin = $skin; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - #endregion |
|
| 504 | - |
|
| 505 | - #region user access checks |
|
| 506 | - |
|
| 507 | - public function isActive() |
|
| 508 | - { |
|
| 509 | - return $this->status == self::STATUS_ACTIVE; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Tests if the user is identified |
|
| 514 | - * |
|
| 515 | - * @param IdentificationVerifier $iv |
|
| 516 | - * |
|
| 517 | - * @return bool |
|
| 518 | - * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
| 519 | - * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
| 520 | - * to play it safe for now. |
|
| 521 | - * @category Security-Critical |
|
| 522 | - */ |
|
| 523 | - public function isIdentified(IdentificationVerifier $iv) |
|
| 524 | - { |
|
| 525 | - if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
| 526 | - // User forced to unidentified in the database. |
|
| 527 | - return false; |
|
| 528 | - } |
|
| 529 | - elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 530 | - // User forced to identified in the database. |
|
| 531 | - return true; |
|
| 532 | - } |
|
| 533 | - else { |
|
| 534 | - // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 535 | - return $iv->isUserIdentified($this->getOnWikiName()); |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * DO NOT USE FOR TESTING IDENTIFICATION STATUS. |
|
| 541 | - * |
|
| 542 | - * @return bool|null |
|
| 543 | - */ |
|
| 544 | - public function getForceIdentified() { |
|
| 545 | - return $this->forceidentified; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Tests if the user is suspended |
|
| 550 | - * @return bool |
|
| 551 | - * @category Security-Critical |
|
| 552 | - */ |
|
| 553 | - public function isSuspended() |
|
| 554 | - { |
|
| 555 | - return $this->status == self::STATUS_SUSPENDED; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Tests if the user is new |
|
| 560 | - * @return bool |
|
| 561 | - * @category Security-Critical |
|
| 562 | - */ |
|
| 563 | - public function isNewUser() |
|
| 564 | - { |
|
| 565 | - return $this->status == self::STATUS_NEW; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Tests if the user has been declined access to the tool |
|
| 570 | - * @return bool |
|
| 571 | - * @category Security-Critical |
|
| 572 | - */ |
|
| 573 | - public function isDeclined() |
|
| 574 | - { |
|
| 575 | - return $this->status == self::STATUS_DECLINED; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Tests if the user is the community user |
|
| 580 | - * |
|
| 581 | - * @todo decide if this means logged out. I think it usually does. |
|
| 582 | - * @return bool |
|
| 583 | - * @category Security-Critical |
|
| 584 | - */ |
|
| 585 | - public function isCommunityUser() |
|
| 586 | - { |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - #endregion |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Gets the approval date of the user |
|
| 594 | - * @return DateTime|false |
|
| 595 | - */ |
|
| 596 | - public function getApprovalDate() |
|
| 597 | - { |
|
| 598 | - $query = $this->dbObject->prepare(<<<SQL |
|
| 226 | + ); |
|
| 227 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 228 | + |
|
| 229 | + $statement->bindValue(':id', $this->id); |
|
| 230 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 231 | + |
|
| 232 | + $statement->bindValue(':username', $this->username); |
|
| 233 | + $statement->bindValue(':email', $this->email); |
|
| 234 | + $statement->bindValue(':status', $this->status); |
|
| 235 | + $statement->bindValue(':onwikiname', $this->onwikiname); |
|
| 236 | + $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
| 237 | + $statement->bindValue(':lastactive', $this->lastactive); |
|
| 238 | + $statement->bindValue(':forcelogout', $this->forcelogout); |
|
| 239 | + $statement->bindValue(':forceidentified', $this->forceidentified); |
|
| 240 | + $statement->bindValue(':welcome_template', $this->welcome_template); |
|
| 241 | + $statement->bindValue(':abortpref', $this->abortpref); |
|
| 242 | + $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
| 243 | + $statement->bindValue(':emailsig', $this->emailsig); |
|
| 244 | + $statement->bindValue(':creationmode', $this->creationmode); |
|
| 245 | + $statement->bindValue(':skin', $this->skin); |
|
| 246 | + |
|
| 247 | + if (!$statement->execute()) { |
|
| 248 | + throw new Exception($statement->errorInfo()); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + if ($statement->rowCount() !== 1) { |
|
| 252 | + throw new OptimisticLockFailedException(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $this->updateversion++; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + #region properties |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Gets the tool username |
|
| 263 | + * @return string |
|
| 264 | + */ |
|
| 265 | + public function getUsername() |
|
| 266 | + { |
|
| 267 | + return $this->username; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Sets the tool username |
|
| 272 | + * |
|
| 273 | + * @param string $username |
|
| 274 | + */ |
|
| 275 | + public function setUsername($username) |
|
| 276 | + { |
|
| 277 | + $this->username = $username; |
|
| 278 | + |
|
| 279 | + // If this isn't a brand new user, then it's a rename, force the logout |
|
| 280 | + if (!$this->isNew()) { |
|
| 281 | + $this->forcelogout = 1; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Gets the user's email address |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + public function getEmail() |
|
| 290 | + { |
|
| 291 | + return $this->email; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Sets the user's email address |
|
| 296 | + * |
|
| 297 | + * @param string $email |
|
| 298 | + */ |
|
| 299 | + public function setEmail($email) |
|
| 300 | + { |
|
| 301 | + $this->email = $email; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | + public function getStatus() |
|
| 309 | + { |
|
| 310 | + return $this->status; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @param string $status |
|
| 315 | + */ |
|
| 316 | + public function setStatus($status) |
|
| 317 | + { |
|
| 318 | + $this->status = $status; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Gets the user's on-wiki name |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + public function getOnWikiName() |
|
| 326 | + { |
|
| 327 | + return $this->onwikiname; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Sets the user's on-wiki name |
|
| 332 | + * |
|
| 333 | + * This can have interesting side-effects with OAuth. |
|
| 334 | + * |
|
| 335 | + * @param string $onWikiName |
|
| 336 | + */ |
|
| 337 | + public function setOnWikiName($onWikiName) |
|
| 338 | + { |
|
| 339 | + $this->onwikiname = $onWikiName; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Gets the welcome signature |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public function getWelcomeSig() |
|
| 347 | + { |
|
| 348 | + return $this->welcome_sig; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Sets the welcome signature |
|
| 353 | + * |
|
| 354 | + * @param string $welcomeSig |
|
| 355 | + */ |
|
| 356 | + public function setWelcomeSig($welcomeSig) |
|
| 357 | + { |
|
| 358 | + $this->welcome_sig = $welcomeSig; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Gets the last activity date for the user |
|
| 363 | + * |
|
| 364 | + * @return string |
|
| 365 | + * @todo This should probably return an instance of DateTime |
|
| 366 | + */ |
|
| 367 | + public function getLastActive() |
|
| 368 | + { |
|
| 369 | + return $this->lastactive; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Gets the user's forced logout status |
|
| 374 | + * |
|
| 375 | + * @return bool |
|
| 376 | + */ |
|
| 377 | + public function getForceLogout() |
|
| 378 | + { |
|
| 379 | + return $this->forcelogout == 1; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Sets the user's forced logout status |
|
| 384 | + * |
|
| 385 | + * @param bool $forceLogout |
|
| 386 | + */ |
|
| 387 | + public function setForceLogout($forceLogout) |
|
| 388 | + { |
|
| 389 | + $this->forcelogout = $forceLogout ? 1 : 0; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Returns the ID of the welcome template used. |
|
| 394 | + * @return int |
|
| 395 | + */ |
|
| 396 | + public function getWelcomeTemplate() |
|
| 397 | + { |
|
| 398 | + return $this->welcome_template; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Sets the ID of the welcome template used. |
|
| 403 | + * |
|
| 404 | + * @param int $welcomeTemplate |
|
| 405 | + */ |
|
| 406 | + public function setWelcomeTemplate($welcomeTemplate) |
|
| 407 | + { |
|
| 408 | + $this->welcome_template = $welcomeTemplate; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Gets the user's abort preference |
|
| 413 | + * @todo this is badly named too! Also a bool that's actually an int. |
|
| 414 | + * @return int |
|
| 415 | + */ |
|
| 416 | + public function getAbortPref() |
|
| 417 | + { |
|
| 418 | + return $this->abortpref; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Sets the user's abort preference |
|
| 423 | + * @todo rename, retype, and re-comment. |
|
| 424 | + * |
|
| 425 | + * @param int $abortPreference |
|
| 426 | + */ |
|
| 427 | + public function setAbortPref($abortPreference) |
|
| 428 | + { |
|
| 429 | + $this->abortpref = $abortPreference; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
| 434 | + * @return int the diff ID |
|
| 435 | + */ |
|
| 436 | + public function getConfirmationDiff() |
|
| 437 | + { |
|
| 438 | + return $this->confirmationdiff; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Sets the user's confirmation diff. |
|
| 443 | + * |
|
| 444 | + * @param int $confirmationDiff |
|
| 445 | + */ |
|
| 446 | + public function setConfirmationDiff($confirmationDiff) |
|
| 447 | + { |
|
| 448 | + $this->confirmationdiff = $confirmationDiff; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Gets the users' email signature used on outbound mail. |
|
| 453 | + * @todo rename me! |
|
| 454 | + * @return string |
|
| 455 | + */ |
|
| 456 | + public function getEmailSig() |
|
| 457 | + { |
|
| 458 | + return $this->emailsig; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Sets the user's email signature for outbound mail. |
|
| 463 | + * |
|
| 464 | + * @param string $emailSignature |
|
| 465 | + */ |
|
| 466 | + public function setEmailSig($emailSignature) |
|
| 467 | + { |
|
| 468 | + $this->emailsig = $emailSignature; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @return int |
|
| 473 | + */ |
|
| 474 | + public function getCreationMode() |
|
| 475 | + { |
|
| 476 | + return $this->creationmode; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * @param $creationMode int |
|
| 481 | + */ |
|
| 482 | + public function setCreationMode($creationMode) |
|
| 483 | + { |
|
| 484 | + $this->creationmode = $creationMode; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @return string |
|
| 489 | + */ |
|
| 490 | + public function getSkin() |
|
| 491 | + { |
|
| 492 | + return $this->skin; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @param $skin string |
|
| 497 | + */ |
|
| 498 | + public function setSkin($skin) |
|
| 499 | + { |
|
| 500 | + $this->skin = $skin; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + #endregion |
|
| 504 | + |
|
| 505 | + #region user access checks |
|
| 506 | + |
|
| 507 | + public function isActive() |
|
| 508 | + { |
|
| 509 | + return $this->status == self::STATUS_ACTIVE; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Tests if the user is identified |
|
| 514 | + * |
|
| 515 | + * @param IdentificationVerifier $iv |
|
| 516 | + * |
|
| 517 | + * @return bool |
|
| 518 | + * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
| 519 | + * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
| 520 | + * to play it safe for now. |
|
| 521 | + * @category Security-Critical |
|
| 522 | + */ |
|
| 523 | + public function isIdentified(IdentificationVerifier $iv) |
|
| 524 | + { |
|
| 525 | + if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
| 526 | + // User forced to unidentified in the database. |
|
| 527 | + return false; |
|
| 528 | + } |
|
| 529 | + elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 530 | + // User forced to identified in the database. |
|
| 531 | + return true; |
|
| 532 | + } |
|
| 533 | + else { |
|
| 534 | + // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 535 | + return $iv->isUserIdentified($this->getOnWikiName()); |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * DO NOT USE FOR TESTING IDENTIFICATION STATUS. |
|
| 541 | + * |
|
| 542 | + * @return bool|null |
|
| 543 | + */ |
|
| 544 | + public function getForceIdentified() { |
|
| 545 | + return $this->forceidentified; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Tests if the user is suspended |
|
| 550 | + * @return bool |
|
| 551 | + * @category Security-Critical |
|
| 552 | + */ |
|
| 553 | + public function isSuspended() |
|
| 554 | + { |
|
| 555 | + return $this->status == self::STATUS_SUSPENDED; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Tests if the user is new |
|
| 560 | + * @return bool |
|
| 561 | + * @category Security-Critical |
|
| 562 | + */ |
|
| 563 | + public function isNewUser() |
|
| 564 | + { |
|
| 565 | + return $this->status == self::STATUS_NEW; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Tests if the user has been declined access to the tool |
|
| 570 | + * @return bool |
|
| 571 | + * @category Security-Critical |
|
| 572 | + */ |
|
| 573 | + public function isDeclined() |
|
| 574 | + { |
|
| 575 | + return $this->status == self::STATUS_DECLINED; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Tests if the user is the community user |
|
| 580 | + * |
|
| 581 | + * @todo decide if this means logged out. I think it usually does. |
|
| 582 | + * @return bool |
|
| 583 | + * @category Security-Critical |
|
| 584 | + */ |
|
| 585 | + public function isCommunityUser() |
|
| 586 | + { |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + #endregion |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Gets the approval date of the user |
|
| 594 | + * @return DateTime|false |
|
| 595 | + */ |
|
| 596 | + public function getApprovalDate() |
|
| 597 | + { |
|
| 598 | + $query = $this->dbObject->prepare(<<<SQL |
|
| 599 | 599 | SELECT timestamp |
| 600 | 600 | FROM log |
| 601 | 601 | WHERE objectid = :userid |
@@ -604,12 +604,12 @@ discard block |
||
| 604 | 604 | ORDER BY id DESC |
| 605 | 605 | LIMIT 1; |
| 606 | 606 | SQL |
| 607 | - ); |
|
| 608 | - $query->execute(array(":userid" => $this->id)); |
|
| 607 | + ); |
|
| 608 | + $query->execute(array(":userid" => $this->id)); |
|
| 609 | 609 | |
| 610 | - $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
| 611 | - $query->closeCursor(); |
|
| 610 | + $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
| 611 | + $query->closeCursor(); |
|
| 612 | 612 | |
| 613 | - return $data; |
|
| 614 | - } |
|
| 613 | + return $data; |
|
| 614 | + } |
|
| 615 | 615 | } |
@@ -16,167 +16,167 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class CommunityUser extends User |
| 18 | 18 | { |
| 19 | - public function getId() |
|
| 20 | - { |
|
| 21 | - return -1; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function save() |
|
| 25 | - { |
|
| 26 | - // Do nothing |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - #region properties |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function getUsername() |
|
| 35 | - { |
|
| 36 | - global $communityUsername; |
|
| 37 | - |
|
| 38 | - return $communityUsername; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function setUsername($username) |
|
| 42 | - { |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - public function getEmail() |
|
| 49 | - { |
|
| 50 | - global $cDataClearEmail; |
|
| 51 | - |
|
| 52 | - return $cDataClearEmail; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function setEmail($email) |
|
| 56 | - { |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function getStatus() |
|
| 60 | - { |
|
| 61 | - return "Community"; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function getOnWikiName() |
|
| 65 | - { |
|
| 66 | - return "127.0.0.1"; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function setOnWikiName($onWikiName) |
|
| 70 | - { |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function getWelcomeSig() |
|
| 74 | - { |
|
| 75 | - return null; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function setWelcomeSig($welcomeSig) |
|
| 79 | - { |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function getLastActive() |
|
| 83 | - { |
|
| 84 | - $now = new DateTime(); |
|
| 85 | - |
|
| 86 | - return $now->format("Y-m-d H:i:s"); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function getForceLogout() |
|
| 90 | - { |
|
| 91 | - return true; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function setForceLogout($forceLogout) |
|
| 95 | - { |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param string $status |
|
| 100 | - */ |
|
| 101 | - public function setStatus($status) |
|
| 102 | - { |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function getWelcomeTemplate() |
|
| 106 | - { |
|
| 107 | - return 0; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public function setWelcomeTemplate($welcomeTemplate) |
|
| 111 | - { |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - public function getAbortPref() |
|
| 115 | - { |
|
| 116 | - return 0; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function setAbortPref($abortPreference) |
|
| 120 | - { |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function getConfirmationDiff() |
|
| 124 | - { |
|
| 125 | - return null; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function setConfirmationDiff($confirmationDiff) |
|
| 129 | - { |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function getEmailSig() |
|
| 133 | - { |
|
| 134 | - return null; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function setEmailSig($emailSignature) |
|
| 138 | - { |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function setUseAlternateSkin($useAlternate) |
|
| 142 | - { |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - #endregion |
|
| 146 | - |
|
| 147 | - #region user access checks |
|
| 148 | - |
|
| 149 | - public function isIdentified(IdentificationVerifier $iv) |
|
| 150 | - { |
|
| 151 | - return false; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - public function isSuspended() |
|
| 155 | - { |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - public function isNewUser() |
|
| 160 | - { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - public function isDeclined() |
|
| 165 | - { |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - public function isCommunityUser() |
|
| 170 | - { |
|
| 171 | - return true; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - #endregion |
|
| 175 | - |
|
| 176 | - public function getApprovalDate() |
|
| 177 | - { |
|
| 178 | - $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00"); |
|
| 179 | - |
|
| 180 | - return $data; |
|
| 181 | - } |
|
| 19 | + public function getId() |
|
| 20 | + { |
|
| 21 | + return -1; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function save() |
|
| 25 | + { |
|
| 26 | + // Do nothing |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + #region properties |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function getUsername() |
|
| 35 | + { |
|
| 36 | + global $communityUsername; |
|
| 37 | + |
|
| 38 | + return $communityUsername; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function setUsername($username) |
|
| 42 | + { |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + public function getEmail() |
|
| 49 | + { |
|
| 50 | + global $cDataClearEmail; |
|
| 51 | + |
|
| 52 | + return $cDataClearEmail; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function setEmail($email) |
|
| 56 | + { |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function getStatus() |
|
| 60 | + { |
|
| 61 | + return "Community"; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function getOnWikiName() |
|
| 65 | + { |
|
| 66 | + return "127.0.0.1"; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function setOnWikiName($onWikiName) |
|
| 70 | + { |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function getWelcomeSig() |
|
| 74 | + { |
|
| 75 | + return null; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function setWelcomeSig($welcomeSig) |
|
| 79 | + { |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function getLastActive() |
|
| 83 | + { |
|
| 84 | + $now = new DateTime(); |
|
| 85 | + |
|
| 86 | + return $now->format("Y-m-d H:i:s"); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function getForceLogout() |
|
| 90 | + { |
|
| 91 | + return true; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function setForceLogout($forceLogout) |
|
| 95 | + { |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param string $status |
|
| 100 | + */ |
|
| 101 | + public function setStatus($status) |
|
| 102 | + { |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function getWelcomeTemplate() |
|
| 106 | + { |
|
| 107 | + return 0; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public function setWelcomeTemplate($welcomeTemplate) |
|
| 111 | + { |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + public function getAbortPref() |
|
| 115 | + { |
|
| 116 | + return 0; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function setAbortPref($abortPreference) |
|
| 120 | + { |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function getConfirmationDiff() |
|
| 124 | + { |
|
| 125 | + return null; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function setConfirmationDiff($confirmationDiff) |
|
| 129 | + { |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function getEmailSig() |
|
| 133 | + { |
|
| 134 | + return null; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function setEmailSig($emailSignature) |
|
| 138 | + { |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function setUseAlternateSkin($useAlternate) |
|
| 142 | + { |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + #endregion |
|
| 146 | + |
|
| 147 | + #region user access checks |
|
| 148 | + |
|
| 149 | + public function isIdentified(IdentificationVerifier $iv) |
|
| 150 | + { |
|
| 151 | + return false; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + public function isSuspended() |
|
| 155 | + { |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + public function isNewUser() |
|
| 160 | + { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + public function isDeclined() |
|
| 165 | + { |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + public function isCommunityUser() |
|
| 170 | + { |
|
| 171 | + return true; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + #endregion |
|
| 175 | + |
|
| 176 | + public function getApprovalDate() |
|
| 177 | + { |
|
| 178 | + $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00"); |
|
| 179 | + |
|
| 180 | + return $data; |
|
| 181 | + } |
|
| 182 | 182 | } |