Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if(!defined('BASEPATH')) exit('No direct script access allowed');
- class Login extends CI_Controller
- {
- /**
- * This is default constructor of the class
- */
- public function __construct()
- {
- parent::__construct();
- $this->load->model('login_model');
- }
- /**
- * Index Page for this controller.
- */
- public function index()
- {
- $this->isLoggedIn();
- }
- /**
- * This function used to check the user is logged in or not
- */
- function isLoggedIn()
- {
- $isLoggedIn = $this->session->userdata('isLoggedIn');
- if(!isset($isLoggedIn) || $isLoggedIn != TRUE)
- {
- $data['tahunajaran'] = $this->login_model->lihat_tahunajaran();
- $this->load->view('login', $data);
- }
- else
- {
- redirect('/dashboard');
- }
- }
- /**
- * This function used to logged in user
- */
- public function loginMe()
- {
- $this->load->library('form_validation');
- $this->form_validation->set_rules('username', 'Username', 'required|max_length[128]|');
- $this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|');
- if($this->form_validation->run() == FALSE)
- {
- $this->index();
- }
- else
- {
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- $thnajaran = $this->input->post('thnajaran');
- $tipe = $this->input->post('tipe');
- if($tipe != "Admin"){
- $result = $this->login_model->loginMe($username, $password);
- }else{
- $result = $this->login_model->loginAdmin($username, $password);
- }
- if(count($result) > 0)
- {
- foreach ($result as $res)
- {
- if($tipe != "Admin"){
- $sessionArray = array('userId'=>$res->userId,
- 'idmatpel'=>$res->id_matpel,
- 'role'=>$res->roleId,
- 'roleText'=>$res->role,
- 'thnajaran'=>$thnajaran,
- 'name'=>$res->name,
- 'isLoggedIn' => TRUE
- );
- }else{
- $sessionArray = array('userId'=>$res->userId,
- 'role'=>$res->roleId,
- 'roleText'=>$res->role,
- 'thnajaran'=>$thnajaran,
- 'name'=>$res->name,
- 'isLoggedIn' => TRUE
- );
- }
- $this->session->set_userdata($sessionArray);
- redirect('/dashboard');
- }
- }
- else
- {
- $this->session->set_flashdata('error', 'Username or password mismatch');
- redirect('/login');
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement