|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
|
4
|
|
|
* ACC Development Team. Please see team.json for a list of contributors. * |
|
5
|
|
|
* * |
|
6
|
|
|
* This is free and unencumbered software released into the public domain. * |
|
7
|
|
|
* Please see LICENSE.md for the full licencing statement. * |
|
8
|
|
|
******************************************************************************/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Waca\Pages\Request; |
|
11
|
|
|
|
|
12
|
|
|
use Exception; |
|
13
|
|
|
use Waca\DataObjects\Request; |
|
14
|
|
|
use Waca\Exceptions\ApplicationLogicException; |
|
15
|
|
|
use Waca\Exceptions\OptimisticLockFailedException; |
|
16
|
|
|
use Waca\Helpers\Logger; |
|
17
|
|
|
use Waca\RequestStatus; |
|
18
|
|
|
use Waca\Tasks\PublicInterfacePageBase; |
|
19
|
|
|
use Waca\WebRequest; |
|
20
|
|
|
|
|
21
|
|
|
class PageConfirmEmail extends PublicInterfacePageBase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Main function for this page, when no specific actions are called. |
|
25
|
|
|
* @throws ApplicationLogicException |
|
26
|
|
|
* @throws Exception |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function main() |
|
29
|
|
|
{ |
|
30
|
|
|
$id = WebRequest::getInt('id'); |
|
31
|
|
|
$si = WebRequest::getString('si'); |
|
32
|
|
|
|
|
33
|
|
|
if ($id === null || $si === null) { |
|
34
|
|
|
throw new ApplicationLogicException('Link incomplete - please double check the link you received.'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** @var Request|false $request */ |
|
38
|
|
|
$request = Request::getById($id, $this->getDatabase()); |
|
39
|
|
|
|
|
40
|
|
|
if ($request === false) { |
|
|
|
|
|
|
41
|
|
|
throw new ApplicationLogicException('Request not found'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if ($request->getEmailConfirm() === 'Confirmed') { |
|
45
|
|
|
// request has already been confirmed. Bomb out silently. |
|
46
|
|
|
$this->redirect('requestSubmitted'); |
|
47
|
|
|
|
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if ($request->getEmailConfirm() === $si) { |
|
52
|
|
|
$request->setEmailConfirm('Confirmed'); |
|
53
|
|
|
} |
|
54
|
|
|
else { |
|
55
|
|
|
throw new ApplicationLogicException('The confirmation value does not appear to match the expected value'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
try { |
|
59
|
|
|
$request->save(); |
|
60
|
|
|
} |
|
61
|
|
|
catch (OptimisticLockFailedException $ex) { |
|
62
|
|
|
// Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting |
|
63
|
|
|
// to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they |
|
64
|
|
|
// double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the |
|
65
|
|
|
// case. |
|
66
|
|
|
|
|
67
|
|
|
$request = Request::getById($id, $this->getDatabase()); |
|
68
|
|
|
if ($request->getEmailConfirm() === 'Confirmed') { |
|
|
|
|
|
|
69
|
|
|
// we've already done the sanity checks above |
|
70
|
|
|
|
|
71
|
|
|
$this->redirect('requestSubmitted'); |
|
72
|
|
|
|
|
73
|
|
|
// skip the log and notification |
|
74
|
|
|
return; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// something really weird happened. Another race condition? |
|
78
|
|
|
throw $ex; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
Logger::emailConfirmed($this->getDatabase(), $request); |
|
82
|
|
|
|
|
83
|
|
|
if ($request->getStatus() != RequestStatus::CLOSED) { |
|
84
|
|
|
$this->getNotificationHelper()->requestReceived($request); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$this->redirect('requestSubmitted'); |
|
88
|
|
|
} |
|
89
|
|
|
} |