From 4f3175fc92d92d06c7658fb511f4328aef8bf53d Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Mon, 7 Mar 2016 21:04:33 +0100 Subject: [PATCH] Regio, user tabel and login is working. --- application/controllers/Login.php | 29 +++++++++++-- .../migrations/20160304200000_add_regio.php | 39 +++++++++++++++++ .../migrations/20160304220000_add_user.php | 42 +++++++++++++++++++ application/models/Login_model.php | 42 +++++++++++++++++++ application/models/Regio_model.php | 25 +++++++++++ application/views/login.php | 2 + 6 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 application/migrations/20160304200000_add_regio.php create mode 100644 application/migrations/20160304220000_add_user.php create mode 100644 application/models/Login_model.php create mode 100644 application/models/Regio_model.php diff --git a/application/controllers/Login.php b/application/controllers/Login.php index 15717f3..adae768 100644 --- a/application/controllers/Login.php +++ b/application/controllers/Login.php @@ -12,6 +12,15 @@ class Login extends CI_Controller public function index() { + // Load model + $this->load->model('Regio_model'); + $regios = $this->Regio_model->get_regio_list(); + + // Arrange data + foreach ($regios as $regio) { + $data['regio'][$regio['id']] = $regio['naam']; + } + // Header $this->load->view('header'); @@ -21,15 +30,29 @@ class Login extends CI_Controller if ($this->form_validation->run() == FALSE) { // login page - $this->load->view('login'); + $this->load->view('login', $data); } else { - echo "Done"; + // check login + $this->_checklogin(); } - // Footer $this->load->view('footer'); } + + private function _checklogin() + { + // Load model + $this->load->model('Login_model'); + $logincheck = $this->Login_model->check_user(); + + if ($logincheck == FALSE) { + echo "No user "; + } else { + echo "Ok"; + } + + } } ?> \ No newline at end of file diff --git a/application/migrations/20160304200000_add_regio.php b/application/migrations/20160304200000_add_regio.php new file mode 100644 index 0000000..cb8d4c1 --- /dev/null +++ b/application/migrations/20160304200000_add_regio.php @@ -0,0 +1,39 @@ +dbforge->add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => '3', + 'unsigned' => TRUE, + 'auto_increment' => TRUE, + ), + 'naam' => array( + 'type' => 'VARCHAR', + 'constraint' => '80', + ), + )); + $this->dbforge->add_key('id', TRUE); + $this->dbforge->create_table('regio'); + + $data = array( + 'id' => '0', + 'naam' => 'LSW' + ); + + $this->db->insert('regio', $data); + } + + public function down() + { + $this->dbforge->drop_table('regio'); + } +} \ No newline at end of file diff --git a/application/migrations/20160304220000_add_user.php b/application/migrations/20160304220000_add_user.php new file mode 100644 index 0000000..c36e179 --- /dev/null +++ b/application/migrations/20160304220000_add_user.php @@ -0,0 +1,42 @@ +dbforge->add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => '4', + 'unsigned' => TRUE, + 'auto_increment' => TRUE, + ), + 'regioid' => array( + 'type' => 'INT', + 'constraint' => '3', + 'unsigned' => TRUE, + ), + 'username' => array( + 'type' => 'VARCHAR', + 'constraint' => '80', + ), + 'password' => array( + 'type' => 'VARCHAR', + 'constraint' => '80', + ), + )); + $this->dbforge->add_key('id', TRUE); + $this->dbforge->create_table('user'); + + } + + public function down() + { + $this->dbforge->drop_table('user'); + } +} \ No newline at end of file diff --git a/application/models/Login_model.php b/application/models/Login_model.php new file mode 100644 index 0000000..6a8682d --- /dev/null +++ b/application/models/Login_model.php @@ -0,0 +1,42 @@ +security->xss_clean($this->input->post('username')); + $password = $this->security->xss_clean($this->input->post('password')); + $regioid = $this->security->xss_clean($this->input->post('regioid')); + //$username = $this->input->post('username'); + //$password = $this->input->post('password'); + //$regioid = $this->input->post('regioid'); + + // Search for user + $this->db->select('id'); + $this->db->where('username', $username); + $this->db->where('password', sha1($password)); + $this->db->where('regioid', $regioid); + $this->db->from('user'); + + $query = $this->db->get(); + //echo $query->num_rows(); + if ($query->num_rows() == 1) + { + return TRUE; + } else { + return FALSE; + } + + } +} \ No newline at end of file diff --git a/application/models/Regio_model.php b/application/models/Regio_model.php new file mode 100644 index 0000000..8b466ca --- /dev/null +++ b/application/models/Regio_model.php @@ -0,0 +1,25 @@ +db->select('id, naam'); + $this->db->from('regio'); + $this->db->order_by('naam', 'ASC'); + + $query = $this->db->get(); + + return $query->result_array(); + } +} \ No newline at end of file diff --git a/application/views/login.php b/application/views/login.php index 33fc4d8..db034d3 100644 --- a/application/views/login.php +++ b/application/views/login.php @@ -14,6 +14,8 @@

+ +