Completed
Push — newinternal ( 65a0f5...5b021c )
by Simon
08:29
created
includes/Pages/Statistics/StatsReservedRequests.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 
14 14
 class StatsReservedRequests extends InternalPageBase
15 15
 {
16
-    public function main()
17
-    {
18
-        $this->setHtmlTitle('Reserved Requests :: Statistics');
16
+	public function main()
17
+	{
18
+		$this->setHtmlTitle('Reserved Requests :: Statistics');
19 19
 
20
-        $query = <<<sql
20
+		$query = <<<sql
21 21
 SELECT
22 22
     p.id AS requestid,
23 23
     p.name AS name,
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
 WHERE reserved != 0;
30 30
 sql;
31 31
 
32
-        $database = $this->getDatabase();
33
-        $statement = $database->query($query);
34
-        $data = $statement->fetchAll(PDO::FETCH_ASSOC);
35
-        $this->assign('dataTable', $data);
36
-        $this->assign('statsPageTitle', 'All currently reserved requests');
37
-        $this->setTemplate('statistics/reserved-requests.tpl');
38
-    }
32
+		$database = $this->getDatabase();
33
+		$statement = $database->query($query);
34
+		$data = $statement->fetchAll(PDO::FETCH_ASSOC);
35
+		$this->assign('dataTable', $data);
36
+		$this->assign('statsPageTitle', 'All currently reserved requests');
37
+		$this->setTemplate('statistics/reserved-requests.tpl');
38
+	}
39 39
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageBreakReservation.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,79 +19,79 @@
 block discarded – undo
19 19
 
20 20
 class PageBreakReservation extends RequestActionBase
21 21
 {
22
-    protected function main()
23
-    {
24
-        $this->checkPosted();
25
-        $database = $this->getDatabase();
26
-        $request = $this->getRequest($database);
22
+	protected function main()
23
+	{
24
+		$this->checkPosted();
25
+		$database = $this->getDatabase();
26
+		$request = $this->getRequest($database);
27 27
 
28
-        if ($request->getReserved() === null) {
29
-            throw new ApplicationLogicException('Request is not reserved!');
30
-        }
28
+		if ($request->getReserved() === null) {
29
+			throw new ApplicationLogicException('Request is not reserved!');
30
+		}
31 31
 
32
-        $currentUser = User::getCurrent($database);
32
+		$currentUser = User::getCurrent($database);
33 33
 
34
-        if ($currentUser->getId() === $request->getReserved()) {
35
-            $this->doUnreserve($request, $database);
36
-        }
37
-        else {
38
-            // not the same user!
39
-            if ($this->barrierTest('force', $currentUser)) {
40
-                $this->doBreakReserve($request, $database);
41
-            }
42
-            else {
43
-                throw new AccessDeniedException($this->getSecurityManager());
44
-            }
45
-        }
46
-    }
34
+		if ($currentUser->getId() === $request->getReserved()) {
35
+			$this->doUnreserve($request, $database);
36
+		}
37
+		else {
38
+			// not the same user!
39
+			if ($this->barrierTest('force', $currentUser)) {
40
+				$this->doBreakReserve($request, $database);
41
+			}
42
+			else {
43
+				throw new AccessDeniedException($this->getSecurityManager());
44
+			}
45
+		}
46
+	}
47 47
 
48
-    /**
49
-     * @param Request     $request
50
-     * @param PdoDatabase $database
51
-     *
52
-     * @throws Exception
53
-     */
54
-    protected function doUnreserve(Request $request, PdoDatabase $database)
55
-    {
56
-        // same user! we allow people to unreserve their own stuff
57
-        $request->setReserved(null);
58
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
59
-        $request->save();
48
+	/**
49
+	 * @param Request     $request
50
+	 * @param PdoDatabase $database
51
+	 *
52
+	 * @throws Exception
53
+	 */
54
+	protected function doUnreserve(Request $request, PdoDatabase $database)
55
+	{
56
+		// same user! we allow people to unreserve their own stuff
57
+		$request->setReserved(null);
58
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
59
+		$request->save();
60 60
 
61
-        Logger::unreserve($database, $request);
62
-        $this->getNotificationHelper()->requestUnreserved($request);
61
+		Logger::unreserve($database, $request);
62
+		$this->getNotificationHelper()->requestUnreserved($request);
63 63
 
64
-        // Redirect home!
65
-        $this->redirect();
66
-    }
64
+		// Redirect home!
65
+		$this->redirect();
66
+	}
67 67
 
68
-    /**
69
-     * @param Request     $request
70
-     * @param PdoDatabase $database
71
-     *
72
-     * @throws Exception
73
-     */
74
-    protected function doBreakReserve(Request $request, PdoDatabase $database)
75
-    {
76
-        if (!WebRequest::postBoolean("confirm")) {
77
-            $this->assignCSRFToken();
68
+	/**
69
+	 * @param Request     $request
70
+	 * @param PdoDatabase $database
71
+	 *
72
+	 * @throws Exception
73
+	 */
74
+	protected function doBreakReserve(Request $request, PdoDatabase $database)
75
+	{
76
+		if (!WebRequest::postBoolean("confirm")) {
77
+			$this->assignCSRFToken();
78 78
 
79
-            $this->assign("request", $request->getId());
80
-            $this->assign("reservedUser", User::getById($request->getReserved(), $database));
81
-            $this->assign("updateversion", WebRequest::postInt('updateversion'));
79
+			$this->assign("request", $request->getId());
80
+			$this->assign("reservedUser", User::getById($request->getReserved(), $database));
81
+			$this->assign("updateversion", WebRequest::postInt('updateversion'));
82 82
 
83
-            $this->setTemplate("confirmations/breakreserve.tpl");
84
-        }
85
-        else {
86
-            $request->setReserved(null);
87
-            $request->setUpdateVersion(WebRequest::postInt('updateversion'));
88
-            $request->save();
83
+			$this->setTemplate("confirmations/breakreserve.tpl");
84
+		}
85
+		else {
86
+			$request->setReserved(null);
87
+			$request->setUpdateVersion(WebRequest::postInt('updateversion'));
88
+			$request->save();
89 89
 
90
-            Logger::breakReserve($database, $request);
91
-            $this->getNotificationHelper()->requestReserveBroken($request);
90
+			Logger::breakReserve($database, $request);
91
+			$this->getNotificationHelper()->requestReserveBroken($request);
92 92
 
93
-            // Redirect home!
94
-            $this->redirect();
95
-        }
96
-    }
93
+			// Redirect home!
94
+			$this->redirect();
95
+		}
96
+	}
97 97
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageComment.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -15,51 +15,51 @@
 block discarded – undo
15 15
 
16 16
 class PageComment extends RequestActionBase
17 17
 {
18
-    /**
19
-     * Main function for this page, when no specific actions are called.
20
-     * @return void
21
-     */
22
-    protected function main()
23
-    {
24
-        $this->checkPosted();
25
-        $database = $this->getDatabase();
26
-        $request = $this->getRequest($database);
18
+	/**
19
+	 * Main function for this page, when no specific actions are called.
20
+	 * @return void
21
+	 */
22
+	protected function main()
23
+	{
24
+		$this->checkPosted();
25
+		$database = $this->getDatabase();
26
+		$request = $this->getRequest($database);
27 27
 
28
-        $commentText = WebRequest::postString('comment');
29
-        if ($commentText === false || $commentText == '') {
30
-            $this->redirect('viewRequest', null, array('id' => $request->getId()));
28
+		$commentText = WebRequest::postString('comment');
29
+		if ($commentText === false || $commentText == '') {
30
+			$this->redirect('viewRequest', null, array('id' => $request->getId()));
31 31
 
32
-            return;
33
-        }
32
+			return;
33
+		}
34 34
 
35
-        //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter.
36
-        $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/';
37
-        $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/';
35
+		//Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter.
36
+		$ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/';
37
+		$ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/';
38 38
 
39
-        $overridePolicy = WebRequest::postBoolean('privpol-check-override');
39
+		$overridePolicy = WebRequest::postBoolean('privpol-check-override');
40 40
 
41
-        if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) {
42
-            $this->assignCSRFToken();
43
-            $this->assign("request", $request);
44
-            $this->assign("comment", $commentText);
45
-            $this->setTemplate("privpol-warning.tpl");
41
+		if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) {
42
+			$this->assignCSRFToken();
43
+			$this->assign("request", $request);
44
+			$this->assign("comment", $commentText);
45
+			$this->setTemplate("privpol-warning.tpl");
46 46
 
47
-            return;
48
-        }
47
+			return;
48
+		}
49 49
 
50
-        $visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user';
50
+		$visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user';
51 51
 
52
-        $comment = new Comment();
53
-        $comment->setDatabase($database);
52
+		$comment = new Comment();
53
+		$comment->setDatabase($database);
54 54
 
55
-        $comment->setRequest($request->getId());
56
-        $comment->setVisibility($visibility);
57
-        $comment->setUser(User::getCurrent($database)->getId());
58
-        $comment->setComment($commentText);
55
+		$comment->setRequest($request->getId());
56
+		$comment->setVisibility($visibility);
57
+		$comment->setUser(User::getCurrent($database)->getId());
58
+		$comment->setComment($commentText);
59 59
 
60
-        $comment->save();
60
+		$comment->save();
61 61
 
62
-        $this->getNotificationHelper()->commentCreated($comment, $request);
63
-        $this->redirect('viewRequest', null, array('id' => $request->getId()));
64
-    }
62
+		$this->getNotificationHelper()->commentCreated($comment, $request);
63
+		$this->redirect('viewRequest', null, array('id' => $request->getId()));
64
+	}
65 65
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageReservation.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -17,58 +17,58 @@
 block discarded – undo
17 17
 
18 18
 class PageReservation extends RequestActionBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     * @throws ApplicationLogicException
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->checkPosted();
27
-        $database = $this->getDatabase();
28
-        $request = $this->getRequest($database);
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 * @throws ApplicationLogicException
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->checkPosted();
27
+		$database = $this->getDatabase();
28
+		$request = $this->getRequest($database);
29 29
 
30
-        $closureDate = $request->getClosureDate();
30
+		$closureDate = $request->getClosureDate();
31 31
 
32
-        $date = new DateTime();
33
-        $date->modify("-7 days");
34
-        $oneweek = $date->format("Y-m-d H:i:s");
32
+		$date = new DateTime();
33
+		$date->modify("-7 days");
34
+		$oneweek = $date->format("Y-m-d H:i:s");
35 35
 
36
-        $currentUser = User::getCurrent($database);
37
-        if ($request->getStatus() == "Closed" && $closureDate < $oneweek) {
38
-            if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) {
39
-                throw new ApplicationLogicException(
40
-                    "You are not allowed to reserve a request that has been closed for over a week.");
41
-            }
42
-        }
36
+		$currentUser = User::getCurrent($database);
37
+		if ($request->getStatus() == "Closed" && $closureDate < $oneweek) {
38
+			if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) {
39
+				throw new ApplicationLogicException(
40
+					"You are not allowed to reserve a request that has been closed for over a week.");
41
+			}
42
+		}
43 43
 
44
-        if ($request->getReserved() !== null && $request->getReserved() != $currentUser->getId()) {
45
-            throw new ApplicationLogicException("Request is already reserved!");
46
-        }
44
+		if ($request->getReserved() !== null && $request->getReserved() != $currentUser->getId()) {
45
+			throw new ApplicationLogicException("Request is already reserved!");
46
+		}
47 47
 
48
-        if ($request->getReserved() === null) {
49
-            // Check the number of requests a user has reserved already
50
-            $doubleReserveCountQuery = $database->prepare("SELECT COUNT(*) FROM request WHERE reserved = :userid;");
51
-            $doubleReserveCountQuery->bindValue(":userid", $currentUser->getId());
52
-            $doubleReserveCountQuery->execute();
53
-            $doubleReserveCount = $doubleReserveCountQuery->fetchColumn();
54
-            $doubleReserveCountQuery->closeCursor();
48
+		if ($request->getReserved() === null) {
49
+			// Check the number of requests a user has reserved already
50
+			$doubleReserveCountQuery = $database->prepare("SELECT COUNT(*) FROM request WHERE reserved = :userid;");
51
+			$doubleReserveCountQuery->bindValue(":userid", $currentUser->getId());
52
+			$doubleReserveCountQuery->execute();
53
+			$doubleReserveCount = $doubleReserveCountQuery->fetchColumn();
54
+			$doubleReserveCountQuery->closeCursor();
55 55
 
56
-            // User already has at least one reserved.
57
-            if ($doubleReserveCount != 0) {
58
-                SessionAlert::warning("You have multiple requests reserved!");
59
-            }
56
+			// User already has at least one reserved.
57
+			if ($doubleReserveCount != 0) {
58
+				SessionAlert::warning("You have multiple requests reserved!");
59
+			}
60 60
 
61
-            $request->setReserved($currentUser->getId());
62
-            $request->setUpdateVersion(WebRequest::postInt('updateversion'));
63
-            $request->save();
61
+			$request->setReserved($currentUser->getId());
62
+			$request->setUpdateVersion(WebRequest::postInt('updateversion'));
63
+			$request->save();
64 64
 
65
-            Logger::reserve($database, $request);
65
+			Logger::reserve($database, $request);
66 66
 
67
-            $this->getNotificationHelper()->requestReserved($request);
67
+			$this->getNotificationHelper()->requestReserved($request);
68 68
 
69
-            SessionAlert::success("Reserved request {$request->getId()}.");
70
-        }
69
+			SessionAlert::success("Reserved request {$request->getId()}.");
70
+		}
71 71
 
72
-        $this->redirect('viewRequest', null, array('id' => $request->getId()));
73
-    }
72
+		$this->redirect('viewRequest', null, array('id' => $request->getId()));
73
+	}
74 74
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageDeferRequest.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -17,57 +17,57 @@
 block discarded – undo
17 17
 
18 18
 class PageDeferRequest extends RequestActionBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     * @throws ApplicationLogicException
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->checkPosted();
27
-        $database = $this->getDatabase();
28
-        $request = $this->getRequest($database);
29
-        $currentUser = User::getCurrent($database);
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 * @throws ApplicationLogicException
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->checkPosted();
27
+		$database = $this->getDatabase();
28
+		$request = $this->getRequest($database);
29
+		$currentUser = User::getCurrent($database);
30 30
 
31
-        $target = WebRequest::postString('target');
32
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
31
+		$target = WebRequest::postString('target');
32
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
33 33
 
34
-        if (!array_key_exists($target, $requestStates)) {
35
-            throw new ApplicationLogicException('Defer target not valid');
36
-        }
34
+		if (!array_key_exists($target, $requestStates)) {
35
+			throw new ApplicationLogicException('Defer target not valid');
36
+		}
37 37
 
38
-        if ($request->getStatus() == $target) {
39
-            SessionAlert::warning('This request is already in the specified queue.');
40
-            $this->redirect('viewRequest', null, array('id' => $request->getId()));
38
+		if ($request->getStatus() == $target) {
39
+			SessionAlert::warning('This request is already in the specified queue.');
40
+			$this->redirect('viewRequest', null, array('id' => $request->getId()));
41 41
 
42
-            return;
43
-        }
42
+			return;
43
+		}
44 44
 
45
-        $closureDate = $request->getClosureDate();
46
-        $date = new DateTime();
47
-        $date->modify("-7 days");
48
-        $oneweek = $date->format("Y-m-d H:i:s");
45
+		$closureDate = $request->getClosureDate();
46
+		$date = new DateTime();
47
+		$date->modify("-7 days");
48
+		$oneweek = $date->format("Y-m-d H:i:s");
49 49
 
50 50
 
51
-        if ($request->getStatus() == "Closed" && $closureDate < $oneweek) {
52
-            if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) {
53
-                throw new ApplicationLogicException(
54
-                    "You are not allowed to re-open a request that has been closed for over a week.");
55
-            }
56
-        }
51
+		if ($request->getStatus() == "Closed" && $closureDate < $oneweek) {
52
+			if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) {
53
+				throw new ApplicationLogicException(
54
+					"You are not allowed to re-open a request that has been closed for over a week.");
55
+			}
56
+		}
57 57
 
58
-        $request->setReserved(null);
59
-        $request->setStatus($target);
60
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
61
-        $request->save();
58
+		$request->setReserved(null);
59
+		$request->setStatus($target);
60
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
61
+		$request->save();
62 62
 
63
-        $deto = $requestStates[$target]['deferto'];
64
-        $detolog = $requestStates[$target]['defertolog'];
63
+		$deto = $requestStates[$target]['deferto'];
64
+		$detolog = $requestStates[$target]['defertolog'];
65 65
 
66
-        Logger::deferRequest($database, $request, $detolog);
66
+		Logger::deferRequest($database, $request, $detolog);
67 67
 
68
-        $this->getNotificationHelper()->requestDeferred($request);
69
-        SessionAlert::success("Request {$request->getId()} deferred to {$deto}");
68
+		$this->getNotificationHelper()->requestDeferred($request);
69
+		SessionAlert::success("Request {$request->getId()} deferred to {$deto}");
70 70
 
71
-        $this->redirect();
72
-    }
71
+		$this->redirect();
72
+	}
73 73
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageCustomClose.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -23,264 +23,264 @@
 block discarded – undo
23 23
 
24 24
 class PageCustomClose extends PageCloseRequest
25 25
 {
26
-    use RequestData;
27
-
28
-    protected function main()
29
-    {
30
-        $database = $this->getDatabase();
31
-
32
-        $request = $this->getRequest($database);
33
-        $currentUser = User::getCurrent($this->getDatabase());
34
-
35
-        if ($request->getStatus() === 'Closed') {
36
-            throw new ApplicationLogicException('Request is already closed');
37
-        }
38
-
39
-        // Dual-mode page
40
-        if (WebRequest::wasPosted()) {
41
-            $this->validateCSRFToken();
42
-            $this->doCustomClose($currentUser, $request, $database);
43
-
44
-            $this->redirect();
45
-        }
46
-        else {
47
-            $this->assignCSRFToken();
48
-            $this->showCustomCloseForm($database, $request);
49
-        }
50
-    }
51
-
52
-    /**
53
-     * @param $database
54
-     *
55
-     * @return Request
56
-     * @throws ApplicationLogicException
57
-     */
58
-    protected function getRequest(PdoDatabase $database)
59
-    {
60
-        $requestId = WebRequest::getInt('request');
61
-        if ($requestId === null) {
62
-            throw new ApplicationLogicException('Request ID not found');
63
-        }
64
-
65
-        /** @var Request $request */
66
-        $request = Request::getById($requestId, $database);
67
-
68
-        if ($request === false) {
69
-            throw new ApplicationLogicException('Request not found');
70
-        }
71
-
72
-        return $request;
73
-    }
74
-
75
-    /**
76
-     * @param PdoDatabase $database
77
-     *
78
-     * @return EmailTemplate|null
79
-     */
80
-    protected function getTemplate(PdoDatabase $database)
81
-    {
82
-        $templateId = WebRequest::getInt('template');
83
-        if ($templateId === null) {
84
-            return null;
85
-        }
86
-
87
-        /** @var EmailTemplate $template */
88
-        $template = EmailTemplate::getById($templateId, $database);
89
-        if ($template === false || !$template->getActive()) {
90
-            return null;
91
-        }
92
-
93
-        return $template;
94
-    }
95
-
96
-    /**
97
-     * @param $database
98
-     * @param $request
99
-     *
100
-     * @throws Exception
101
-     */
102
-    protected function showCustomCloseForm(PdoDatabase $database, Request $request)
103
-    {
104
-        $currentUser = User::getCurrent($database);
105
-        $config = $this->getSiteConfiguration();
106
-
107
-        $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
108
-        if (!$allowedPrivateData) {
109
-            // we probably shouldn't be showing the user this form if they're not allowed to access private data...
110
-            throw new AccessDeniedException($this->getSecurityManager());
111
-        }
112
-
113
-        $template = $this->getTemplate($database);
114
-
115
-        // Preload data
116
-        $this->assign('defaultAction', '');
117
-        $this->assign('preloadText', '');
118
-        $this->assign('preloadTitle', '');
119
-
120
-        if ($template !== null) {
121
-            $this->assign('defaultAction', $template->getDefaultAction());
122
-            $this->assign('preloadText', $template->getText());
123
-            $this->assign('preloadTitle', $template->getName());
124
-        }
125
-
126
-        // Static data
127
-        $this->assign('requeststates', $config->getRequestStates());
128
-
129
-        // request data
130
-        $this->assign('requestId', $request->getIp());
131
-        $this->assign('updateVersion', $request->getUpdateVersion());
132
-        $this->setupBasicData($request, $config);
133
-        $this->setupReservationDetails($request->getReserved(), $database, $currentUser);
134
-        $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
135
-
136
-        // IP location
137
-        $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
138
-        $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp));
139
-
140
-        // Confirmations
141
-        $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request));
142
-        $this->assign('confirmReserveOverride', $this->checkReserveOverride($request, $currentUser));
143
-
144
-        $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser));
145
-
146
-        // template
147
-        $this->setTemplate('custom-close.tpl');
148
-    }
149
-
150
-    /**
151
-     * @param User        $currentUser
152
-     * @param Request     $request
153
-     * @param PdoDatabase $database
154
-     *
155
-     * @throws ApplicationLogicException
156
-     */
157
-    protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database)
158
-    {
159
-        $messageBody = WebRequest::postString('msgbody');
160
-        if ($messageBody === null || trim($messageBody) === '') {
161
-            throw new ApplicationLogicException('Message body cannot be blank');
162
-        }
163
-
164
-        $ccMailingList = true;
165
-        if ($this->barrierTest('skipCcMailingList', $currentUser)) {
166
-            $ccMailingList = WebRequest::postBoolean('ccMailingList');
167
-        }
168
-
169
-        if ($request->getStatus() === 'Closed') {
170
-            throw new ApplicationLogicException('Request is already closed');
171
-        }
172
-
173
-        if (!(WebRequest::postBoolean('confirmEmailAlreadySent')
174
-            && WebRequest::postBoolean('confirmReserveOverride'))
175
-        ) {
176
-            throw new ApplicationLogicException('Not all confirmations checked');
177
-        }
178
-
179
-        $action = WebRequest::postString('action');
180
-        $availableRequestStates = $this->getSiteConfiguration()->getRequestStates();
181
-
182
-        if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) {
183
-            // Close request
184
-            $this->closeRequest($request, $database, $action, $messageBody);
185
-
186
-            // Send the mail after the save, since save can be rolled back
187
-            $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
188
-        }
189
-        else {
190
-            if (array_key_exists($action, $availableRequestStates)) {
191
-                // Defer to other state
192
-                $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody);
193
-
194
-                // Send the mail after the save, since save can be rolled back
195
-                $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
196
-            }
197
-            else {
198
-                $request->setReserved(null);
199
-                $request->setUpdateVersion(WebRequest::postInt('updateversion'));
200
-                $request->save();
201
-
202
-                // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
203
-                // and be rolled back.
204
-
205
-                // Send mail
206
-                $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
207
-
208
-                Logger::sentMail($database, $request, $messageBody);
209
-                Logger::unreserve($database, $request);
210
-
211
-                $this->getNotificationHelper()->sentMail($request);
212
-                SessionAlert::success("Sent mail to Request {$request->getId()}");
213
-            }
214
-        }
215
-    }
216
-
217
-    /**
218
-     * @param Request     $request
219
-     * @param PdoDatabase $database
220
-     * @param string      $action
221
-     * @param string      $messageBody
222
-     *
223
-     * @throws Exception
224
-     * @throws OptimisticLockFailedException
225
-     */
226
-    protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody)
227
-    {
228
-        $request->setStatus('Closed');
229
-        $request->setReserved(null);
230
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
231
-        $request->save();
232
-
233
-        // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and
234
-        // be rolled back.
235
-
236
-        if ($action == EmailTemplate::CREATED) {
237
-            $logCloseType = 'custom-y';
238
-            $notificationCloseType = "Custom, Created";
239
-        }
240
-        else {
241
-            $logCloseType = 'custom-n';
242
-            $notificationCloseType = "Custom, Not Created";
243
-        }
244
-
245
-        Logger::closeRequest($database, $request, $logCloseType, $messageBody);
246
-        $this->getNotificationHelper()->requestClosed($request, $notificationCloseType);
247
-
248
-        $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8');
249
-        SessionAlert::success("Request {$request->getId()} ({$requestName}) marked as 'Done'.");
250
-    }
251
-
252
-    /**
253
-     * @param Request     $request
254
-     * @param PdoDatabase $database
255
-     * @param string      $action
256
-     * @param             $availableRequestStates
257
-     * @param string      $messageBody
258
-     *
259
-     * @throws Exception
260
-     * @throws OptimisticLockFailedException
261
-     */
262
-    protected function deferRequest(
263
-        Request $request,
264
-        PdoDatabase $database,
265
-        $action,
266
-        $availableRequestStates,
267
-        $messageBody
268
-    ) {
269
-        $request->setStatus($action);
270
-        $request->setReserved(null);
271
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
272
-        $request->save();
273
-
274
-        // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
275
-        // and be rolled back.
276
-
277
-        $deferToLog = $availableRequestStates[$action]['defertolog'];
278
-        Logger::sentMail($database, $request, $messageBody);
279
-        Logger::deferRequest($database, $request, $deferToLog);
280
-
281
-        $this->getNotificationHelper()->requestDeferredWithMail($request);
282
-
283
-        $deferTo = $availableRequestStates[$action]['deferto'];
284
-        SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email.");
285
-    }
26
+	use RequestData;
27
+
28
+	protected function main()
29
+	{
30
+		$database = $this->getDatabase();
31
+
32
+		$request = $this->getRequest($database);
33
+		$currentUser = User::getCurrent($this->getDatabase());
34
+
35
+		if ($request->getStatus() === 'Closed') {
36
+			throw new ApplicationLogicException('Request is already closed');
37
+		}
38
+
39
+		// Dual-mode page
40
+		if (WebRequest::wasPosted()) {
41
+			$this->validateCSRFToken();
42
+			$this->doCustomClose($currentUser, $request, $database);
43
+
44
+			$this->redirect();
45
+		}
46
+		else {
47
+			$this->assignCSRFToken();
48
+			$this->showCustomCloseForm($database, $request);
49
+		}
50
+	}
51
+
52
+	/**
53
+	 * @param $database
54
+	 *
55
+	 * @return Request
56
+	 * @throws ApplicationLogicException
57
+	 */
58
+	protected function getRequest(PdoDatabase $database)
59
+	{
60
+		$requestId = WebRequest::getInt('request');
61
+		if ($requestId === null) {
62
+			throw new ApplicationLogicException('Request ID not found');
63
+		}
64
+
65
+		/** @var Request $request */
66
+		$request = Request::getById($requestId, $database);
67
+
68
+		if ($request === false) {
69
+			throw new ApplicationLogicException('Request not found');
70
+		}
71
+
72
+		return $request;
73
+	}
74
+
75
+	/**
76
+	 * @param PdoDatabase $database
77
+	 *
78
+	 * @return EmailTemplate|null
79
+	 */
80
+	protected function getTemplate(PdoDatabase $database)
81
+	{
82
+		$templateId = WebRequest::getInt('template');
83
+		if ($templateId === null) {
84
+			return null;
85
+		}
86
+
87
+		/** @var EmailTemplate $template */
88
+		$template = EmailTemplate::getById($templateId, $database);
89
+		if ($template === false || !$template->getActive()) {
90
+			return null;
91
+		}
92
+
93
+		return $template;
94
+	}
95
+
96
+	/**
97
+	 * @param $database
98
+	 * @param $request
99
+	 *
100
+	 * @throws Exception
101
+	 */
102
+	protected function showCustomCloseForm(PdoDatabase $database, Request $request)
103
+	{
104
+		$currentUser = User::getCurrent($database);
105
+		$config = $this->getSiteConfiguration();
106
+
107
+		$allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
108
+		if (!$allowedPrivateData) {
109
+			// we probably shouldn't be showing the user this form if they're not allowed to access private data...
110
+			throw new AccessDeniedException($this->getSecurityManager());
111
+		}
112
+
113
+		$template = $this->getTemplate($database);
114
+
115
+		// Preload data
116
+		$this->assign('defaultAction', '');
117
+		$this->assign('preloadText', '');
118
+		$this->assign('preloadTitle', '');
119
+
120
+		if ($template !== null) {
121
+			$this->assign('defaultAction', $template->getDefaultAction());
122
+			$this->assign('preloadText', $template->getText());
123
+			$this->assign('preloadTitle', $template->getName());
124
+		}
125
+
126
+		// Static data
127
+		$this->assign('requeststates', $config->getRequestStates());
128
+
129
+		// request data
130
+		$this->assign('requestId', $request->getIp());
131
+		$this->assign('updateVersion', $request->getUpdateVersion());
132
+		$this->setupBasicData($request, $config);
133
+		$this->setupReservationDetails($request->getReserved(), $database, $currentUser);
134
+		$this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
135
+
136
+		// IP location
137
+		$trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
138
+		$this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp));
139
+
140
+		// Confirmations
141
+		$this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request));
142
+		$this->assign('confirmReserveOverride', $this->checkReserveOverride($request, $currentUser));
143
+
144
+		$this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser));
145
+
146
+		// template
147
+		$this->setTemplate('custom-close.tpl');
148
+	}
149
+
150
+	/**
151
+	 * @param User        $currentUser
152
+	 * @param Request     $request
153
+	 * @param PdoDatabase $database
154
+	 *
155
+	 * @throws ApplicationLogicException
156
+	 */
157
+	protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database)
158
+	{
159
+		$messageBody = WebRequest::postString('msgbody');
160
+		if ($messageBody === null || trim($messageBody) === '') {
161
+			throw new ApplicationLogicException('Message body cannot be blank');
162
+		}
163
+
164
+		$ccMailingList = true;
165
+		if ($this->barrierTest('skipCcMailingList', $currentUser)) {
166
+			$ccMailingList = WebRequest::postBoolean('ccMailingList');
167
+		}
168
+
169
+		if ($request->getStatus() === 'Closed') {
170
+			throw new ApplicationLogicException('Request is already closed');
171
+		}
172
+
173
+		if (!(WebRequest::postBoolean('confirmEmailAlreadySent')
174
+			&& WebRequest::postBoolean('confirmReserveOverride'))
175
+		) {
176
+			throw new ApplicationLogicException('Not all confirmations checked');
177
+		}
178
+
179
+		$action = WebRequest::postString('action');
180
+		$availableRequestStates = $this->getSiteConfiguration()->getRequestStates();
181
+
182
+		if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) {
183
+			// Close request
184
+			$this->closeRequest($request, $database, $action, $messageBody);
185
+
186
+			// Send the mail after the save, since save can be rolled back
187
+			$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
188
+		}
189
+		else {
190
+			if (array_key_exists($action, $availableRequestStates)) {
191
+				// Defer to other state
192
+				$this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody);
193
+
194
+				// Send the mail after the save, since save can be rolled back
195
+				$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
196
+			}
197
+			else {
198
+				$request->setReserved(null);
199
+				$request->setUpdateVersion(WebRequest::postInt('updateversion'));
200
+				$request->save();
201
+
202
+				// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
203
+				// and be rolled back.
204
+
205
+				// Send mail
206
+				$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
207
+
208
+				Logger::sentMail($database, $request, $messageBody);
209
+				Logger::unreserve($database, $request);
210
+
211
+				$this->getNotificationHelper()->sentMail($request);
212
+				SessionAlert::success("Sent mail to Request {$request->getId()}");
213
+			}
214
+		}
215
+	}
216
+
217
+	/**
218
+	 * @param Request     $request
219
+	 * @param PdoDatabase $database
220
+	 * @param string      $action
221
+	 * @param string      $messageBody
222
+	 *
223
+	 * @throws Exception
224
+	 * @throws OptimisticLockFailedException
225
+	 */
226
+	protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody)
227
+	{
228
+		$request->setStatus('Closed');
229
+		$request->setReserved(null);
230
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
231
+		$request->save();
232
+
233
+		// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and
234
+		// be rolled back.
235
+
236
+		if ($action == EmailTemplate::CREATED) {
237
+			$logCloseType = 'custom-y';
238
+			$notificationCloseType = "Custom, Created";
239
+		}
240
+		else {
241
+			$logCloseType = 'custom-n';
242
+			$notificationCloseType = "Custom, Not Created";
243
+		}
244
+
245
+		Logger::closeRequest($database, $request, $logCloseType, $messageBody);
246
+		$this->getNotificationHelper()->requestClosed($request, $notificationCloseType);
247
+
248
+		$requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8');
249
+		SessionAlert::success("Request {$request->getId()} ({$requestName}) marked as 'Done'.");
250
+	}
251
+
252
+	/**
253
+	 * @param Request     $request
254
+	 * @param PdoDatabase $database
255
+	 * @param string      $action
256
+	 * @param             $availableRequestStates
257
+	 * @param string      $messageBody
258
+	 *
259
+	 * @throws Exception
260
+	 * @throws OptimisticLockFailedException
261
+	 */
262
+	protected function deferRequest(
263
+		Request $request,
264
+		PdoDatabase $database,
265
+		$action,
266
+		$availableRequestStates,
267
+		$messageBody
268
+	) {
269
+		$request->setStatus($action);
270
+		$request->setReserved(null);
271
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
272
+		$request->save();
273
+
274
+		// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
275
+		// and be rolled back.
276
+
277
+		$deferToLog = $availableRequestStates[$action]['defertolog'];
278
+		Logger::sentMail($database, $request, $messageBody);
279
+		Logger::deferRequest($database, $request, $deferToLog);
280
+
281
+		$this->getNotificationHelper()->requestDeferredWithMail($request);
282
+
283
+		$deferTo = $availableRequestStates[$action]['deferto'];
284
+		SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email.");
285
+	}
286 286
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageSendToUser.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@
 block discarded – undo
17 17
 
18 18
 class PageSendToUser extends RequestActionBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     * @throws ApplicationLogicException
23
-     * @throws Exception
24
-     */
25
-    protected function main()
26
-    {
27
-        $this->checkPosted();
28
-        $database = $this->getDatabase();
29
-        $request = $this->getRequest($database);
30
-
31
-        if ($request->getReserved() !== User::getCurrent($database)->getId()) {
32
-            throw new ApplicationLogicException('You don\'t have this request reserved!');
33
-        }
34
-
35
-        $username = WebRequest::postString('user');
36
-        if ($username === null) {
37
-            throw new ApplicationLogicException('User must be specified');
38
-        }
39
-
40
-        $user = User::getByUsername($username, $database);
41
-        if ($user === false) {
42
-            throw new ApplicationLogicException('User not found');
43
-        }
44
-
45
-        if (!$user->isActive()) {
46
-            throw new ApplicationLogicException('User is currently not active on the tool');
47
-        }
48
-
49
-        $request->setReserved($user->getId());
50
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
51
-        $request->save();
52
-
53
-        Logger::sendReservation($database, $request, $user);
54
-        $this->getNotificationHelper()->requestReservationSent($request, $user);
55
-        SessionAlert::success("Reservation sent successfully");
56
-
57
-        $this->redirect('viewRequest', null, array('id' => $request->getId()));
58
-    }
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 * @throws ApplicationLogicException
23
+	 * @throws Exception
24
+	 */
25
+	protected function main()
26
+	{
27
+		$this->checkPosted();
28
+		$database = $this->getDatabase();
29
+		$request = $this->getRequest($database);
30
+
31
+		if ($request->getReserved() !== User::getCurrent($database)->getId()) {
32
+			throw new ApplicationLogicException('You don\'t have this request reserved!');
33
+		}
34
+
35
+		$username = WebRequest::postString('user');
36
+		if ($username === null) {
37
+			throw new ApplicationLogicException('User must be specified');
38
+		}
39
+
40
+		$user = User::getByUsername($username, $database);
41
+		if ($user === false) {
42
+			throw new ApplicationLogicException('User not found');
43
+		}
44
+
45
+		if (!$user->isActive()) {
46
+			throw new ApplicationLogicException('User is currently not active on the tool');
47
+		}
48
+
49
+		$request->setReserved($user->getId());
50
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
51
+		$request->save();
52
+
53
+		Logger::sendReservation($database, $request, $user);
54
+		$this->getNotificationHelper()->requestReservationSent($request, $user);
55
+		SessionAlert::success("Reservation sent successfully");
56
+
57
+		$this->redirect('viewRequest', null, array('id' => $request->getId()));
58
+	}
59 59
 }
Please login to merge, or discard this patch.
includes/Pages/PageForgotPassword.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -17,149 +17,149 @@
 block discarded – undo
17 17
 
18 18
 class PageForgotPassword extends InternalPageBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     *
23
-     * This is the forgotten password reset form
24
-     * @category Security-Critical
25
-     */
26
-    protected function main()
27
-    {
28
-        if (WebRequest::wasPosted()) {
29
-            $this->validateCSRFToken();
30
-            $username = WebRequest::postString('username');
31
-            $email = WebRequest::postEmail('email');
32
-            $database = $this->getDatabase();
33
-
34
-            if ($username === null || trim($username) === "" || $email === null || trim($email) === "") {
35
-                throw new ApplicationLogicException("Both username and email address must be specified!");
36
-            }
37
-
38
-            $user = User::getByUsername($username, $database);
39
-            $this->sendResetMail($user, $email);
40
-
41
-            SessionAlert::success('<strong>Your password reset request has been completed.</strong> Please check your e-mail.');
42
-
43
-            $this->redirect('login');
44
-        }
45
-        else {
46
-            $this->assignCSRFToken();
47
-            $this->setTemplate('forgot-password/forgotpw.tpl');
48
-        }
49
-    }
50
-
51
-    /**
52
-     * Sends a reset email if the user is authenticated
53
-     *
54
-     * @param User|boolean $user  The user located from the database, or false. Doesn't really matter, since we do the
55
-     *                            check anyway within this method and silently skip if we don't have a user.
56
-     * @param string       $email The provided email address
57
-     */
58
-    private function sendResetMail($user, $email)
59
-    {
60
-        // If the user isn't found, or the email address is wrong, skip sending the details silently.
61
-        if (!$user instanceof User) {
62
-            return;
63
-        }
64
-
65
-        if (strtolower($user->getEmail()) === strtolower($email)) {
66
-            $clientIp = $this->getXffTrustProvider()
67
-                ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress());
68
-
69
-            $this->assign("user", $user);
70
-            $this->assign("hash", $user->getForgottenPasswordHash());
71
-            $this->assign("remoteAddress", $clientIp);
72
-
73
-            $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl');
74
-
75
-            $this->getEmailHelper()->sendMail($user->getEmail(), "", $emailContent);
76
-        }
77
-    }
78
-
79
-    /**
80
-     * Entry point for the reset action
81
-     *
82
-     * This is the reset password part of the form.
83
-     * @category Security-Critical
84
-     */
85
-    protected function reset()
86
-    {
87
-        $si = WebRequest::getString('si');
88
-        $id = WebRequest::getString('id');
89
-
90
-        if ($si === null || trim($si) === "" || $id === null || trim($id) === "") {
91
-            throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly");
92
-        }
93
-
94
-        $database = $this->getDatabase();
95
-        $user = $this->getResettingUser($id, $database, $si);
96
-
97
-        // Dual mode
98
-        if (WebRequest::wasPosted()) {
99
-            $this->validateCSRFToken();
100
-            try {
101
-                $this->doReset($user);
102
-            }
103
-            catch (ApplicationLogicException $ex) {
104
-                SessionAlert::error($ex->getMessage());
105
-                $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id));
106
-
107
-                return;
108
-            }
109
-        }
110
-        else {
111
-            $this->assignCSRFToken();
112
-            $this->assign('user', $user);
113
-            $this->setTemplate('forgot-password/forgotpwreset.tpl');
114
-        }
115
-    }
116
-
117
-    /**
118
-     * Gets the user resetting their password from the database, or throwing an exception if that is not possible.
119
-     *
120
-     * @param integer     $id       The ID of the user to retrieve
121
-     * @param PdoDatabase $database The database object to use
122
-     * @param string      $si       The reset hash provided
123
-     *
124
-     * @return User
125
-     * @throws ApplicationLogicException
126
-     */
127
-    private function getResettingUser($id, $database, $si)
128
-    {
129
-        $user = User::getById($id, $database);
130
-
131
-        if ($user === false || $user->getForgottenPasswordHash() !== $si || $user->isCommunityUser()) {
132
-            throw new ApplicationLogicException("User not found");
133
-        }
134
-
135
-        return $user;
136
-    }
137
-
138
-    /**
139
-     * Performs the setting of the new password
140
-     *
141
-     * @param User $user The user to set the password for
142
-     *
143
-     * @throws ApplicationLogicException
144
-     */
145
-    private function doReset(User $user)
146
-    {
147
-        $pw = WebRequest::postString('pw');
148
-        $pw2 = WebRequest::postString('pw2');
149
-
150
-        if ($pw !== $pw2) {
151
-            throw new ApplicationLogicException('Passwords do not match!');
152
-        }
153
-
154
-        $user->setPassword($pw);
155
-        $user->save();
156
-
157
-        SessionAlert::success('You may now log in!');
158
-        $this->redirect('login');
159
-    }
160
-
161
-    protected function isProtectedPage()
162
-    {
163
-        return false;
164
-    }
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 *
23
+	 * This is the forgotten password reset form
24
+	 * @category Security-Critical
25
+	 */
26
+	protected function main()
27
+	{
28
+		if (WebRequest::wasPosted()) {
29
+			$this->validateCSRFToken();
30
+			$username = WebRequest::postString('username');
31
+			$email = WebRequest::postEmail('email');
32
+			$database = $this->getDatabase();
33
+
34
+			if ($username === null || trim($username) === "" || $email === null || trim($email) === "") {
35
+				throw new ApplicationLogicException("Both username and email address must be specified!");
36
+			}
37
+
38
+			$user = User::getByUsername($username, $database);
39
+			$this->sendResetMail($user, $email);
40
+
41
+			SessionAlert::success('<strong>Your password reset request has been completed.</strong> Please check your e-mail.');
42
+
43
+			$this->redirect('login');
44
+		}
45
+		else {
46
+			$this->assignCSRFToken();
47
+			$this->setTemplate('forgot-password/forgotpw.tpl');
48
+		}
49
+	}
50
+
51
+	/**
52
+	 * Sends a reset email if the user is authenticated
53
+	 *
54
+	 * @param User|boolean $user  The user located from the database, or false. Doesn't really matter, since we do the
55
+	 *                            check anyway within this method and silently skip if we don't have a user.
56
+	 * @param string       $email The provided email address
57
+	 */
58
+	private function sendResetMail($user, $email)
59
+	{
60
+		// If the user isn't found, or the email address is wrong, skip sending the details silently.
61
+		if (!$user instanceof User) {
62
+			return;
63
+		}
64
+
65
+		if (strtolower($user->getEmail()) === strtolower($email)) {
66
+			$clientIp = $this->getXffTrustProvider()
67
+				->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress());
68
+
69
+			$this->assign("user", $user);
70
+			$this->assign("hash", $user->getForgottenPasswordHash());
71
+			$this->assign("remoteAddress", $clientIp);
72
+
73
+			$emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl');
74
+
75
+			$this->getEmailHelper()->sendMail($user->getEmail(), "", $emailContent);
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * Entry point for the reset action
81
+	 *
82
+	 * This is the reset password part of the form.
83
+	 * @category Security-Critical
84
+	 */
85
+	protected function reset()
86
+	{
87
+		$si = WebRequest::getString('si');
88
+		$id = WebRequest::getString('id');
89
+
90
+		if ($si === null || trim($si) === "" || $id === null || trim($id) === "") {
91
+			throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly");
92
+		}
93
+
94
+		$database = $this->getDatabase();
95
+		$user = $this->getResettingUser($id, $database, $si);
96
+
97
+		// Dual mode
98
+		if (WebRequest::wasPosted()) {
99
+			$this->validateCSRFToken();
100
+			try {
101
+				$this->doReset($user);
102
+			}
103
+			catch (ApplicationLogicException $ex) {
104
+				SessionAlert::error($ex->getMessage());
105
+				$this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id));
106
+
107
+				return;
108
+			}
109
+		}
110
+		else {
111
+			$this->assignCSRFToken();
112
+			$this->assign('user', $user);
113
+			$this->setTemplate('forgot-password/forgotpwreset.tpl');
114
+		}
115
+	}
116
+
117
+	/**
118
+	 * Gets the user resetting their password from the database, or throwing an exception if that is not possible.
119
+	 *
120
+	 * @param integer     $id       The ID of the user to retrieve
121
+	 * @param PdoDatabase $database The database object to use
122
+	 * @param string      $si       The reset hash provided
123
+	 *
124
+	 * @return User
125
+	 * @throws ApplicationLogicException
126
+	 */
127
+	private function getResettingUser($id, $database, $si)
128
+	{
129
+		$user = User::getById($id, $database);
130
+
131
+		if ($user === false || $user->getForgottenPasswordHash() !== $si || $user->isCommunityUser()) {
132
+			throw new ApplicationLogicException("User not found");
133
+		}
134
+
135
+		return $user;
136
+	}
137
+
138
+	/**
139
+	 * Performs the setting of the new password
140
+	 *
141
+	 * @param User $user The user to set the password for
142
+	 *
143
+	 * @throws ApplicationLogicException
144
+	 */
145
+	private function doReset(User $user)
146
+	{
147
+		$pw = WebRequest::postString('pw');
148
+		$pw2 = WebRequest::postString('pw2');
149
+
150
+		if ($pw !== $pw2) {
151
+			throw new ApplicationLogicException('Passwords do not match!');
152
+		}
153
+
154
+		$user->setPassword($pw);
155
+		$user->save();
156
+
157
+		SessionAlert::success('You may now log in!');
158
+		$this->redirect('login');
159
+	}
160
+
161
+	protected function isProtectedPage()
162
+	{
163
+		return false;
164
+	}
165 165
 }
Please login to merge, or discard this patch.
includes/Pages/PageLogin.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -20,137 +20,137 @@
 block discarded – undo
20 20
  */
21 21
 class PageLogin extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     */
26
-    protected function main()
27
-    {
28
-        // Start by enforcing HTTPS
29
-        if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) {
30
-            if (WebRequest::isHttps()) {
31
-                // Client can clearly use HTTPS, so let's enforce it for all connections.
32
-                if (!headers_sent()) {
33
-                    header("Strict-Transport-Security: max-age=15768000");
34
-                }
35
-            }
36
-            else {
37
-                // This is the login form, not the request form. We need protection here.
38
-                $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri());
39
-
40
-                return;
41
-            }
42
-        }
43
-
44
-        if (WebRequest::wasPosted()) {
45
-            // POST. Do some authentication.
46
-            $this->validateCSRFToken();
47
-
48
-            $user = null;
49
-            try {
50
-                $user = $this->getAuthenticatingUser();
51
-            }
52
-            catch (ApplicationLogicException $ex) {
53
-                SessionAlert::error($ex->getMessage());
54
-                $this->redirect('login');
55
-
56
-                return;
57
-            }
58
-
59
-            // Touch force logout
60
-            $user->setForceLogout(false);
61
-            $user->save();
62
-
63
-            if ($this->getSiteConfiguration()->getEnforceOAuth()) {
64
-                if (!$user->isOAuthLinked()) {
65
-                    $oauthHelper = $this->getOAuthHelper();
66
-
67
-                    $requestToken = $oauthHelper->getRequestToken();
68
-                    $user->setOAuthRequestToken($requestToken->key);
69
-                    $user->setOAuthRequestSecret($requestToken->secret);
70
-                    $user->save();
71
-
72
-                    WebRequest::setPartialLogin($user);
73
-                    $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
74
-
75
-                    return;
76
-                }
77
-            }
78
-
79
-            // User is partially linked to OAuth. This is not allowed. Enforce it for this user.
80
-            if ($user->getOnWikiName() === '##OAUTH##') {
81
-                $oauthHelper = $this->getOAuthHelper();
82
-
83
-                $requestToken = $oauthHelper->getRequestToken();
84
-                $user->setOAuthRequestToken($requestToken->key);
85
-                $user->setOAuthRequestSecret($requestToken->secret);
86
-                $user->save();
87
-
88
-                WebRequest::setPartialLogin($user);
89
-                $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
90
-
91
-                return;
92
-            }
93
-
94
-            WebRequest::setLoggedInUser($user);
95
-
96
-            $this->goBackWhenceYouCame($user);
97
-        }
98
-        else {
99
-            // GET. Show the form
100
-            $this->assignCSRFToken();
101
-            $this->setTemplate("login.tpl");
102
-        }
103
-    }
104
-
105
-    /**
106
-     * @return User
107
-     * @throws ApplicationLogicException
108
-     */
109
-    private function getAuthenticatingUser()
110
-    {
111
-        $username = WebRequest::postString("username");
112
-        $password = WebRequest::postString("password");
113
-
114
-        if ($username === null || $password === null || $username === "" || $password === "") {
115
-            throw new ApplicationLogicException("No username/password specified");
116
-        }
117
-
118
-        /** @var User $user */
119
-        $user = User::getByUsername($username, $this->getDatabase());
120
-
121
-        if ($user == false || !$user->authenticate($password)) {
122
-            throw new ApplicationLogicException("Authentication failed");
123
-        }
124
-
125
-        return $user;
126
-    }
127
-
128
-    protected function isProtectedPage()
129
-    {
130
-        return false;
131
-    }
132
-
133
-    /**
134
-     * Redirect the user back to wherever they came from after a successful login
135
-     *
136
-     * @param User $user
137
-     */
138
-    private function goBackWhenceYouCame(User $user)
139
-    {
140
-        // Redirect to wherever the user came from
141
-        $redirectDestination = WebRequest::clearPostLoginRedirect();
142
-        if ($redirectDestination !== null) {
143
-            $this->redirectUrl($redirectDestination);
144
-        }
145
-        else {
146
-            if ($user->isNewUser()) {
147
-                // home page isn't allowed, go to preferences instead
148
-                $this->redirect('preferences');
149
-            }
150
-            else {
151
-                // go to the home page
152
-                $this->redirect('');
153
-            }
154
-        }
155
-    }
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 */
26
+	protected function main()
27
+	{
28
+		// Start by enforcing HTTPS
29
+		if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) {
30
+			if (WebRequest::isHttps()) {
31
+				// Client can clearly use HTTPS, so let's enforce it for all connections.
32
+				if (!headers_sent()) {
33
+					header("Strict-Transport-Security: max-age=15768000");
34
+				}
35
+			}
36
+			else {
37
+				// This is the login form, not the request form. We need protection here.
38
+				$this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri());
39
+
40
+				return;
41
+			}
42
+		}
43
+
44
+		if (WebRequest::wasPosted()) {
45
+			// POST. Do some authentication.
46
+			$this->validateCSRFToken();
47
+
48
+			$user = null;
49
+			try {
50
+				$user = $this->getAuthenticatingUser();
51
+			}
52
+			catch (ApplicationLogicException $ex) {
53
+				SessionAlert::error($ex->getMessage());
54
+				$this->redirect('login');
55
+
56
+				return;
57
+			}
58
+
59
+			// Touch force logout
60
+			$user->setForceLogout(false);
61
+			$user->save();
62
+
63
+			if ($this->getSiteConfiguration()->getEnforceOAuth()) {
64
+				if (!$user->isOAuthLinked()) {
65
+					$oauthHelper = $this->getOAuthHelper();
66
+
67
+					$requestToken = $oauthHelper->getRequestToken();
68
+					$user->setOAuthRequestToken($requestToken->key);
69
+					$user->setOAuthRequestSecret($requestToken->secret);
70
+					$user->save();
71
+
72
+					WebRequest::setPartialLogin($user);
73
+					$this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
74
+
75
+					return;
76
+				}
77
+			}
78
+
79
+			// User is partially linked to OAuth. This is not allowed. Enforce it for this user.
80
+			if ($user->getOnWikiName() === '##OAUTH##') {
81
+				$oauthHelper = $this->getOAuthHelper();
82
+
83
+				$requestToken = $oauthHelper->getRequestToken();
84
+				$user->setOAuthRequestToken($requestToken->key);
85
+				$user->setOAuthRequestSecret($requestToken->secret);
86
+				$user->save();
87
+
88
+				WebRequest::setPartialLogin($user);
89
+				$this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key));
90
+
91
+				return;
92
+			}
93
+
94
+			WebRequest::setLoggedInUser($user);
95
+
96
+			$this->goBackWhenceYouCame($user);
97
+		}
98
+		else {
99
+			// GET. Show the form
100
+			$this->assignCSRFToken();
101
+			$this->setTemplate("login.tpl");
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * @return User
107
+	 * @throws ApplicationLogicException
108
+	 */
109
+	private function getAuthenticatingUser()
110
+	{
111
+		$username = WebRequest::postString("username");
112
+		$password = WebRequest::postString("password");
113
+
114
+		if ($username === null || $password === null || $username === "" || $password === "") {
115
+			throw new ApplicationLogicException("No username/password specified");
116
+		}
117
+
118
+		/** @var User $user */
119
+		$user = User::getByUsername($username, $this->getDatabase());
120
+
121
+		if ($user == false || !$user->authenticate($password)) {
122
+			throw new ApplicationLogicException("Authentication failed");
123
+		}
124
+
125
+		return $user;
126
+	}
127
+
128
+	protected function isProtectedPage()
129
+	{
130
+		return false;
131
+	}
132
+
133
+	/**
134
+	 * Redirect the user back to wherever they came from after a successful login
135
+	 *
136
+	 * @param User $user
137
+	 */
138
+	private function goBackWhenceYouCame(User $user)
139
+	{
140
+		// Redirect to wherever the user came from
141
+		$redirectDestination = WebRequest::clearPostLoginRedirect();
142
+		if ($redirectDestination !== null) {
143
+			$this->redirectUrl($redirectDestination);
144
+		}
145
+		else {
146
+			if ($user->isNewUser()) {
147
+				// home page isn't allowed, go to preferences instead
148
+				$this->redirect('preferences');
149
+			}
150
+			else {
151
+				// go to the home page
152
+				$this->redirect('');
153
+			}
154
+		}
155
+	}
156 156
 }
Please login to merge, or discard this patch.