Welcome Guest, Not a member yet? Register   Sign In
Post your controller!
#21

[eluser]richzilla[/eluser]
is 106 lines too big? oh well..

my very first bit of proper codeigniter stuff:

Code:
<?php
    class Site extends Controller {
    
        function index() {
            $this->load->view('site_view');
        }
        
        function login() {
            $this->form_validation->set_rules('username','User Name', 'required|xss_clean');
            $this->form_validation->set_rules('password','Password','required|xss_clean');
            
            $this->form_validation->set_error_delimiters('<div class="error">','</div>');
            
            $data = array (
            'userName' => $this->input->post('username'),
            'userPass' => $this->input->post('password')
            );
            
            if ($this->form_validation->run() == FALSE) {
                $this->index();
            }
            else {
                
                $query = $this->user_model->checklog($data);
                
                if ($query->num_rows() > 0) {
                    $row = $query->row();
                    $this->session->set_userdata(array('loggedIn' => TRUE, 'userId' => $row->id, 'userName' => $row->userName, 'userGroup' => $row->uGroup));
                    $this->_secure();
                    
                }
                else {
                    $this->session->set_flashdata('status','The credentials you entered are incorrect, please try again.');
                    redirect('site');
                }
            }
        
        }
        
        function _secure() {
            if ($this->session->userdata('loggedIn') == TRUE) {
                $group = $this->session->userdata('userGroup');    
                switch ($group) {
                    case 'STA':
                        $this->staff();
                        break;
                    case 'ADM':
                        $this->secure();
                        break;
                    case 'CLI':
                        $this->client();
                        break;
                    default:
                        $this->_noview();
                        break;
                }
                
            }
            else {
                $this->_noview();
            }
        }
        
        function secure() {
            if ($this->session->userdata('userGroup') != 'ADM') {
                $this->_noview();
            }
            else {
                $this->load->view('secure_page');
            }
        
        }
        
        function _noview() {
            $this->session->set_flashdata('status','You are not authorised to view this page');
            redirect('site');
        }
        
        function staff() {
            if ($this->session->userdata('userGroup') === 'ADM') {
                $this->load->view('staff_view');
            }
            elseif ($this->session->userdata('userGroup') === 'STA') {
                $this->load->view('staff_view');
            }
            else {
                $this->_noview();
            }
        
        }
        
        function logout() {
            $this->session->sess_destroy();
            $this->load->view('site_view');
        }
        
        function client() {
            if ($this->session->userdata('loggedIn') == TRUE) {
                $this->load->view('client_view');
            }
            else {
                $this->_noview();
            }
        }
    
    }


Messages In This Thread
Post your controller! - by El Forum - 08-30-2009, 12:19 AM
Post your controller! - by El Forum - 08-30-2009, 01:36 AM
Post your controller! - by El Forum - 08-30-2009, 07:19 AM
Post your controller! - by El Forum - 08-30-2009, 12:31 PM
Post your controller! - by El Forum - 08-30-2009, 12:44 PM
Post your controller! - by El Forum - 08-30-2009, 08:59 PM
Post your controller! - by El Forum - 08-30-2009, 10:07 PM
Post your controller! - by El Forum - 08-31-2009, 02:13 AM
Post your controller! - by El Forum - 08-31-2009, 03:13 AM
Post your controller! - by El Forum - 08-31-2009, 03:19 AM
Post your controller! - by El Forum - 08-31-2009, 04:43 AM
Post your controller! - by El Forum - 08-31-2009, 04:49 AM
Post your controller! - by El Forum - 09-01-2009, 01:05 AM
Post your controller! - by El Forum - 09-01-2009, 09:30 PM
Post your controller! - by El Forum - 09-02-2009, 02:42 AM
Post your controller! - by El Forum - 09-02-2009, 05:34 AM
Post your controller! - by El Forum - 09-02-2009, 09:02 AM
Post your controller! - by El Forum - 09-02-2009, 09:43 AM
Post your controller! - by El Forum - 09-02-2009, 10:13 AM
Post your controller! - by El Forum - 09-02-2009, 01:13 PM
Post your controller! - by El Forum - 09-03-2009, 06:40 AM
Post your controller! - by El Forum - 11-03-2009, 10:20 PM
Post your controller! - by El Forum - 11-03-2009, 11:02 PM
Post your controller! - by El Forum - 11-03-2009, 11:33 PM
Post your controller! - by El Forum - 11-04-2009, 12:09 AM
Post your controller! - by El Forum - 11-04-2009, 03:36 AM
Post your controller! - by El Forum - 11-04-2009, 07:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB