Browse Source

Regio, user tabel and login is working.

master
Rogier Neeleman 8 years ago
parent
commit
4f3175fc92
  1. 29
      application/controllers/Login.php
  2. 39
      application/migrations/20160304200000_add_regio.php
  3. 42
      application/migrations/20160304220000_add_user.php
  4. 42
      application/models/Login_model.php
  5. 25
      application/models/Regio_model.php
  6. 2
      application/views/login.php

29
application/controllers/Login.php

@ -12,6 +12,15 @@ class Login extends CI_Controller @@ -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 @@ -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";
}
}
}
?>

39
application/migrations/20160304200000_add_regio.php

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Add regio table
*/
class Migration_Add_regio extends CI_Migration
{
public function up()
{
$this->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');
}
}

42
application/migrations/20160304220000_add_user.php

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Add regio table
*/
class Migration_Add_user extends CI_Migration
{
public function up()
{
$this->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');
}
}

42
application/models/Login_model.php

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Regio model
*/
class Login_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function check_user()
{
// Validate POST
$username = $this->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;
}
}
}

25
application/models/Regio_model.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Regio model
*/
class Regio_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function get_regio_list()
{
$this->db->select('id, naam');
$this->db->from('regio');
$this->db->order_by('naam', 'ASC');
$query = $this->db->get();
return $query->result_array();
}
}

2
application/views/login.php

@ -14,6 +14,8 @@ @@ -14,6 +14,8 @@
<?php echo form_input('username'); ?><br>
<label for='text2'>Password:</label>
<?php echo form_password('password'); ?><br>
<label for='text2'>Regio:</label>
<?php echo form_dropdown('regioid', $regio); ?><br>
<?php echo form_submit('login', 'Login'); ?>
</div>
<div class='col_5'>

Loading…
Cancel
Save