These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | include 'php/jodel-web.php'; |
||
4 | |||
5 | if(isset($_GET['postId']) && $_GET['vote']) |
||
6 | { |
||
7 | error_log('test'); |
||
8 | header('Content-Type: application/json'); |
||
9 | echo json_encode($jodelAccountForKarma->votePostId($_GET['postId'], $_GET['vote'])); |
||
10 | die(); |
||
11 | } |
||
12 | |||
13 | if((!isset($_GET['pw']) || $config['pw'] != $_GET['pw']) && !isUserAdmin()) |
||
14 | { |
||
15 | error_log($_SERVER['REMOTE_ADDR'] . ' used a wrong password on vote-ajax.php'); |
||
16 | $respone = array("message" => $_SERVER['REMOTE_ADDR'] . ' used a wrong password on vote-ajax.php',"success" => false); |
||
17 | echo json_encode($response); |
||
18 | die(); |
||
19 | } |
||
20 | else |
||
21 | { |
||
22 | |||
23 | View Code Duplication | if(isset($_GET['solution']) && isset($_GET['key']) && isset($_POST['deviceUid'])) |
|
0 ignored issues
–
show
|
|||
24 | { |
||
25 | $jodelAccount = new JodelAccount($_POST['deviceUid']); |
||
26 | $response = array("success" => $jodelAccount->verifyCaptcha()); |
||
27 | echo json_encode($response); |
||
28 | die(); |
||
29 | } |
||
30 | |||
31 | $message = ""; |
||
32 | $success = true; |
||
33 | $token = ""; |
||
34 | if(isset($_POST['vote']) && isset($_POST['postId'])) |
||
35 | { |
||
36 | $i = 0; |
||
37 | $result = $db->query("SELECT access_token, device_uid FROM accounts WHERE device_uid NOT IN (SELECT device_uid FROM votes WHERE postId = '" . $_POST['postId'] . "')"); |
||
38 | |||
39 | if($result->num_rows > 0) |
||
40 | { |
||
41 | $row = $result->fetch_assoc(); |
||
42 | $accessToken = $row['access_token']; |
||
43 | $deviceUid = $row['device_uid']; |
||
44 | |||
45 | $jodelAccount = new JodelAccount($deviceUid); |
||
46 | |||
47 | if(!$jodelAccount->isAccountVerified()) |
||
48 | { |
||
49 | $view = new View(); |
||
50 | $message = "This account is not verified. Please verify this account first."; |
||
51 | $captcha = $view->getCaptcha($accessToken); |
||
52 | /* save captcha images |
||
53 | $filename = explode("/", $captcha['image_url']); |
||
54 | $filename = $filename[count($filename) - 1]; |
||
55 | if (!file_exists("captcha/".$filename)) |
||
56 | { |
||
57 | $image = file_get_contents($captcha['image_url']); |
||
58 | $fp = fopen("captcha/".$filename, 'w'); |
||
59 | fwrite($fp, $image); |
||
60 | fclose($fp); |
||
61 | } |
||
62 | */ |
||
63 | $captchaCodes = array("1CEAFRH69O" => "7-8", |
||
64 | "2QT6JRL06T" => "1-2", |
||
65 | "4GEIEE5P8P" => "2-6-8", |
||
66 | "5VI2JTJYWY" => "0-5", |
||
67 | "6UHC4L53DG" => "0-2-3", |
||
68 | "18FTBXVIJC" => "1-3-5", |
||
69 | "AKWROEYSD3" => "1-5-7", |
||
70 | "BL5901E1JS" => "0-4", |
||
71 | "BNB1P58AJ6" => "4", |
||
72 | "CORKCXU0TA" => "2-4-5", |
||
73 | "D3SKGYMB0C" => "1", |
||
74 | "DB96PZYUM7" => "2-7", |
||
75 | "EJSHC2LTY1" => "5-6-8", |
||
76 | "G6X12MP9DW" => "3", |
||
77 | "IGDPXAFRE8" => "1-6-7", |
||
78 | "IH92Z2ETIE" => "1-2-7", |
||
79 | "JGA66GP5TG" => "1-5-8", |
||
80 | "KUD8PU6UAB" => "5", |
||
81 | "MF7ZX46TQQ" => "0-1-8", |
||
82 | "MFDV8CMHHG" => "2-7-8", |
||
83 | "MI9R8R1YIZ" => "1-7-8", |
||
84 | "NI1A0RU1VJ" => "3-4-6", |
||
85 | "OFJP966MXD" => "1-4-6", |
||
86 | "OQZBADCV8I" => "2-5-8", |
||
87 | "QNLPAJ8XGM" => "3-7-8", |
||
88 | "RXNR1VZPUC" => "0-4-6", |
||
89 | "YLJB76EJDY" => "3-4", |
||
90 | "YO9E3X95IG" => "0-1-7", |
||
91 | "ZJP7PW2LRG" => "4-5"); |
||
92 | $filename = explode("/", $captcha['image_url']); |
||
93 | $filename = explode(".", $filename[count($filename) - 1])[0]; |
||
94 | $_GET['solution'] = $captchaCodes[$filename]; |
||
95 | $_GET['key'] = $captcha["key"]; |
||
96 | $_GET['deviceUid'] = $deviceUid; |
||
97 | $response = array("success" => $jodelAccount->verifyCaptcha()); |
||
98 | echo json_encode($response); |
||
99 | die(); |
||
100 | $success = false; |
||
101 | } |
||
102 | else |
||
103 | { |
||
104 | $jodelAccount->votePostId($_POST['postId'], $_POST['vote']); |
||
105 | } |
||
106 | } |
||
107 | else |
||
108 | { |
||
109 | $message = 'There is no account available for this jodel. Please create at least one new account to vote this jodel.'; |
||
110 | $success = false; |
||
111 | } |
||
112 | } |
||
113 | |||
114 | if (isset($captcha)) |
||
115 | { |
||
116 | $response = array("success" => $success, "message" => $message, "captcha" => $captcha, "deviceUid" => $deviceUid); |
||
117 | } |
||
118 | else |
||
119 | { |
||
120 | $response = array("success" => $success, "message" => $message); |
||
121 | } |
||
122 | } |
||
123 | echo json_encode($response); |
||
124 | ?> |
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.