-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuth.php
More file actions
197 lines (164 loc) · 5.9 KB
/
Auth.php
File metadata and controls
197 lines (164 loc) · 5.9 KB
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
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Auth extends CI_Controller
{
public function __construct()
{
parent::__construct();
// check_already_login();
}
public function index()
{
check_already_login();
$this->load->view('Login');
}
// function Log()
// {
// check_already_login();
// $this->load->view('Login');
// }
public function Log_act()
{
// check_already_login();
$this->_rules();
if ($this->form_validation->run() == FALSE) {
$this->index();
} else {
?>
<link rel="stylesheet" href="<?= base_url() ?>assets/sweetalert2/sweetalert2.min.css">
<script src="<?= base_url() ?>assets/sweetalert2/sweetalert2.min.js"></script>
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, Helvetica, sans-serif;
font-size: 1.125em;
font-weight: normal;
}
</style>
<body></body>
<?php
$username = htmlspecialchars($this->input->post('username', TRUE), ENT_QUOTES);
$password = htmlspecialchars($this->input->post('pass', TRUE), ENT_QUOTES);
$cek_admin = $this->Log_model->auth_admin($username, $password);
if ($cek_admin->num_rows() > 0) { //jika login sebagai admin
$data = $cek_admin->row_array();
$this->session->set_userdata('masuk', TRUE);
$this->session->set_userdata('akses', '1');
$this->session->set_userdata('ses_id', $data['id_admin']);
$this->session->set_userdata('ses_nama', $data['nama']);
$this->session->set_userdata('ses_username', $data['username']);
$nm = $this->session->userdata('ses_nama');
$this->session->set_flashdata('success', "Selamat Datang $nm");
redirect('Barang');
} else { //jika login sebagai kasir
$cek_kasir = $this->Log_model->auth_user($username, $password);
if ($cek_kasir->num_rows() > 0) {
$data = $cek_kasir->row_array();
$this->session->set_userdata('masuk', TRUE);
$this->session->set_userdata('akses', '2');
$this->session->set_userdata('ses_id', $data['id_user']);
$this->session->set_userdata('ses_nama', $data['nama']);
$this->session->set_userdata('ses_username', $data['username']);
$nm = $this->session->userdata('ses_nama');
$this->session->set_flashdata('success', "Selamat Datang $nm");
redirect('Barang');
} else {
?>
<Script>
Swal.fire({
icon: 'error',
title: 'Failure',
text: 'Login gagal, Username atau Password salah',
showConfirmButton: false,
timer: 1500
}).then((result) => {
window.location = '<?= base_url('Auth') ?>';
})
</Script>
<?php
}
}
}
}
public function set_profile()
{
$data['title'] = "Edit";
$data['judul'] = "Edit Profile";
$data['error'] = '';
// $user = $this->db->get('tbl_admin');
// $user = $this->db->get('tbl_user');
// $where['id_project'] = $id_project;
// $data['user'] = $this->db->get('tbl_admin');
// $data['user'] = $this->db->get('tbl_user');
$data['user'] = $this->User_model->get_data_login($this->session->userdata('sess_id'));
$this->load->view('templates/header', $data);
$this->load->view('templates/sidebar');
$this->load->view('F_user/Update_profile', $data);
$this->load->view('templates/footer');
}
public function update_profile()
{
$id = htmlspecialchars($this->input->post('id', TRUE), ENT_QUOTES);
$akses = htmlspecialchars($this->input->post('akses', TRUE), ENT_QUOTES);
//print_r($akses);exit;
if ($akses == 1) {
$nama = $this->input->post('nama');
$username = $this->input->post('username');
if($this->input->post('password')!=""){
$password = $this->input->post('password');
$this->db->query("UPDATE tbl_admin SET username='{$username}',pass=MD5('{$password}'),nama = '{$nama}'
WHERE id_admin = '{$id}'");
}else{
$data = [
'nama' => $nama,
'username' => $username
];
$this->db->where('id_admin', $id);
$this->db->update('tbl_admin', $data);
}
$this->session->set_flashdata('pesan', '
<div class="alert alert-success alert-dismissible fade show" role="alert">
Data Berhasil Di Ubah !
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>');
redirect('Auth/set_profile');
} else {
$nama = $this->input->post('nama');
$username = $this->input->post('username');
if($this->input->post('password')!=""){
$password = $this->input->post('password');
$this->db->query("UPDATE tbl_user SET username='{$username}',pass=MD5('{$password}'),nama = '{$nama}'
WHERE id_user = '{$id}'");
}else{
$data = [
'nama' => $nama,
'username' => $username
];
$this->db->where('id_user', $id);
$this->db->update('tbl_user', $data);
}
$this->session->set_flashdata('pesan', '
<div class="alert alert-success alert-dismissible fade show" role="alert">
Data Berhasil Di Ubah !
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>');
redirect('Auth/set_profile');
}
}
public function _rules()
{
$this->form_validation->set_rules('username', 'Username', 'required', array('required' => '%s harus diisi !!!'));
$this->form_validation->set_rules('pass', 'Password', 'required', array('required' => '%s harus diisi !!!'));
}
public function Logout()
{
$this->session->sess_destroy();
$url = base_url('Auth');
redirect($url);
}
}
/* End of file Auth.php */
/* Location: ./application/controllers/Auth.php */