-
Notifications
You must be signed in to change notification settings - Fork 2
/
daftar.php
213 lines (193 loc) · 8.79 KB
/
daftar.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
// Include koneksi ke database
include 'koneksi.php';
// Pesan kesalahan
$errorMsg = '';
// Include file environment.php
include 'environment.php';
// Menggunakan nilai dari variabel TOKEN_BOT
$token = TOKEN_BOT;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Ambil data dari form
$userName = $_POST['user_name'];
$name = $_POST['name'];
// $bio = $_POST['bio'];
$bio = "Update bio anda edit profil!";
$password = $_POST['password'];
$teleChatID = $_POST['tele_chat_id'];
// Inisialisasi direktori dan nama file default
$uploadDir = 'storage/profile/';
$defaultImage = 'default.png';
// Cek apakah user_name sudah ada dalam database
$checkUsernameQuery = "SELECT COUNT(user_name) AS total FROM users WHERE user_name = '$userName'";
$checkUsernameResult = mysqli_query($koneksi, $checkUsernameQuery);
$row = mysqli_fetch_assoc($checkUsernameResult);
$totalUsername = $row['total'];
if ($totalUsername > 0) {
header("location:daftar.php?pesan=userexists");
} else {
// Cek apakah tele_chat_id sudah ada dalam database
$checkTeleChatIDQuery = "SELECT COUNT(tele_chat_id) AS total FROM users WHERE tele_chat_id = '$teleChatID'";
$checkTeleChatIDResult = mysqli_query($koneksi, $checkTeleChatIDQuery);
$rowTeleChatID = mysqli_fetch_assoc($checkTeleChatIDResult);
$totalTeleChatID = $rowTeleChatID['total'];
if ($totalTeleChatID > 0) {
header("location:daftar.php?pesan=chatidused");
exit();
} else {
// Generate kode OTP
$generatedCode = mt_rand(100000, 999999);
// Simpan kode OTP ke database
$insertOTPQuery = "INSERT INTO otp (user_name, otp_code, to_use) VALUES ('$userName', '$generatedCode', 'register')";
// eksekusi setelah data user berhasil diinput
// API Telegram untuk mengirim pesan
$telegramAPI = "https://api.telegram.org/bot$token/sendMessage?parse_mode=markdown&chat_id=$teleChatID&text=Kode%20OTP%20Regis:%20`$generatedCode`";
// Kirim pesan ke Telegram
$ch = curl_init();
// Set opsi cURL
curl_setopt($ch, CURLOPT_URL, $telegramAPI);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
// Tutup cURL
curl_close($ch);
// Fungsi untuk mendapatkan ekstensi file
function getFileExtension($filename) {
return pathinfo($filename, PATHINFO_EXTENSION);
}
// Fungsi untuk mendapatkan nama file tanpa ekstensi
function getFileNameWithoutExtension($filename) {
return pathinfo($filename, PATHINFO_FILENAME);
}
// Validasi ukuran file
if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] > 512 * 1024) {
header("location:daftar.php?pesan=filetoolarge");
exit();
} else {
// Validasi ekstensi file
if ($_FILES['image']['size'] > 0) {
$allowedExtensions = array('jpg', 'jpeg', 'png', 'gif');
$imageExtension = getFileExtension($_FILES['image']['name']);
if (!in_array($imageExtension, $allowedExtensions)) {
header("location:daftar.php?pesan=unsupportedfile");
exit();
}
}
// Proses upload gambar jika ada
if (empty($errorMsg) && $_FILES['image']['size'] > 0) {
$fileName = $_FILES['image']['name'];
$filePath = $uploadDir . $fileName;
$i = 1;
while (file_exists($filePath)) {
$newFileName = getFileNameWithoutExtension($fileName) . '-' . $i . '.' . $imageExtension;
$filePath = $uploadDir . $newFileName;
$i++;
}
if (!move_uploaded_file($_FILES['image']['tmp_name'], $filePath)) {
$errorMsg = "Gagal mengunggah file gambar.";
}
// Set $filePath hanya dengan nama file
$filePath = basename($filePath);
} else {
// Gunakan gambar default jika tidak ada gambar yang diunggah
$filePath = $defaultImage;
}
// Query untuk memasukkan data ke database
$insertQuery = "INSERT INTO users (user_name, name, user_profile_path, user_bio, level_id, password, status, tele_chat_id) VALUES ('$userName', '$name', '$filePath', '$bio', 2, '$password', 'Nonaktif', '$teleChatID')";
// Jalankan query
if (empty($errorMsg) && mysqli_query($koneksi, $insertQuery)) {
mysqli_query($koneksi, $insertOTPQuery); // insert OTP code
// Redirect ke halaman sukses dengan alert jika berhasil
header("Location: verif-otp.php?pesan=registered&username=$userName");
exit();
} elseif (empty($errorMsg)) {
$errorMsg = "Gagal memasukkan data ke database: " . mysqli_error($koneksi);
}
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MiawShare - Login</title>
<link rel="stylesheet" href="styles/daftar.css">
<!-- <link rel="stylesheet" href="styles/style.css"> -->
<link rel="icon" type="image/png" href="assets/logo/logo.png">
<link rel="stylesheet" href="styles/alert.css">
<link rel="stylesheet" href="styles/hide-spin-button.css">
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="number"] {
-moz-appearance: textfield;
}
</style>
</head>
<body>
<?php
if(isset($_GET['pesan'])){
if($_GET['pesan']=="filetoolarge"){
echo "<div class='alert'>File gambar tidak boleh lebih dari 512KB</div>";
}
}
if(isset($_GET['pesan'])){
if($_GET['pesan']=="userexists"){
echo "<div class='alert'>Username sudah digunakan. Silakan gunakan username yang lain.</div>";
}
}
if(isset($_GET['pesan'])){
if($_GET['pesan']=="unsupportedfile"){
echo "<div class='alert'>Format file tidak didukung. Hanya JPG, JPEG, PNG, dan GIF yang diperbolehkan.</div>";
}
}
if(isset($_GET['pesan'])){
if($_GET['pesan']=="chatidused"){
echo "<div class='alert'>ChatID Telegram sudah digunakan. Silakan gunakan ChatID yang lain.</div>";
}
}
?>
<div class="login-container">
<form class="login-form" method="POST" enctype="multipart/form-data">
<div class="logo_items flex">
<span class="nav_image">
<img src="assets/logo/logo.png" alt="logo_img" />
</span>
<span class="logo_name">MiawShare</span>
</div>
<h2>Daftar</h2>
<div class="form-group">
<label for="name">Nama</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="username">Username</label>
<!-- <input type="text" id="username" name="username" required> -->
<input type="text" id="user_name" name="user_name" required>
</div>
<div class="form-group password-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
<button type="button" id="togglePassword" class="toggle-password">Show</button>
</div>
<p class="inilink">Dapatkan <a href="https://t.me/chatIDrobot" target="_blank">ChatID</a></p>
<p class="inilink">Tulis apapun di <a href="https://t.me/spamtestingbot" target="_blank">Bot Notifikasi</a></p>
<div class="form-group">
<label for="tele_chat_id">ChatID Telegram:</label>
<input type="number" id="tele_chat_id" name="tele_chat_id" required>
</div>
<p class="terms">Dengan membuat akun, anda setuju dengan<a href="pages/terms.php"> ketentuan penggunaan kami.</a></p>
<button type="submit">Buat</button>
<p id="mendaftar">Sudah punya akun? <a href="index.php">Kembali</a></p>
<p id="verify"><a href="verif-otp.php">Verifikasi</a></p>
</form>
</div>
<script src="script/login.js"></script>
<script src="script/alert-time.js"></script>
</body>
</html>