-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuat-akun.php
473 lines (411 loc) · 18.3 KB
/
buat-akun.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<?php
include "koneksi.php";
ini_set('max_execution_time', '300');
//ambil function smtp_mail
include("asset/library-email/function.php");
$error = null;
$event = null;
$sukses = null;
$kunci = null;
$email_db = null;
//select option
$result = $koneksi->query('SELECT judul,id_event FROM master_event WHERE status=1'
);
if (isset($_POST['submit'])) {
//Get Data
$nama = $_POST['nama'];
$jenis_kelamin = $_POST['jenis_kelamin'];
$event = $_POST['event'];
$institusi = $_POST['institusi'];
$alamat = $_POST['alamat'];
$email = $_POST['email'];
$secret_key = '6Ld3FuYcAAAAANmQI1TzqJxUlb57n13WoOiv9J7J';
// Disini kita akan melakukan komunkasi dengan google recpatcha
// dengan mengirimkan scret key dan hasil dari response recaptcha nya
$verify = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret_key.'&response='.$_POST['g-recaptcha-response']);
$response = json_decode($verify);
if ($response->success) {
echo '<script>alert("Google reCAPTACHA verified")</script>';
}
//cek email apakah sudah ada di database (1 email = 1 kali daftar)
$sql = "SELECT email FROM master_peserta WHERE email = '$email' LIMIT 1";
$result2 = $koneksi->query($sql);
while ($row = mysqli_fetch_array($result2)) {
$email_db = $row['email'];
}
if ($email == $email_db) {
$sukses = '<div class=" alert alert-danger text-center" role="alert">
Email sudah terdaftar.
</div>';
} else {
// Secret Key ini kita ambil dari halaman Google reCaptcha
// $secret_key = '6Ld3FuYcAAAAANmQI1TzqJxUlb57n13WoOiv9J7J';
// Disini kita akan melakukan komunkasi dengan google recpatcha
// dengan mengirimkan scret key dan hasil dari response recaptcha nya
// $verify = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret_key.'&response='.$_POST['g-recaptcha-response']);
// $response = json_decode($verify);
// if ($response->success) {
// Jika proses validasi captcha berhasil
$password = $_POST['password'];
$konfirmasi_password = $_POST['konfirmasi_password'];
$uppercase = preg_match('@[A-Z]@', $password);
$lowercase = preg_match('@[a-z]@', $password);
$number = preg_match('@[0-9]@', $password);
$specialChar = preg_match(
'[!@#$%^&*()_+\-=\[\]{};:\\|,.<>\/?~]',
$password
);
if (
!$uppercase ||
!$lowercase ||
!$number ||
$specialChar ||
strlen($password) < 8
) {
$kunci =
'Password harus ada 8 karakter, harus memuat satu huruf kapital, angka, dan karakter spesial';
} elseif ($password != $konfirmasi_password) {
$error =
"<div class='alert alert-danger text-center' role='alert'>password kamu tidak sama dengan konfirmasi password</div>";
} else {
// form valid
//Sanitize form data
$nama = $koneksi->real_escape_string($nama);
$jenis_kelamin = $koneksi->real_escape_string($jenis_kelamin);
$event = $koneksi->real_escape_string($event);
$institusi = $koneksi->real_escape_string($institusi);
$alamat = $koneksi->real_escape_string($alamat);
$email = $koneksi->real_escape_string($email);
$password = $koneksi->real_escape_string($password);
$konfirmasi_password = $koneksi->real_escape_string(
$konfirmasi_password
);
//Generate Vkey
$vkey = md5(time() . $nama);
// echo $vkey;
// -----------------------------------------------------------------
//generate id_peserta
// mengambil data barang dengan kode paling besar
$query_id = mysqli_query(
$koneksi,
'SELECT max(id_peserta) as kodeTerbesar FROM master_peserta'
);
$data = mysqli_fetch_array($query_id);
$noid = $data['kodeTerbesar'];
// echo $noid;
// mengambil angka dari kode barang terbesar, menggunakan fungsi substr
// dan diubah ke integer dengan (int)
$urutan = (int) substr($noid, 3);
// bilangan yang diambil ini ditambah 1 untuk menentukan nomor urut berikutnya
$urutan++;
// membentuk kode barang baru
// perintah sprintf("%03s", $urutan); berguna untuk membuat string menjadi 3 karakter
// misalnya perintah sprintf("%03s", 15); maka akan menghasilkan '015'
// angka yang diambil tadi digabungkan dengan kode huruf yang kita inginkan, misalnya USR
$huruf = 'PSR';
$noid = $huruf . sprintf('%03s', $urutan);
//echo $noid;
// ---------------------------------------------------------------------
//Insert to database
$password = md5($password);
$insert = $koneksi->query(
"INSERT INTO master_peserta(id_peserta,nama_lengkap,jenis_kelamin,asal_institusi,alamat,email,password,vkey) VALUES('$noid','$nama','$jenis_kelamin','$institusi','$alamat','$email','$password','$vkey')"
);
if ($event != null) {
$peserta_event = "$noid$event";
//insert kedua
$insert .= $koneksi->query(
"INSERT INTO peserta_event (id_peserta_event,id_peserta,id_event) VALUES('$peserta_event','$noid','$event')"
);
}
if ($insert) {
//Send Email
$to = $email;
$subject = 'Webinar Informatika UKDC ';
$message = "
<div style='width : 550px;
border : 2px solid black;
margin : 20px auto;'>
<div style='border-bottom : 2px solid black;'>
<center><img src = 'https://drive.google.com/uc?id=1cTPc2fgt_RY78klrt6m3mSRnXtdRSAQD' alt = 'DC Informatics' width = '550' height = '175'></center>
</div>
<p style='font-size : 25px;
font-family : sans-serif;
text-align : center;'> Halo, $email! </p><br>
<p style='font-size : 18px;
font-family : sans-serif;
text-align : center;'> Yuk verifikasi email kamu dengan cara <br> klik tombol dibawah ini ya! <br>
</p>
<br>
<br>
<center><a href = 'https://webinar.ukdc.ac.id/verify.php?vkey=$vkey' style='font-family : sans-serif;
font-size : 15px;
background : #2de030;
color : white;
border : white 3px solid;
border-radius : 5px;
padding : 12px 20px;
margin-top : 10px;
text-decoration : none;'> Verifikasi Email </a><center>
<br>
<br>
<br>
<br>
<p class = 'p3' style='font-size : 12px;
font-family : sans-serif;
text-align : center;''> © DC Informatics </p>
</div>
";
$headers = "From:[email protected] \r \n";
smtp_mail($to, $subject, $message, $headers, '', 0, 0, true);
$sukses = '<div class="alert alert-danger text-center" role="alert">
Sukses buat akun silahkan cek email untuk verifikasi.
</div>';
//header('location:thankyou.php');
} else {
echo $mysqli->error;
}
}
// } else {
// // Jika captcha tidak valid
// $error ="<div class='alert alert-danger text-center' role='alert'>Silahkan klik kotak I'm not robot (reCaptcha) untuk verifikasi</div>";
// }
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sign Up | DC-Event</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- untuk style font dan layout-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="fonts/iconic/css/material-design-iconic-font.min.css">
<link rel="stylesheet" type="text/css" href="vendor/select2/select2.css">
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<title>Buat Akun</title>
<!-- Load Librari Google reCaptcha nya -->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<style>
#message {
background: #f1f1f1;
color: #000;
padding: 5px;
margin: 0px;
margin-top: 8px;
}
#message p {
padding: 0px 35px;
font-size: 12px;
}
.valid {
color: green;
}
.valid:before {
position: relative;
left: -10px;
content: "\2713";
}
.invalid {
color: red;
}
.invalid:before {
position: relative;
left: -10px;
content: "\0D7";
}
#letter {
float: left;
}
#number {
float: left;
}
</style>
<body>
<div class="container-login" style="background-image: url('images/bg08.jpg');">
<div class="wrap-login p-l-55 p-r-55 p-t-20 p-b-20" style="min-height:95vh;">
<div> <?php echo $sukses; ?></div>
<div> <?php echo $error; ?></div>
<form class="login-form validate-form" action="buat-akun.php" method="POST">
<span class="login-form-title p-b-30">
Buat Akun
</span>
<span class="txt2">Nama Lengkap</span>
<div class="wrap-input validate-input m-b-20" data-validate="Masukkan Nama">
<input class="input" type="text" name="nama">
<span class="focus-input"></span>
</div>
<p style="font-size: 12px;">Pastikan masukkan nama lengkap untuk sertifikat</p>
<br>
<span class="txt2">Gender</span>
<div class="select2.container">
<select class="select2-dropdown" name="jenis_kelamin">
<option value="0">Laki-Laki</option>
<option value="1">Perempuan</option>
</select>
</div>
<br>
<span class="txt2">Email</span>
<div class="wrap-input validate-input m-b-20" data-validate="Masukkan Email">
<input class="input" type="email" name="email">
<span class="focus-input"></span>
</div>
<span class="txt2">Event</span>
<div class="select2.container">
<div class="mb-3 text-start">
<?php
echo "<select name='event' class='select2-dropdown' >";
$rowcount = mysqli_num_rows($result);
if ($rowcount <= 0) {
echo '<option value=""></option>';
} else {
while ($row = $result->fetch_assoc()) {
$id_event = $row['id_event'];
$judul = $row['judul'];
echo '<option value="' .
$id_event .
'" ><div class ="">' .
$judul .
'</div></option>';
}
}
echo '</select>';
?>
</div>
</div>
<br>
<span class="txt2">Asal Instansi</span>
<div class="wrap-input validate-input m-b-20" data-validate="Masukkan Asal Instansi">
<input class="input" type="text" name="institusi" placeholder="">
<span class="focus-input"></span>
</div>
<span class="txt2">Alamat Rumah</span>
<div class="wrap-input validate-input m-b-20" data-validate="Masukkan alamat">
<input class="input" type="text" name="alamat" placeholder="">
<span class="focus-input"></span>
</div>
<p style="font-size: 12px;">Alamat Rumah digunakan untuk pengiriman hadiah jika anda beruntung.</p>
<br>
<span class="txt2">Password</span>
<div class="wrap-input validate-input m-b-25" data-validate="Masukkan password">
<input class="input" type="password" placeholder="" id="pass" name="password">
<span class="focus-input"></span>
</div>
<div id="message">
<p>Password harus terdiri dari: </p>
<p id="letter" class="invalid"><b>Huruf kecil</b></p>
<p id="capital" class="invalid"><b>Huruf besar</b></p>
<p id="number" class="invalid"><b>Nomor</b></p>
<p id="length" class="invalid"><b>8 karakter</b></p>
<p id="spechar" class="invalid" style="text-align:left;"><b>Karakter khusus</b></p>
</div>
<br>
<span class="txt2">Konfirmasi Password</span>
<div class="wrap-input validate-input m-b-25" data-validate="Masukkan password">
<input class="input" type="password" name="konfirmasi_password" placeholder="">
<span class="focus-input"></span>
</div>
<?php echo $kunci; ?>
<!-- site key -->
<!-- <div class="g-recaptcha mb-3" data-sitekey="6Ld3FuYcAAAAADmklc5SwsdjDSWbwXADHj0V4sQN" data-expired-callback="recaptchaExpired" onload="getReCaptcha()"></div> -->
<div class="container-login-form-btn p-t-15 p-b-30">
<button class="login-form-btn" name="submit">
Daftar
</button>
</div>
<div class="text-center">
<a href="index.php" class="txt2 hov1">Kembali</a>
</div>
<hr>
</form>
</div>
</div>
<!-- java script -->
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<script src="vendor/animsition/js/animsition.min.js"></script>
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
</body>
<script>
// function getReCaptcha(){
// grecaptcha.ready(function() {
// grecaptcha.render('g-recaptcha', {
// 'sitekey': '6Ld3FuYcAAAAADmklc5SwsdjDSWbwXADHj0V4sQN',
// 'expired-callback': fnCallback
// });
// });
//}
// getReCaptcha();
//setInterval(function(){getReCaptcha();}, 5*60*100);
// var fnCallback = function() {
// grecaptcha.reset();
// };
function recaptchaExpired(){
alert("Your Recaptcha has expired, please verify it again !");
}
var myInput = document.getElementById("pass");
var letter = document.getElementById("letter");
var capital = document.getElementById("capital");
var number = document.getElementById("number");
var spechar = document.getElementById("spechar");
var length = document.getElementById("length");
myInput.onfocus = function() {
document.getElementById("message").style.display = "block";
}
myInput.onblur = function() {
document.getElementById("message").style.display = "block";
}
myInput.onkeyup = function() {
// Validate lowercase letters
var lowerCaseLetters = /[a-z]/g;
if (myInput.value.match(lowerCaseLetters)) {
letter.classList.remove("invalid");
letter.classList.add("valid");
} else {
letter.classList.remove("valid");
letter.classList.add("invalid");
}
// Validate capital letters
var upperCaseLetters = /[A-Z]/g;
if (myInput.value.match(upperCaseLetters)) {
capital.classList.remove("invalid");
capital.classList.add("valid");
} else {
capital.classList.remove("valid");
capital.classList.add("invalid");
}
// Validate numbers
var numbers = /[0-9]/g;
if (myInput.value.match(numbers)) {
number.classList.remove("invalid");
number.classList.add("valid");
} else {
number.classList.remove("valid");
number.classList.add("invalid");
}
//specials character
var spechars = /[!@#$%^&*()_+\-=\[\]{};:\\|,.<>\/?~]/;
if (myInput.value.match(spechars)) {
spechar.classList.remove("invalid");
spechar.classList.add("valid");
} else {
spechar.classList.remove("valid");
spechar.classList.add("invalid");
}
// Validate length
if (myInput.value.length >= 8) {
length.classList.remove("invalid");
length.classList.add("valid");
} else {
length.classList.remove("valid");
length.classList.add("invalid");
}
}
</script>
</html>