44 lines
1018 B
PHP
44 lines
1018 B
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class User extends CI_Controller {
|
|
function __Construct()
|
|
{
|
|
parent ::__construct();
|
|
$this->load->model('UserModel');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$location = site_url('welcome');
|
|
header("Location: ".$location);
|
|
}
|
|
|
|
public function login()
|
|
{
|
|
$data['username'] = $_POST['username'];
|
|
$data['password'] = $_POST['password'];
|
|
$result = $this->UserModel->login($data);
|
|
if (isset($result)){
|
|
$newdata = array(
|
|
'username' => $result->username,
|
|
'type' => $result->type,
|
|
'logged_in' => TRUE
|
|
);
|
|
$this->session->set_userdata($newdata);
|
|
$location = site_url('welcome');
|
|
header("Location: ".$location);
|
|
}else{
|
|
$location = site_url('welcome');
|
|
header("Location: ".$location);
|
|
}
|
|
}
|
|
|
|
public function logout(){
|
|
$deldata = array('username','type','logged_in');
|
|
$this->session->unset_userdata($deldata);
|
|
$location = site_url('welcome');
|
|
header("Location: ".$location);
|
|
}
|
|
}
|
|
?>
|