Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Login extends CI_Controller {
- function __construct() {
- parent::__construct();
- //session_start();
- $this->load->model(array('user_model'));
- $this->load->helper(array('form', 'url', 'html', 'date', 'form_helper', 'file'));
- $this->load->library(array('form_validation', 'table', 'template', 'session', 'simple_login'));
- $this->load->database();
- $this->load->helper('url');
- }
- function index() {
- $session = $this->session->userdata('isLogin');
- if ($session == FALSE) {
- $this->template->displayUser('template_user/home');
- } else {
- if ($this->session->userdata('status') == 'Super Admin') {
- redirect('dashboard');
- } else if ($this->session->userdata('status') == 'Admin') {
- redirect('admin');
- } else if ($this->session->userdata('status') == 'User') {
- redirect('developer');
- }
- }
- }
- function proses() {
- $this->form_validation->set_rules('username', 'username', 'required');
- $this->form_validation->set_rules('password', 'password', 'required');
- if ($this->form_validation->run() == FALSE) {
- $this->template->displayUser('template_user/home');
- } else {
- $usr = $this->input->post('username');
- $psw = $this->input->post('password');
- //$u = mysqli_real_escape_string($usr);
- //$p = (mysqli_real_escape_string($psw));
- $cek = $this->user_model->cek($usr, $psw);
- if ($cek->num_rows() > 0) {
- //login berhasil, buat session
- foreach ($cek->result() as $qad) {
- $sess_data['id_user'] = $qad->id_user;
- $sess_data['nama'] = $qad->nama;
- $sess_data['username'] = $qad->username;
- $sess_data['status'] = $qad->status;
- $this->session->set_userdata('isLogin', TRUE);
- $this->session->set_userdata($sess_data);
- }
- if ($this->session->userdata('status') == 'Super Admin') {
- redirect('dashboard');
- } else if ($this->session->userdata('status') == 'Admin') {
- redirect('admin');
- } else if ($this->session->userdata('status') == 'User') {
- redirect('developer');
- }
- } else {
- $this->session->set_flashdata('result_login', '<br>Anda belum Login!<br>Username atau Password yang anda masukkan salah.');
- redirect('login');
- }
- }
- }
- function logout() {
- $this->session->sess_destroy();
- redirect('maps');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement