Test Failed
Push — master ( cc6deb...6d0343 )
by Justin
33:28 queued 29:27
created

LogoutPage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 4
c 2
b 2
f 0
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getContent() 0 6 2
B setCustomHeader() 0 26 2
1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
20
/**
21
 * Project: JuKuCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 19.03.2018
25
 * Time: 13:52
26
 */
27
28
class LogoutPage extends HTMLPage {
29
30
	protected $error = false;
31
32
	public function setCustomHeader() {
33
		//check, if session was started
34
		PHPUtils::checkSessionStarted();
35
36
		if (!Security::checkCSRFToken()) {
37
			$this->error = true;
38
39
			//dont logout user, because csrf token isnt correct
40
			return;
41
		}
42
43
		//logout user
44
		User::current()->logout();
45
46
		//get domain
47
		$domain = Registry::singleton()->getObject("domain");
48
49
		//generate index url
50
		$index_url = DomainUtils::generateURL($domain->getHomePage());
51
52
		header("Location: " . $index_url);
53
54
		//flush gzip buffer
55
		ob_end_flush();
56
57
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
58
	}
59
60
	public function getContent(): string {
61
		if ($this->error) {
62
			return "Wrong CSRF token!";
63
		}
64
65
		return "";
66
	}
67
68
}
69
70
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
71