-
Notifications
You must be signed in to change notification settings - Fork 0
/
proses.php
110 lines (103 loc) · 4.14 KB
/
proses.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
<?php
class sewa{
private $conn;
public function __construct(){
$server="localhost";
$user="root";
$pass="";
$db="sewa";
$this->conn=mysqli_connect($server,$user,$pass,$db);
}
public function registrasi($nama,$email,$password,$alamat,$hp){
$sql = mysqli_query($this->conn, "INSERT INTO akun (email,password, akses) VALUES ('$email', md5('$password'), 'user')");
$ambil_id = mysqli_query($this->conn, "SELECT id_user FROM akun WHERE email='$email' AND password=md5('$password')");
$row = mysqli_fetch_assoc($ambil_id);
$id_user = $row['id_user'];
$user = mysqli_query($this->conn, "INSERT INTO data_user (nama, email, id_user, alamat, hp, foto) VALUES ('$nama', '$email', $id_user, '$alamat', '$hp', 'gambar/default.png')");
if ($sql && $user) {
?>
<script>
alert("Registrasi Berhasil");
location="login.php";
</script>
<?php
} else {
echo mysqli_error($this->conn);
}
?>
<script>
alert("Registrasi Gagal");
location="daftar.php";
</script>
<?php
}
public function login($email,$password){
$sql = mysqli_query($this->conn,"SELECT * FROM akun WHERE email = '$email' AND password = md5('$password')");
$row = mysqli_fetch_assoc($sql);
$num = mysqli_num_rows($sql);
if ($num != 0) {
session_start();
if ($row['akses'] == "admin") {
$_SESSION['akses'] = $row['akses'];
$_SESSION['login'] = "sukses";
header("location: admin/dashboard.php");
} else {
$_SESSION['id_user'] = $row['id_user'];
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['nama'] = $row['nama'];
$_SESSION['akses'] = $row['akses'];
$_SESSION['login'] = "sukses";
header("location: user/dashboard.php");
}
}
else{
?>
<script>
alert("Akun tidak ditemukan");
location="login.php";
</script>
<?php
}
}
public function loginadmin($email,$password){
$sql = mysqli_query($this->conn,"SELECT * FROM akun_admin WHERE email = '$email' AND password = md5('$password')");
$row = mysqli_fetch_assoc($sql);
$num = mysqli_num_rows($sql);
if ($num != 0) {
session_start();
if ($row['akses'] == "admin") {
$_SESSION['akses'] = $row['akses'];
$_SESSION['login'] = "sukses";
header("location: admin/dashboard.php");
} else {
$_SESSION['id_user'] = $row['id_user'];
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['nama'] = $row['nama'];
$_SESSION['akses'] = $row['akses'];
$_SESSION['login'] = "sukses";
header("location: user/dashboard.php");
}
}
else{
?>
<script>
alert("Akun tidak ditemukan");
location="loginadmin.php";
</script>
<?php
}
}
}
$sewa = new sewa();
if (isset($_GET['registrasi'])) {
$sewa -> registrasi($_POST['nama'],$_POST['email'],$_POST['password'],$_POST['alamat'],$_POST['hp']);
}
if (isset($_GET['login'])) {
$sewa -> login($_POST['email'],$_POST['password']);
}
if (isset($_GET['loginadmin'])) {
$sewa -> loginadmin($_POST['email'],$_POST['password']);
}
?>