Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. Controller
  2.  
  3. function add()
  4. {
  5. $this->load->helper(array('form', 'url'));
  6. $this->load->library('form_validation');
  7. $rules = array(
  8. array(
  9. 'field' => 'email',
  10. 'label' => 'email',
  11. 'rules' => 'required|valid_email'
  12. ),
  13. array(
  14. 'field' => 'username',
  15. 'label' => 'username',
  16. 'rules' => 'trim|required|min_length[5]|max_length[50]|xss_clean'
  17. ),
  18. array(
  19. 'field' => 'password',
  20. 'label' => 'Password',
  21. 'rules' => 'required|min_length[5]'
  22. ),
  23. array(
  24. 'field' => 'konfirmasi_password',
  25. 'label' => 'Konfirmasi Password',
  26. 'rules' => 'required|matches[konfirmasi_password'
  27. )
  28. );
  29. $this->form_validation->set_rules($rules);
  30. if ($this->form_validation->run() == FALSE)
  31. {
  32. $this->load->view('register_view');
  33. }
  34. else
  35. {
  36. //echo 'Data berhasil dimasukkan';
  37. $this->load->model('user_model');
  38. $hash = $_POST['password'];
  39. $hash = sha1($hash);
  40. $data = array('email' => $_POST['email'], 'username' => $_POST['username'], 'password' => $hash,'is_Active'=>$_POST['is_Active'] );
  41. $this->user_model->insert($data);
  42. $this->load->helper('url');
  43. redirect('user');
  44.  
  45. }
  46.  
  47. function login(){
  48. $this->load->view('login_view');
  49.  
  50. }
  51.  
  52. function validate_login() {
  53. $this->load->model('user_model');
  54. $this->load->library('session');
  55. $cek=$this->user_model->validasi();
  56. if($cek==true ){
  57. $session=array('username'=>$this->input->post('username'),'is_loged_in'=>true);
  58. $this->session->set_userdata($session);
  59. // $this->load->helper('url');
  60. // redirect ('user/data');
  61. echo 'bisaaaa';
  62. }
  63. else{
  64. // $this->load->helper('url');
  65. // redirect('user/login');
  66. echo 'todak bisaaaa';
  67. }
  68. }
  69.  
  70. model
  71.  
  72. function validasi()
  73. {
  74. $this->load->database();
  75. $username=$this->input->post('username');
  76. $password=$this->input->post(sha1($_POST['password']));
  77. $this->db->where('username',$username);
  78. $this->db->where('password', $password);
  79.  
  80. $ambil = $this->db->get('users');
  81.  
  82. if($ambil->num_rows == 1)
  83. {
  84. return true;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement