Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Home extends CI_Controller {
  5.  
  6. function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->library(array('template','cart', 'form_validation'));
  10. $this->load->model('m_home');
  11. }
  12.  
  13. public function index()
  14. {
  15. $data['data'] = $this->m_home->get_where('t_items', ['status' => 1]);
  16. $this->template->sageng('home', $data);
  17. }
  18.  
  19. public function kategori()
  20. {
  21. if (!$this->uri->segment(3)) {
  22. redirect('home');
  23. }
  24. $url = strtolower(str_replace([' ','%20','_'], '-', $this->uri->segment(3)));
  25.  
  26. $table = 't_kategori k JOIN t_rkategori rk ON (k.id_kategori = rk.id_kategori) JOIN
  27. t_items i ON (rk.id_item = i.id_item)';
  28.  
  29. $data['data'] = $this->m_home->get_where($table, ['i.status' => 1, 'k.url' => $url]);
  30. $data['url'] = ucwords(str_replace(['-','%20','_'], ' ', $this->uri->segment(3)));
  31.  
  32. $this->template->sageng('home', $data);
  33. }
  34.  
  35. public function detail()
  36. {
  37. if(is_numeric($this->uri->segment(3)))
  38. {
  39. $id = $this->uri->segment(3);
  40. $data['data'] = $this->m_home->get_where('t_items', array('id_item' => $id));
  41.  
  42. $this->template->sageng('item_detail', $data);
  43. } else {
  44. redirect('home');
  45. }
  46. }
  47.  
  48. public function registrasi()
  49. {
  50. if($this->input->post('submit',TRUE) == 'Submit')
  51. {
  52. $this->load->library('form_validation');
  53.  
  54. $this->form_validation->set_rules('nama1', 'Nama Depan', "required|min_length[3]|regex_match[/^[a-zA-Z'.]+$/]");
  55. $this->form_validation->set_rules('nama2', 'Nama Belakang', "regex_match[/^[a-zA-Z'.]+$/]");
  56. $this->form_validation->set_rules('user', 'Username', "required|min_length[5]|regex_match[/^[a-zA-Z'.]+$/]");
  57. $this->form_validation->set_rules('email', 'Email', "required|valid_email");
  58. $this->form_validation->set_rules('pass1', 'Password', "required|min_length[5]");
  59. $this->form_validation->set_rules('pass2', 'Ketik Ulang Password', "required|matches[pass1]");
  60. $this->form_validation->set_rules('jk', 'Jenis Kelamin', "required");
  61. $this->form_validation->set_rules('telp', 'Telp', "required|min_length[8]|numeric");
  62. $this->form_validation->set_rules('alamat', 'Alamat', "required|min_length[10]");
  63.  
  64. if ($this->form_validation->run() == TRUE)
  65. {
  66. $data = array(
  67. 'username' => $this->input->post('user', TRUE),
  68. 'fullname' => $this->input->post('nama1', TRUE).' '.$this->input->post('nama2', TRUE),
  69. 'email' => $this->input->post('email', TRUE),
  70. 'password' => password_hash($this->input->post('pass1', TRUE), PASSWORD_DEFAULT, ['cost' => 10]),
  71. 'jk' => $this->input->post('jk', TRUE),
  72. 'telp' => $this->input->post('telp', TRUE),
  73. 'alamat' => $this->input->post('alamat', TRUE),
  74. 'status' => 1
  75. );
  76.  
  77. if ($this->m_home->insert('t_users', $data))
  78. {
  79. $this->template->sageng('reg_success');
  80. } else {
  81. echo '<script type="text/javascript">alert("Username/Email tidak tersedia");</script>';
  82. }
  83. }
  84. }
  85.  
  86. if ($this->session->userdata('user_login') == TRUE)
  87. {
  88. redirect('home');
  89. }
  90.  
  91. $data = array(
  92. 'user' => $this->input->post('user', TRUE),
  93. 'nama1' => $this->input->post('nama1', TRUE),
  94. 'nama2' => $this->input->post('nama2', TRUE),
  95. 'email' => $this->input->post('email', TRUE),
  96. 'jk' => $this->input->post('jk', TRUE),
  97. 'telp' => $this->input->post('telp', TRUE),
  98. 'alamat' => $this->input->post('alamat', TRUE),
  99. );
  100.  
  101. $this->template->sageng('register', $data);
  102. }
  103.  
  104. public function login()
  105. {
  106. if ($this->input->post('submit') == 'Submit')
  107. {
  108. $user = $this->input->post('username', TRUE);
  109. $pass = $this->input->post('password', TRUE);
  110.  
  111. $cek = $this->m_home->get_where('t_users', "username = '$user' || email = '$user'");
  112.  
  113. if ($cek->num_rows() > 0) {
  114. $data = $cek->row();
  115.  
  116. if (password_verify($pass, $data->password))
  117. {
  118. $datauser = array(
  119. 'user_id' => $data->id_user,
  120. 'name' => $data->fullname,
  121. 'user_login' => TRUE
  122. );
  123.  
  124. $this->session->set_userdata($datauser);
  125.  
  126. redirect('home');
  127.  
  128. } else {
  129.  
  130. $this->session->set_flashdata('alert', "Password yang anda masukan salah");
  131.  
  132. }
  133.  
  134. } else {
  135. $this->session->set_flashdata('alert', "Username Ditolak");
  136. }
  137.  
  138. }
  139.  
  140. if ($this->session->userdata('user_login') == TRUE)
  141. {
  142. redirect('home');
  143. }
  144.  
  145. $this->load->view('login');
  146. }
  147.  
  148. public function profil()
  149. {
  150. if (!$this->session->userdata('user_login'))
  151. {
  152. redirect('home/login');
  153. }
  154.  
  155. $get = $this->m_home->get_where('t_users', array('id_user' => $this->session->userdata('user_id')))->row();
  156.  
  157. if($this->input->post('submit',TRUE) == 'Submit')
  158. {
  159. $this->load->library('form_validation');
  160.  
  161. $this->form_validation->set_rules('nama1', 'Nama Depan', "required|min_length[3]|regex_match[/^[a-zA-Z'.]+$/]");
  162. $this->form_validation->set_rules('nama2', 'Nama Belakang', "regex_match[/^[a-zA-Z'.]+$/]");
  163. $this->form_validation->set_rules('user', 'Username', "required|min_length[5]|regex_match[/^[a-zA-Z'.]+$/]");
  164. $this->form_validation->set_rules('pass', 'Masukan Password Anda', "required|min_length[5]");
  165. $this->form_validation->set_rules('jk', 'Jenis Kelamin', "required");
  166. $this->form_validation->set_rules('telp', 'Telp', "required|min_length[8]|numeric");
  167. $this->form_validation->set_rules('alamat', 'Alamat', "required|min_length[10]");
  168.  
  169. if ($this->form_validation->run() == TRUE)
  170. {
  171. if (password_verify($this->input->post('pass', TRUE), $get->password))
  172. {
  173.  
  174. $data = array(
  175. 'username' => $this->input->post('user', TRUE),
  176. 'fullname' => $this->input->post('nama1', TRUE).' '.$this->input->post('nama2', TRUE),
  177. 'jk' => $this->input->post('jk', TRUE),
  178. 'telp' => $this->input->post('telp', TRUE),
  179. 'alamat' => $this->input->post('alamat', TRUE),
  180. );
  181.  
  182. if ($this->m_home->update('t_users', $data, array('id_user' => $this->session->userdata('user_id'))))
  183. {
  184.  
  185. $this->session->set_userdata(array('name' => $this->input->post('nama1', TRUE).' '.$this->input->post
  186. ('nama2', TRUE)));
  187.  
  188. redirect('home');
  189.  
  190. } else {
  191.  
  192. echo '<script type="text/javascript">alert("Username/Email tidak tersedia");</script>';
  193. }
  194. } else {
  195.  
  196. echo '<script type="text/javascript">alert("Password Salah..");window.location.replace("'.base_url().'/index.php/home/logout")</script>';
  197.  
  198. }
  199. }
  200. }
  201. $name = explode(' ', $get->fullname);
  202. $data['nama1'] = $name[0];
  203. $data['nama2'] = $name[1];
  204. $data['user'] = $get->username;
  205. $data['email'] = $get->email;
  206. $data['jk'] = $get->jk;
  207. $data['telp'] = $get->telp;
  208. $data['alamat'] = $get->alamat;
  209.  
  210. $this->template->sageng('user_profil', $data);
  211. }
  212.  
  213. public function logout()
  214. {
  215. $this->session->sess_destroy();
  216. redirect('home');
  217. }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement