This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathback_connectpanel.php
91 lines (78 loc) · 1.79 KB
/
back_connectpanel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php require 'common.php'; ?>
<?php
function connectPanel($is_endpoint, $email, $ePanelData){
require 'common.php';
$panelData = JSON_decode($ePanelData);
$query = "
SELECT accountid
FROM panels
WHERE alpha_uid = :uid";
if ($is_endpoint){
$uid = $panelData->alphaId;
} else {
$uid = $_POST['uid'];
}
$query_params = array(
':uid' => $uid,
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$row = $stmt->fetch();
if ($row['accountid'] != null){
return false;
}
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
if ($is_endpoint){
$name = $panelData->name;
$description = $panelData->description;
} else {
$email = $_SESSION['user']["email"];
$name = $_POST['name'];
$description = $_POST['description'];
}
$query_params = array(
':uid' => $uid,
':email' => $email,
':name' => $name,
':description' => $description
);
$query = "
UPDATE panels
SET accountid = (
SELECT id
FROM users
WHERE email = :email),
name = :name,
description = :description
WHERE alpha_uid = :uid";
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
if ($stmt->rowCount() == 0){
if ($is_endpoint){
return false;
}
die ("Control Panel ID not registered");
} else {
if ($is_endpoint){
return true;
}
header("Location: home.php");
}
}
if (!empty($_POST) && !(empty($_SESSION['user']))){
connectPanel(false, null);
}
?>