@@ -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 |
@@ -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 |
@@ -14,14 +14,14 @@ |
||
| 14 | 14 | |
| 15 | 15 | class UserCreationTask extends CreationTaskBase |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @return IMediaWikiClient |
|
| 19 | - */ |
|
| 20 | - protected function getMediaWikiClient() |
|
| 21 | - { |
|
| 22 | - $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
| 23 | - $this->getSiteConfiguration()); |
|
| 17 | + /** |
|
| 18 | + * @return IMediaWikiClient |
|
| 19 | + */ |
|
| 20 | + protected function getMediaWikiClient() |
|
| 21 | + { |
|
| 22 | + $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
| 23 | + $this->getSiteConfiguration()); |
|
| 24 | 24 | |
| 25 | - return $oauth; |
|
| 26 | - } |
|
| 25 | + return $oauth; |
|
| 26 | + } |
|
| 27 | 27 | } |
| 28 | 28 | \ No newline at end of file |
@@ -15,22 +15,22 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PageDropRequest extends PageCloseRequest |
| 17 | 17 | { |
| 18 | - protected function getTemplate(PdoDatabase $database) |
|
| 19 | - { |
|
| 20 | - return EmailTemplate::getDroppedTemplate(); |
|
| 21 | - } |
|
| 18 | + protected function getTemplate(PdoDatabase $database) |
|
| 19 | + { |
|
| 20 | + return EmailTemplate::getDroppedTemplate(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 24 | - { |
|
| 25 | - return false; |
|
| 26 | - } |
|
| 23 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 24 | + { |
|
| 25 | + return false; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 29 | - { |
|
| 30 | - return false; |
|
| 31 | - } |
|
| 28 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 29 | + { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 34 | - { |
|
| 35 | - } |
|
| 33 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 34 | + { |
|
| 35 | + } |
|
| 36 | 36 | } |
| 37 | 37 | \ No newline at end of file |
@@ -12,21 +12,21 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Page404 extends InternalPageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no actions are called. |
|
| 17 | - */ |
|
| 18 | - protected function main() |
|
| 19 | - { |
|
| 20 | - if (!headers_sent()) { |
|
| 21 | - header("HTTP/1.1 404 Not Found"); |
|
| 22 | - } |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no actions are called. |
|
| 17 | + */ |
|
| 18 | + protected function main() |
|
| 19 | + { |
|
| 20 | + if (!headers_sent()) { |
|
| 21 | + header("HTTP/1.1 404 Not Found"); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - $this->skipAlerts(); |
|
| 25 | - $this->setTemplate("404.tpl"); |
|
| 26 | - } |
|
| 24 | + $this->skipAlerts(); |
|
| 25 | + $this->setTemplate("404.tpl"); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - protected function isProtectedPage() |
|
| 29 | - { |
|
| 30 | - return false; |
|
| 31 | - } |
|
| 28 | + protected function isProtectedPage() |
|
| 29 | + { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -65,8 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $user = User::getByUsername($username, $database); |
| 68 | - } |
|
| 69 | - else { |
|
| 68 | + } else { |
|
| 70 | 69 | $user = User::getById($partialId, $database); |
| 71 | 70 | } |
| 72 | 71 | |
@@ -105,8 +104,7 @@ discard block |
||
| 105 | 104 | |
| 106 | 105 | return; |
| 107 | 106 | } |
| 108 | - } |
|
| 109 | - else { |
|
| 107 | + } else { |
|
| 110 | 108 | $this->assign('showSignIn', true); |
| 111 | 109 | |
| 112 | 110 | $this->setupPartial(); |
@@ -131,8 +129,7 @@ discard block |
||
| 131 | 129 | if (WebRequest::isHttps()) { |
| 132 | 130 | // Client can clearly use HTTPS, so let's enforce it for all connections. |
| 133 | 131 | $this->headerQueue[] = "Strict-Transport-Security: max-age=15768000"; |
| 134 | - } |
|
| 135 | - else { |
|
| 132 | + } else { |
|
| 136 | 133 | // This is the login form, not the request form. We need protection here. |
| 137 | 134 | $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
| 138 | 135 | |
@@ -166,8 +163,7 @@ discard block |
||
| 166 | 163 | $username = $this->partialUser->getUsername(); |
| 167 | 164 | |
| 168 | 165 | $this->setupAlternates($this->partialUser, $partialStage, $database); |
| 169 | - } |
|
| 170 | - else { |
|
| 166 | + } else { |
|
| 171 | 167 | // No, see if we've preloaded a username |
| 172 | 168 | $preloadUsername = WebRequest::getString('tplUsername'); |
| 173 | 169 | if ($preloadUsername !== null) { |
@@ -194,13 +190,11 @@ discard block |
||
| 194 | 190 | $redirectDestination = WebRequest::clearPostLoginRedirect(); |
| 195 | 191 | if ($redirectDestination !== null) { |
| 196 | 192 | $this->redirectUrl($redirectDestination); |
| 197 | - } |
|
| 198 | - else { |
|
| 193 | + } else { |
|
| 199 | 194 | if ($user->isNewUser()) { |
| 200 | 195 | // home page isn't allowed, go to preferences instead |
| 201 | 196 | $this->redirect('preferences'); |
| 202 | - } |
|
| 203 | - else { |
|
| 197 | + } else { |
|
| 204 | 198 | // go to the home page |
| 205 | 199 | $this->redirect(''); |
| 206 | 200 | } |
@@ -323,7 +317,8 @@ discard block |
||
| 323 | 317 | if (isset($types[$type])) { |
| 324 | 318 | $options = $types[$type]; |
| 325 | 319 | |
| 326 | - array_walk($options, function(&$val) { |
|
| 320 | + array_walk($options, function(&$val) |
|
| 321 | + { |
|
| 327 | 322 | $val = $this->names[$val]; |
| 328 | 323 | }); |
| 329 | 324 | |
@@ -21,310 +21,310 @@ |
||
| 21 | 21 | |
| 22 | 22 | abstract class LoginCredentialPageBase extends InternalPageBase |
| 23 | 23 | { |
| 24 | - /** @var User */ |
|
| 25 | - protected $partialUser = null; |
|
| 26 | - protected $nextPageMap = array( |
|
| 27 | - 'yubikeyotp' => 'otp', |
|
| 28 | - 'totp' => 'otp', |
|
| 29 | - 'scratch' => 'otp', |
|
| 30 | - ); |
|
| 31 | - protected $names = array( |
|
| 32 | - 'yubikeyotp' => 'Yubikey OTP', |
|
| 33 | - 'totp' => 'TOTP (phone code generator)', |
|
| 34 | - 'scratch' => 'scratch token', |
|
| 35 | - ); |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Main function for this page, when no specific actions are called. |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - protected function main() |
|
| 42 | - { |
|
| 43 | - if (!$this->enforceHttps()) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - if (WebRequest::wasPosted()) { |
|
| 48 | - $this->validateCSRFToken(); |
|
| 49 | - |
|
| 50 | - $database = $this->getDatabase(); |
|
| 51 | - try { |
|
| 52 | - list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
| 53 | - |
|
| 54 | - if ($partialStage === null) { |
|
| 55 | - $partialStage = 1; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if ($partialId === null) { |
|
| 59 | - $username = WebRequest::postString('username'); |
|
| 60 | - |
|
| 61 | - if ($username === null || trim($username) === '') { |
|
| 62 | - throw new ApplicationLogicException('No username specified.'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $user = User::getByUsername($username, $database); |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - $user = User::getById($partialId, $database); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if ($user === false) { |
|
| 72 | - throw new ApplicationLogicException("Authentication failed"); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $authMan = new AuthenticationManager($database, $this->getSiteConfiguration(), |
|
| 76 | - $this->getHttpHelper()); |
|
| 77 | - |
|
| 78 | - $credential = $this->getProviderCredentials(); |
|
| 79 | - |
|
| 80 | - $authResult = $authMan->authenticate($user, $credential, $partialStage); |
|
| 81 | - |
|
| 82 | - if ($authResult === AuthenticationManager::AUTH_FAIL) { |
|
| 83 | - throw new ApplicationLogicException("Authentication failed"); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($authResult === AuthenticationManager::AUTH_REQUIRE_NEXT_STAGE) { |
|
| 87 | - $this->processJumpNextStage($user, $partialStage, $database); |
|
| 88 | - |
|
| 89 | - return; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if ($authResult === AuthenticationManager::AUTH_OK) { |
|
| 93 | - $this->processLoginSuccess($user); |
|
| 94 | - |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - catch (ApplicationLogicException $ex) { |
|
| 99 | - WebRequest::clearAuthPartialLogin(); |
|
| 100 | - |
|
| 101 | - SessionAlert::error($ex->getMessage()); |
|
| 102 | - $this->redirect('login'); |
|
| 103 | - |
|
| 104 | - return; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - else { |
|
| 108 | - $this->assign('showSignIn', true); |
|
| 109 | - |
|
| 110 | - $this->setupPartial(); |
|
| 111 | - $this->assignCSRFToken(); |
|
| 112 | - $this->providerSpecificSetup(); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - protected function isProtectedPage() |
|
| 117 | - { |
|
| 118 | - return false; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Enforces HTTPS on the login form |
|
| 123 | - * |
|
| 124 | - * @return bool |
|
| 125 | - */ |
|
| 126 | - private function enforceHttps() |
|
| 127 | - { |
|
| 128 | - if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) { |
|
| 129 | - if (WebRequest::isHttps()) { |
|
| 130 | - // Client can clearly use HTTPS, so let's enforce it for all connections. |
|
| 131 | - $this->headerQueue[] = "Strict-Transport-Security: max-age=15768000"; |
|
| 132 | - } |
|
| 133 | - else { |
|
| 134 | - // This is the login form, not the request form. We need protection here. |
|
| 135 | - $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
| 136 | - |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return true; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - protected abstract function providerSpecificSetup(); |
|
| 145 | - |
|
| 146 | - protected function setupPartial() |
|
| 147 | - { |
|
| 148 | - $database = $this->getDatabase(); |
|
| 149 | - |
|
| 150 | - // default stuff |
|
| 151 | - $this->assign('alternatives', array()); // 'u2f' => array('U2F token'), 'otp' => array('TOTP', 'scratch', 'yubiotp'))); |
|
| 152 | - |
|
| 153 | - // is this stage one? |
|
| 154 | - list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
| 155 | - if ($partialStage === null || $partialId === null) { |
|
| 156 | - WebRequest::clearAuthPartialLogin(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // Check to see if we have a partial login in progress |
|
| 160 | - $username = null; |
|
| 161 | - if ($partialId !== null) { |
|
| 162 | - // Yes, enforce this username |
|
| 163 | - $this->partialUser = User::getById($partialId, $database); |
|
| 164 | - $username = $this->partialUser->getUsername(); |
|
| 165 | - |
|
| 166 | - $this->setupAlternates($this->partialUser, $partialStage, $database); |
|
| 167 | - } |
|
| 168 | - else { |
|
| 169 | - // No, see if we've preloaded a username |
|
| 170 | - $preloadUsername = WebRequest::getString('tplUsername'); |
|
| 171 | - if ($preloadUsername !== null) { |
|
| 172 | - $username = $preloadUsername; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - if ($partialStage === null) { |
|
| 177 | - $partialStage = 1; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $this->assign('partialStage', $partialStage); |
|
| 181 | - $this->assign('username', $username); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Redirect the user back to wherever they came from after a successful login |
|
| 186 | - * |
|
| 187 | - * @param User $user |
|
| 188 | - */ |
|
| 189 | - protected function goBackWhenceYouCame(User $user) |
|
| 190 | - { |
|
| 191 | - // Redirect to wherever the user came from |
|
| 192 | - $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
| 193 | - if ($redirectDestination !== null) { |
|
| 194 | - $this->redirectUrl($redirectDestination); |
|
| 195 | - } |
|
| 196 | - else { |
|
| 197 | - if ($user->isNewUser()) { |
|
| 198 | - // home page isn't allowed, go to preferences instead |
|
| 199 | - $this->redirect('preferences'); |
|
| 200 | - } |
|
| 201 | - else { |
|
| 202 | - // go to the home page |
|
| 203 | - $this->redirect(''); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - private function processLoginSuccess(User $user) |
|
| 209 | - { |
|
| 210 | - // Touch force logout |
|
| 211 | - $user->setForceLogout(false); |
|
| 212 | - $user->save(); |
|
| 213 | - |
|
| 214 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
| 215 | - $this->getSiteConfiguration()); |
|
| 216 | - |
|
| 217 | - if ($oauth->isFullyLinked()) { |
|
| 218 | - try { |
|
| 219 | - // Reload the user's identity ticket. |
|
| 220 | - $oauth->refreshIdentity(); |
|
| 221 | - |
|
| 222 | - // Check for blocks |
|
| 223 | - if ($oauth->getIdentity()->getBlocked()) { |
|
| 224 | - // blocked! |
|
| 225 | - SessionAlert::error("You are currently blocked on-wiki. You will not be able to log in until you are unblocked."); |
|
| 226 | - $this->redirect('login'); |
|
| 227 | - |
|
| 228 | - return; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - catch (OAuthException $ex) { |
|
| 232 | - // Oops. Refreshing ticket failed. Force a re-auth. |
|
| 233 | - $authoriseUrl = $oauth->getRequestToken(); |
|
| 234 | - WebRequest::setOAuthPartialLogin($user); |
|
| 235 | - $this->redirectUrl($authoriseUrl); |
|
| 236 | - |
|
| 237 | - return; |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - if (($this->getSiteConfiguration()->getEnforceOAuth() && !$oauth->isFullyLinked()) |
|
| 242 | - || $oauth->isPartiallyLinked() |
|
| 243 | - ) { |
|
| 244 | - $authoriseUrl = $oauth->getRequestToken(); |
|
| 245 | - WebRequest::setOAuthPartialLogin($user); |
|
| 246 | - $this->redirectUrl($authoriseUrl); |
|
| 247 | - |
|
| 248 | - return; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - WebRequest::setLoggedInUser($user); |
|
| 252 | - $this->getDomainAccessManager()->switchToDefaultDomain($user); |
|
| 253 | - |
|
| 254 | - $this->goBackWhenceYouCame($user); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - protected abstract function getProviderCredentials(); |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @param User $user |
|
| 261 | - * @param int $partialStage |
|
| 262 | - * @param PdoDatabase $database |
|
| 263 | - * |
|
| 264 | - * @throws ApplicationLogicException |
|
| 265 | - */ |
|
| 266 | - private function processJumpNextStage(User $user, $partialStage, PdoDatabase $database) |
|
| 267 | - { |
|
| 268 | - WebRequest::setAuthPartialLogin($user->getId(), $partialStage + 1); |
|
| 269 | - |
|
| 270 | - $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
|
| 271 | - $statement = $database->prepare($sql); |
|
| 272 | - $statement->execute(array(':user' => $user->getId(), ':stage' => $partialStage + 1)); |
|
| 273 | - $nextStage = $statement->fetchColumn(); |
|
| 274 | - $statement->closeCursor(); |
|
| 275 | - |
|
| 276 | - if (!isset($this->nextPageMap[$nextStage])) { |
|
| 277 | - throw new ApplicationLogicException('Unknown page handler for next authentication stage.'); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - private function setupAlternates(User $user, $partialStage, PdoDatabase $database) |
|
| 284 | - { |
|
| 285 | - // get the providers available |
|
| 286 | - $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0'; |
|
| 287 | - $statement = $database->prepare($sql); |
|
| 288 | - $statement->execute(array(':user' => $user->getId(), ':stage' => $partialStage)); |
|
| 289 | - $alternates = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
| 290 | - |
|
| 291 | - $types = array(); |
|
| 292 | - foreach ($alternates as $item) { |
|
| 293 | - $type = $this->nextPageMap[$item]; |
|
| 294 | - if (!isset($types[$type])) { |
|
| 295 | - $types[$type] = array(); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $types[$type][] = $item; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - $userOptions = array(); |
|
| 302 | - if (get_called_class() !== PageOtpLogin::class) { |
|
| 303 | - $userOptions = array_merge($userOptions, $this->setupUserOptionsForType($types, 'otp', $userOptions)); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $this->assign('alternatives', $userOptions); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * @param $types |
|
| 311 | - * @param $type |
|
| 312 | - * @param $userOptions |
|
| 313 | - * |
|
| 314 | - * @return mixed |
|
| 315 | - */ |
|
| 316 | - private function setupUserOptionsForType($types, $type, $userOptions) |
|
| 317 | - { |
|
| 318 | - if (isset($types[$type])) { |
|
| 319 | - $options = $types[$type]; |
|
| 320 | - |
|
| 321 | - array_walk($options, function(&$val) { |
|
| 322 | - $val = $this->names[$val]; |
|
| 323 | - }); |
|
| 324 | - |
|
| 325 | - $userOptions[$type] = $options; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - return $userOptions; |
|
| 329 | - } |
|
| 24 | + /** @var User */ |
|
| 25 | + protected $partialUser = null; |
|
| 26 | + protected $nextPageMap = array( |
|
| 27 | + 'yubikeyotp' => 'otp', |
|
| 28 | + 'totp' => 'otp', |
|
| 29 | + 'scratch' => 'otp', |
|
| 30 | + ); |
|
| 31 | + protected $names = array( |
|
| 32 | + 'yubikeyotp' => 'Yubikey OTP', |
|
| 33 | + 'totp' => 'TOTP (phone code generator)', |
|
| 34 | + 'scratch' => 'scratch token', |
|
| 35 | + ); |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Main function for this page, when no specific actions are called. |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + protected function main() |
|
| 42 | + { |
|
| 43 | + if (!$this->enforceHttps()) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + if (WebRequest::wasPosted()) { |
|
| 48 | + $this->validateCSRFToken(); |
|
| 49 | + |
|
| 50 | + $database = $this->getDatabase(); |
|
| 51 | + try { |
|
| 52 | + list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
| 53 | + |
|
| 54 | + if ($partialStage === null) { |
|
| 55 | + $partialStage = 1; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if ($partialId === null) { |
|
| 59 | + $username = WebRequest::postString('username'); |
|
| 60 | + |
|
| 61 | + if ($username === null || trim($username) === '') { |
|
| 62 | + throw new ApplicationLogicException('No username specified.'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $user = User::getByUsername($username, $database); |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + $user = User::getById($partialId, $database); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if ($user === false) { |
|
| 72 | + throw new ApplicationLogicException("Authentication failed"); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $authMan = new AuthenticationManager($database, $this->getSiteConfiguration(), |
|
| 76 | + $this->getHttpHelper()); |
|
| 77 | + |
|
| 78 | + $credential = $this->getProviderCredentials(); |
|
| 79 | + |
|
| 80 | + $authResult = $authMan->authenticate($user, $credential, $partialStage); |
|
| 81 | + |
|
| 82 | + if ($authResult === AuthenticationManager::AUTH_FAIL) { |
|
| 83 | + throw new ApplicationLogicException("Authentication failed"); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($authResult === AuthenticationManager::AUTH_REQUIRE_NEXT_STAGE) { |
|
| 87 | + $this->processJumpNextStage($user, $partialStage, $database); |
|
| 88 | + |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if ($authResult === AuthenticationManager::AUTH_OK) { |
|
| 93 | + $this->processLoginSuccess($user); |
|
| 94 | + |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + catch (ApplicationLogicException $ex) { |
|
| 99 | + WebRequest::clearAuthPartialLogin(); |
|
| 100 | + |
|
| 101 | + SessionAlert::error($ex->getMessage()); |
|
| 102 | + $this->redirect('login'); |
|
| 103 | + |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + else { |
|
| 108 | + $this->assign('showSignIn', true); |
|
| 109 | + |
|
| 110 | + $this->setupPartial(); |
|
| 111 | + $this->assignCSRFToken(); |
|
| 112 | + $this->providerSpecificSetup(); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + protected function isProtectedPage() |
|
| 117 | + { |
|
| 118 | + return false; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Enforces HTTPS on the login form |
|
| 123 | + * |
|
| 124 | + * @return bool |
|
| 125 | + */ |
|
| 126 | + private function enforceHttps() |
|
| 127 | + { |
|
| 128 | + if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) { |
|
| 129 | + if (WebRequest::isHttps()) { |
|
| 130 | + // Client can clearly use HTTPS, so let's enforce it for all connections. |
|
| 131 | + $this->headerQueue[] = "Strict-Transport-Security: max-age=15768000"; |
|
| 132 | + } |
|
| 133 | + else { |
|
| 134 | + // This is the login form, not the request form. We need protection here. |
|
| 135 | + $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
| 136 | + |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + protected abstract function providerSpecificSetup(); |
|
| 145 | + |
|
| 146 | + protected function setupPartial() |
|
| 147 | + { |
|
| 148 | + $database = $this->getDatabase(); |
|
| 149 | + |
|
| 150 | + // default stuff |
|
| 151 | + $this->assign('alternatives', array()); // 'u2f' => array('U2F token'), 'otp' => array('TOTP', 'scratch', 'yubiotp'))); |
|
| 152 | + |
|
| 153 | + // is this stage one? |
|
| 154 | + list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
| 155 | + if ($partialStage === null || $partialId === null) { |
|
| 156 | + WebRequest::clearAuthPartialLogin(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // Check to see if we have a partial login in progress |
|
| 160 | + $username = null; |
|
| 161 | + if ($partialId !== null) { |
|
| 162 | + // Yes, enforce this username |
|
| 163 | + $this->partialUser = User::getById($partialId, $database); |
|
| 164 | + $username = $this->partialUser->getUsername(); |
|
| 165 | + |
|
| 166 | + $this->setupAlternates($this->partialUser, $partialStage, $database); |
|
| 167 | + } |
|
| 168 | + else { |
|
| 169 | + // No, see if we've preloaded a username |
|
| 170 | + $preloadUsername = WebRequest::getString('tplUsername'); |
|
| 171 | + if ($preloadUsername !== null) { |
|
| 172 | + $username = $preloadUsername; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + if ($partialStage === null) { |
|
| 177 | + $partialStage = 1; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $this->assign('partialStage', $partialStage); |
|
| 181 | + $this->assign('username', $username); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Redirect the user back to wherever they came from after a successful login |
|
| 186 | + * |
|
| 187 | + * @param User $user |
|
| 188 | + */ |
|
| 189 | + protected function goBackWhenceYouCame(User $user) |
|
| 190 | + { |
|
| 191 | + // Redirect to wherever the user came from |
|
| 192 | + $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
| 193 | + if ($redirectDestination !== null) { |
|
| 194 | + $this->redirectUrl($redirectDestination); |
|
| 195 | + } |
|
| 196 | + else { |
|
| 197 | + if ($user->isNewUser()) { |
|
| 198 | + // home page isn't allowed, go to preferences instead |
|
| 199 | + $this->redirect('preferences'); |
|
| 200 | + } |
|
| 201 | + else { |
|
| 202 | + // go to the home page |
|
| 203 | + $this->redirect(''); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + private function processLoginSuccess(User $user) |
|
| 209 | + { |
|
| 210 | + // Touch force logout |
|
| 211 | + $user->setForceLogout(false); |
|
| 212 | + $user->save(); |
|
| 213 | + |
|
| 214 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
| 215 | + $this->getSiteConfiguration()); |
|
| 216 | + |
|
| 217 | + if ($oauth->isFullyLinked()) { |
|
| 218 | + try { |
|
| 219 | + // Reload the user's identity ticket. |
|
| 220 | + $oauth->refreshIdentity(); |
|
| 221 | + |
|
| 222 | + // Check for blocks |
|
| 223 | + if ($oauth->getIdentity()->getBlocked()) { |
|
| 224 | + // blocked! |
|
| 225 | + SessionAlert::error("You are currently blocked on-wiki. You will not be able to log in until you are unblocked."); |
|
| 226 | + $this->redirect('login'); |
|
| 227 | + |
|
| 228 | + return; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + catch (OAuthException $ex) { |
|
| 232 | + // Oops. Refreshing ticket failed. Force a re-auth. |
|
| 233 | + $authoriseUrl = $oauth->getRequestToken(); |
|
| 234 | + WebRequest::setOAuthPartialLogin($user); |
|
| 235 | + $this->redirectUrl($authoriseUrl); |
|
| 236 | + |
|
| 237 | + return; |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + if (($this->getSiteConfiguration()->getEnforceOAuth() && !$oauth->isFullyLinked()) |
|
| 242 | + || $oauth->isPartiallyLinked() |
|
| 243 | + ) { |
|
| 244 | + $authoriseUrl = $oauth->getRequestToken(); |
|
| 245 | + WebRequest::setOAuthPartialLogin($user); |
|
| 246 | + $this->redirectUrl($authoriseUrl); |
|
| 247 | + |
|
| 248 | + return; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + WebRequest::setLoggedInUser($user); |
|
| 252 | + $this->getDomainAccessManager()->switchToDefaultDomain($user); |
|
| 253 | + |
|
| 254 | + $this->goBackWhenceYouCame($user); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + protected abstract function getProviderCredentials(); |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @param User $user |
|
| 261 | + * @param int $partialStage |
|
| 262 | + * @param PdoDatabase $database |
|
| 263 | + * |
|
| 264 | + * @throws ApplicationLogicException |
|
| 265 | + */ |
|
| 266 | + private function processJumpNextStage(User $user, $partialStage, PdoDatabase $database) |
|
| 267 | + { |
|
| 268 | + WebRequest::setAuthPartialLogin($user->getId(), $partialStage + 1); |
|
| 269 | + |
|
| 270 | + $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
|
| 271 | + $statement = $database->prepare($sql); |
|
| 272 | + $statement->execute(array(':user' => $user->getId(), ':stage' => $partialStage + 1)); |
|
| 273 | + $nextStage = $statement->fetchColumn(); |
|
| 274 | + $statement->closeCursor(); |
|
| 275 | + |
|
| 276 | + if (!isset($this->nextPageMap[$nextStage])) { |
|
| 277 | + throw new ApplicationLogicException('Unknown page handler for next authentication stage.'); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + private function setupAlternates(User $user, $partialStage, PdoDatabase $database) |
|
| 284 | + { |
|
| 285 | + // get the providers available |
|
| 286 | + $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0'; |
|
| 287 | + $statement = $database->prepare($sql); |
|
| 288 | + $statement->execute(array(':user' => $user->getId(), ':stage' => $partialStage)); |
|
| 289 | + $alternates = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
| 290 | + |
|
| 291 | + $types = array(); |
|
| 292 | + foreach ($alternates as $item) { |
|
| 293 | + $type = $this->nextPageMap[$item]; |
|
| 294 | + if (!isset($types[$type])) { |
|
| 295 | + $types[$type] = array(); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $types[$type][] = $item; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + $userOptions = array(); |
|
| 302 | + if (get_called_class() !== PageOtpLogin::class) { |
|
| 303 | + $userOptions = array_merge($userOptions, $this->setupUserOptionsForType($types, 'otp', $userOptions)); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $this->assign('alternatives', $userOptions); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * @param $types |
|
| 311 | + * @param $type |
|
| 312 | + * @param $userOptions |
|
| 313 | + * |
|
| 314 | + * @return mixed |
|
| 315 | + */ |
|
| 316 | + private function setupUserOptionsForType($types, $type, $userOptions) |
|
| 317 | + { |
|
| 318 | + if (isset($types[$type])) { |
|
| 319 | + $options = $types[$type]; |
|
| 320 | + |
|
| 321 | + array_walk($options, function(&$val) { |
|
| 322 | + $val = $this->names[$val]; |
|
| 323 | + }); |
|
| 324 | + |
|
| 325 | + $userOptions[$type] = $options; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + return $userOptions; |
|
| 329 | + } |
|
| 330 | 330 | } |
@@ -13,18 +13,18 @@ |
||
| 13 | 13 | |
| 14 | 14 | class PageOtpLogin extends LoginCredentialPageBase |
| 15 | 15 | { |
| 16 | - protected function providerSpecificSetup() |
|
| 17 | - { |
|
| 18 | - $this->setTemplate('login/otp.tpl'); |
|
| 19 | - } |
|
| 16 | + protected function providerSpecificSetup() |
|
| 17 | + { |
|
| 18 | + $this->setTemplate('login/otp.tpl'); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - protected function getProviderCredentials() |
|
| 22 | - { |
|
| 23 | - $otp = WebRequest::postString("otp"); |
|
| 24 | - if ($otp === null || $otp === "") { |
|
| 25 | - throw new ApplicationLogicException("No one-time code specified"); |
|
| 26 | - } |
|
| 21 | + protected function getProviderCredentials() |
|
| 22 | + { |
|
| 23 | + $otp = WebRequest::postString("otp"); |
|
| 24 | + if ($otp === null || $otp === "") { |
|
| 25 | + throw new ApplicationLogicException("No one-time code specified"); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - return $otp; |
|
| 29 | - } |
|
| 28 | + return $otp; |
|
| 29 | + } |
|
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -116,8 +116,7 @@ |
||
| 116 | 116 | $redirectDestination = WebRequest::clearPostLoginRedirect(); |
| 117 | 117 | if ($redirectDestination !== null && !$user->isNewUser()) { |
| 118 | 118 | $this->redirectUrl($redirectDestination); |
| 119 | - } |
|
| 120 | - else { |
|
| 119 | + } else { |
|
| 121 | 120 | $this->redirect('preferences', null, null, 'internal.php'); |
| 122 | 121 | } |
| 123 | 122 | } |
@@ -18,93 +18,93 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageOAuthCallback extends InternalPageBase |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @return bool |
|
| 23 | - */ |
|
| 24 | - protected function isProtectedPage() |
|
| 25 | - { |
|
| 26 | - // This page is critical to ensuring OAuth functionality is operational. |
|
| 27 | - return false; |
|
| 28 | - } |
|
| 21 | + /** |
|
| 22 | + * @return bool |
|
| 23 | + */ |
|
| 24 | + protected function isProtectedPage() |
|
| 25 | + { |
|
| 26 | + // This page is critical to ensuring OAuth functionality is operational. |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Main function for this page, when no specific actions are called. |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - protected function main() |
|
| 35 | - { |
|
| 36 | - // This should never get hit except by URL manipulation. |
|
| 37 | - $this->redirect(''); |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Main function for this page, when no specific actions are called. |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + protected function main() |
|
| 35 | + { |
|
| 36 | + // This should never get hit except by URL manipulation. |
|
| 37 | + $this->redirect(''); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Registered endpoint for the account creation callback. |
|
| 42 | - * |
|
| 43 | - * If this ever gets hit, something is wrong somewhere. |
|
| 44 | - */ |
|
| 45 | - protected function create() |
|
| 46 | - { |
|
| 47 | - throw new Exception('OAuth account creation endpoint triggered.'); |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * Registered endpoint for the account creation callback. |
|
| 42 | + * |
|
| 43 | + * If this ever gets hit, something is wrong somewhere. |
|
| 44 | + */ |
|
| 45 | + protected function create() |
|
| 46 | + { |
|
| 47 | + throw new Exception('OAuth account creation endpoint triggered.'); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Callback entry point |
|
| 52 | - * @throws ApplicationLogicException |
|
| 53 | - * @throws OptimisticLockFailedException |
|
| 54 | - */ |
|
| 55 | - protected function authorise() |
|
| 56 | - { |
|
| 57 | - $oauthToken = WebRequest::getString('oauth_token'); |
|
| 58 | - $oauthVerifier = WebRequest::getString('oauth_verifier'); |
|
| 50 | + /** |
|
| 51 | + * Callback entry point |
|
| 52 | + * @throws ApplicationLogicException |
|
| 53 | + * @throws OptimisticLockFailedException |
|
| 54 | + */ |
|
| 55 | + protected function authorise() |
|
| 56 | + { |
|
| 57 | + $oauthToken = WebRequest::getString('oauth_token'); |
|
| 58 | + $oauthVerifier = WebRequest::getString('oauth_verifier'); |
|
| 59 | 59 | |
| 60 | - $this->doCallbackValidation($oauthToken, $oauthVerifier); |
|
| 60 | + $this->doCallbackValidation($oauthToken, $oauthVerifier); |
|
| 61 | 61 | |
| 62 | - $database = $this->getDatabase(); |
|
| 62 | + $database = $this->getDatabase(); |
|
| 63 | 63 | |
| 64 | - $user = OAuthUserHelper::findUserByRequestToken($oauthToken, $database); |
|
| 65 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 64 | + $user = OAuthUserHelper::findUserByRequestToken($oauthToken, $database); |
|
| 65 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 66 | 66 | |
| 67 | - try { |
|
| 68 | - $oauth->completeHandshake($oauthVerifier); |
|
| 69 | - } |
|
| 70 | - catch (CurlException $ex) { |
|
| 71 | - throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
| 72 | - } |
|
| 67 | + try { |
|
| 68 | + $oauth->completeHandshake($oauthVerifier); |
|
| 69 | + } |
|
| 70 | + catch (CurlException $ex) { |
|
| 71 | + throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - // OK, we're the same session that just did a partial login that was redirected to OAuth. Let's upgrade the |
|
| 75 | - // login to a full login |
|
| 76 | - if (WebRequest::getOAuthPartialLogin() === $user->getId()) { |
|
| 77 | - WebRequest::setLoggedInUser($user); |
|
| 78 | - $this->getDomainAccessManager()->switchToDefaultDomain($user); |
|
| 79 | - } |
|
| 74 | + // OK, we're the same session that just did a partial login that was redirected to OAuth. Let's upgrade the |
|
| 75 | + // login to a full login |
|
| 76 | + if (WebRequest::getOAuthPartialLogin() === $user->getId()) { |
|
| 77 | + WebRequest::setLoggedInUser($user); |
|
| 78 | + $this->getDomainAccessManager()->switchToDefaultDomain($user); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // My thinking is there are three cases here: |
|
| 82 | - // a) new user => redirect to prefs - it's the only thing they can access other than stats |
|
| 83 | - // b) existing user hit the connect button in prefs => redirect to prefs since it's where they were |
|
| 84 | - // c) existing user logging in => redirect to wherever they came from |
|
| 85 | - $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
| 86 | - if ($redirectDestination !== null && !$user->isNewUser()) { |
|
| 87 | - $this->redirectUrl($redirectDestination); |
|
| 88 | - } |
|
| 89 | - else { |
|
| 90 | - $this->redirect('preferences', null, null, 'internal.php'); |
|
| 91 | - } |
|
| 92 | - } |
|
| 81 | + // My thinking is there are three cases here: |
|
| 82 | + // a) new user => redirect to prefs - it's the only thing they can access other than stats |
|
| 83 | + // b) existing user hit the connect button in prefs => redirect to prefs since it's where they were |
|
| 84 | + // c) existing user logging in => redirect to wherever they came from |
|
| 85 | + $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
| 86 | + if ($redirectDestination !== null && !$user->isNewUser()) { |
|
| 87 | + $this->redirectUrl($redirectDestination); |
|
| 88 | + } |
|
| 89 | + else { |
|
| 90 | + $this->redirect('preferences', null, null, 'internal.php'); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @param string $oauthToken |
|
| 96 | - * @param string $oauthVerifier |
|
| 97 | - * |
|
| 98 | - * @throws ApplicationLogicException |
|
| 99 | - */ |
|
| 100 | - private function doCallbackValidation($oauthToken, $oauthVerifier) |
|
| 101 | - { |
|
| 102 | - if ($oauthToken === null) { |
|
| 103 | - throw new ApplicationLogicException('No token provided'); |
|
| 104 | - } |
|
| 94 | + /** |
|
| 95 | + * @param string $oauthToken |
|
| 96 | + * @param string $oauthVerifier |
|
| 97 | + * |
|
| 98 | + * @throws ApplicationLogicException |
|
| 99 | + */ |
|
| 100 | + private function doCallbackValidation($oauthToken, $oauthVerifier) |
|
| 101 | + { |
|
| 102 | + if ($oauthToken === null) { |
|
| 103 | + throw new ApplicationLogicException('No token provided'); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - if ($oauthVerifier === null) { |
|
| 107 | - throw new ApplicationLogicException('No oauth verifier provided.'); |
|
| 108 | - } |
|
| 109 | - } |
|
| 106 | + if ($oauthVerifier === null) { |
|
| 107 | + throw new ApplicationLogicException('No oauth verifier provided.'); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | \ No newline at end of file |