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 @@
+
+