Completed
Pull Request — master (#526)
by Michael
02:11
created

session::checksecurity()   C

Complexity

Conditions 13
Paths 45

Size

Total Lines 87
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 182

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 13
eloc 58
nc 45
nop 0
dl 0
loc 87
ccs 0
cts 74
cp 0
crap 182
rs 6.6166
c 3
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**************************************************************************
3
**********      English Wikipedia Account Request Interface      **********
4
***************************************************************************
5
** Wikipedia Account Request Graphic Design by Charles Melbye,           **
6
** which is licensed under a Creative Commons                            **
7
** Attribution-Noncommercial-Share Alike 3.0 United States License.      **
8
**                                                                       **
9
** All other code are released under the Public Domain                   **
10
** by the ACC Development Team.                                          **
11
**                                                                       **
12
** See CREDITS for the list of developers.                               **
13
***************************************************************************/
14
15
class session
16
{
17
18
	public function forceLogout($uid)
19
	{
20
		$user = User::getById($uid, gGetDb());
21
       
22
		if ($user->getForceLogout() == "1") {
0 ignored issues
show
Bug introduced by
The method getForceLogout() does not exist on DataObject. It seems like you code against a sub-type of DataObject such as User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
		if ($user->/** @scrutinizer ignore-call */ getForceLogout() == "1") {
Loading history...
23
			$_SESSION = array();
24
			if (isset($_COOKIE[session_name()])) {
25
				setcookie(session_name(), '', time() - 42000, '/');
26
			}
27
			session_destroy( );
28
29
			BootstrapSkin::displayInternalHeader();
30
			
31
			echo "You have been forcibly logged out, probably due to being renamed. Please log back in.";
32
            
33
			BootstrapSkin::displayAlertBox("You have been forcibly logged out, probably due to being renamed. Please log back in.", "alert-error", "Logged out", true, false);
34
            
35
			$user->setForceLogout(0);
0 ignored issues
show
Bug introduced by
The method setForceLogout() does not exist on DataObject. It seems like you code against a sub-type of DataObject such as User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
			$user->/** @scrutinizer ignore-call */ 
36
          setForceLogout(0);
Loading history...
36
			$user->save();
37
            
38
			BootstrapSkin::displayInternalFooter();
39
			die();
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...
40
		}
41
	}
42
43
	/**
44
	 * Check the user's security level on page load, and bounce accordingly
45
	 * 
46
	 * @deprecated
47
	 */
48
	public function checksecurity()
49
	{
50
		global $secure, $smarty;
51
52
		// CommunityUser has no database row, and we really don't want CommunityUser to have oauth credentials...
53
		if (!User::getCurrent()->isCommunityUser()) {
54
			if (User::getCurrent()->getStoredOnWikiName() == "##OAUTH##"
55
				&& User::getCurrent()->getOAuthAccessToken() == null
56
			) {
57
				reattachOAuthAccount(User::getCurrent());
58
			}
59
60
			if (User::getCurrent()->isOAuthLinked()) {
61
				try {
62
					// test retrieval of the identity
63
					User::getCurrent()->getOAuthIdentity();
64
				}
65
				catch (TransactionException $ex) {
66
					User::getCurrent()->setOAuthAccessToken(null);
67
					User::getCurrent()->setOAuthAccessSecret(null);
68
					User::getCurrent()->save();
69
70
					reattachOAuthAccount(User::getCurrent());
71
				}
72
			}
73
			else {
74
				global $enforceOAuth;
75
76
				if ($enforceOAuth) {
77
					reattachOAuthAccount(User::getCurrent());
78
				}
79
			}
80
		}
81
        
82
		if (User::getCurrent()->isNew()) {
83
			BootstrapSkin::displayAlertBox("I'm sorry, but, your account has not been approved by a site administrator yet. Please stand by.", "alert-error", "New account", true, false);
84
			BootstrapSkin::displayInternalFooter();
85
			die();
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...
86
		}
87
		elseif (User::getCurrent()->isSuspended()) {
88
			$database = gGetDb();
89
			$suspendstatement = $database->prepare(<<<SQL
90
SELECT comment 
91
FROM log 
92
WHERE action = 'Suspended' AND objectid = :userid and objecttype = 'User' 
93
ORDER BY timestamp DESC
94
LIMIT 1;
95
SQL
96
			);
97
            
98
			$suspendstatement->bindValue(":userid", User::getCurrent()->getId());
99
			$suspendstatement->execute();
100
            
101
			$suspendreason = $suspendstatement->fetchColumn();
102
			$suspendstatement->closeCursor();
103
            
104
			$smarty->assign("suspendreason", $suspendreason);
105
			$smarty->display("login/suspended.tpl");
106
			BootstrapSkin::displayInternalFooter();
107
			die();
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...
108
		}
109
		elseif (User::getCurrent()->isDeclined()) {
110
			$database = gGetDb();
111
			$suspendstatement = $database->prepare(<<<SQL
112
SELECT comment
113
FROM log
114
WHERE action = 'Declined' AND objectid = :userid and objecttype = 'User'
115
ORDER BY timestamp DESC
116
LIMIT 1;
117
SQL
118
			);
119
            
120
			$suspendstatement->bindValue(":userid", User::getCurrent()->getId());
121
			$suspendstatement->execute();
122
                
123
			$suspendreason = $suspendstatement->fetchColumn();
124
			$suspendstatement->closeCursor();
125
                
126
			$smarty->assign("suspendreason", $suspendreason);
127
			$smarty->display("login/declined.tpl");
128
			BootstrapSkin::displayInternalFooter();
129
			die();
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...
130
		}
131
		elseif ((!User::getCurrent()->isCommunityUser()) && (User::getCurrent()->isUser() || User::getCurrent()->isAdmin())) {
132
			$secure = 1;
133
		}
134
		else {
135
			//die("Not logged in!");
136
		}
137
	}
138
}
139