1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
include 'php/jodel-web.php'; |
4
|
|
|
|
5
|
|
|
if(isset($_GET['postId']) && $_GET['vote']) |
6
|
|
|
{ |
7
|
|
|
header('Content-Type: application/json'); |
8
|
|
|
$voteResult = $jodelAccountForKarma->votePostId($_GET['postId'], $_GET['vote']); |
9
|
|
|
echo json_encode($voteResult); |
10
|
|
|
die(); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
View Code Duplication |
if(isset($_GET['solution']) && isset($_POST['deviceUid'])) |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
$jodelAccount = new JodelAccount($_POST['deviceUid']); |
16
|
|
|
$response = array("success" => $jodelAccount->verifyCaptcha()); |
17
|
|
|
echo json_encode($response); |
18
|
|
|
die(); |
19
|
|
|
} |
20
|
|
|
$userIsAdmin = isUserAdmin(); |
21
|
|
|
if(!$userIsAdmin) |
22
|
|
|
{ |
23
|
|
|
$userIsVoter = isUserVoter(); |
24
|
|
|
} |
25
|
|
|
else |
26
|
|
|
{ |
27
|
|
|
$userIsVoter = false; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if(!$userIsVoter && !$userIsAdmin) |
31
|
|
|
{ |
32
|
|
|
error_log($_SERVER['REMOTE_ADDR'] . ' used a wrong password on vote-ajax.php'); |
33
|
|
|
$response = array("message" => $_SERVER['REMOTE_ADDR'] . ' used a wrong password on vote-ajax.php',"success" => false); |
34
|
|
|
echo json_encode($response); |
35
|
|
|
die(); |
36
|
|
|
} |
37
|
|
|
else |
38
|
|
|
{ |
39
|
|
|
if($userIsVoter) |
40
|
|
|
{ |
41
|
|
|
$result = $db->query("SELECT user_token, remaining_votes FROM users WHERE user_token = '" . $_COOKIE['JodelVoterPassword'] . "'"); |
42
|
|
|
if($result->num_rows > 0) |
43
|
|
|
{ |
44
|
|
|
$row = $result->fetch_assoc(); |
45
|
|
|
$remaining_votes = $row['remaining_votes']; |
46
|
|
|
} |
47
|
|
|
if($remaining_votes <= 0) |
48
|
|
|
{ |
49
|
|
|
$message = 'This voter account run out of votes. For more information please contact [email protected]'; |
50
|
|
|
$success = false; |
51
|
|
|
|
52
|
|
|
$response = array("success" => $success, "message" => $message); |
53
|
|
|
echo json_encode($response); |
54
|
|
|
die(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
$message = ""; |
60
|
|
|
$success = true; |
61
|
|
|
$token = ""; |
62
|
|
|
if(isset($_POST['vote']) && isset($_POST['postId'])) |
63
|
|
|
{ |
64
|
|
|
$i = 0; |
65
|
|
|
$result = $db->query("SELECT access_token, device_uid FROM accounts WHERE device_uid NOT IN (SELECT device_uid FROM votes WHERE postId = '" . $_POST['postId'] . "')"); |
66
|
|
|
|
67
|
|
|
if($result->num_rows > 0) |
68
|
|
|
{ |
69
|
|
|
$row = $result->fetch_assoc(); |
70
|
|
|
$accessToken = $row['access_token']; |
71
|
|
|
$deviceUid = $row['device_uid']; |
72
|
|
|
|
73
|
|
|
$jodelAccount = new JodelAccount($deviceUid); |
74
|
|
|
|
75
|
|
|
if(!$jodelAccount->isAccountVerified()) |
76
|
|
|
{ |
77
|
|
|
$message = "This account is not verified. Please verify this account first."; |
78
|
|
|
$captcha = $jodelAccount->getCaptcha(); |
79
|
|
|
|
80
|
|
|
$_GET['key'] = $captcha["key"]; |
81
|
|
|
$_GET['deviceUid'] = $deviceUid; |
82
|
|
|
|
83
|
|
|
$success = false; |
84
|
|
|
} |
85
|
|
|
else |
86
|
|
|
{ |
87
|
|
|
if($userIsVoter) |
88
|
|
|
{ |
89
|
|
|
$remaining_votes = $remaining_votes - 1; |
90
|
|
|
$result = $db->query("UPDATE users |
91
|
|
|
SET remaining_votes='" . $remaining_votes . "' |
92
|
|
|
WHERE user_token='" . $_COOKIE['JodelVoterPassword'] . "'"); |
93
|
|
View Code Duplication |
if($result === false) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
error_log("Update remaining votes failed: (" . $db->errno . ") " . $db->error); |
96
|
|
|
} |
97
|
|
|
$db->close(); |
98
|
|
|
} |
99
|
|
|
$jodelAccount->votePostId($_POST['postId'], $_POST['vote']); |
100
|
|
|
//Feedback |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
else |
104
|
|
|
{ |
105
|
|
|
$message = 'There is no account available for this jodel. Please create at least one new account to vote this jodel.'; |
106
|
|
|
$success = false; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if(isset($captcha)) |
111
|
|
|
{ |
112
|
|
|
$response = array("success" => $success, "message" => $message, "captcha" => $captcha, "deviceUid" => $deviceUid); |
113
|
|
|
} |
114
|
|
|
else |
115
|
|
|
{ |
116
|
|
|
$response = array("success" => $success, "message" => $message); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
echo json_encode($response); |
120
|
|
|
?> |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.