umkm-app/application/controllers/login.php

48 lines
1.0 KiB
PHP
Raw Normal View History

2021-09-15 21:00:06 +07:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model("UserModel");
$this->load->library('form_validation');
}
public function index()
{
if($this->session->userdata('user_logged')!==null){
if($this->session->userdata('user_logged')->level=='admin'){
redirect(site_url('admin/dashboard'));
} else {
2021-09-16 15:37:22 +07:00
redirect(site_url('user/dashboard'));
2021-09-15 21:00:06 +07:00
}
}
if($this->input->post()){
if($this->UserModel->doLogin()) {
2021-09-16 15:37:22 +07:00
if($this->UserModel->isPemilik()){
redirect(site_url('user/dashboard'));
} else {
redirect(site_url('admin/dashboard'));
}
2021-09-15 21:00:06 +07:00
} else {
$data['error']="Username atau Password salah !";
$this->load->view('login',$data);
}
} else {
$this->load->view('login');
}
}
public function logout()
{
// hancurkan semua sesi
$this->session->sess_destroy();
redirect(site_url('login'));
}
}