Example #1
0
function is_user()
{
    $CI =& get_instance();
    if (user_logged() && $CI->session->userdata('privileges') == 0) {
        return TRUE;
    } else {
        return FALSE;
    }
}
Example #2
0
 public function login()
 {
     //If the user is logged, redirect to index page
     if (user_logged()) {
         header('location: ' . base_url());
     }
     //Set the validation rules
     $this->form_validation->set_rules('user_email', 'Email', 'required');
     $this->form_validation->set_rules('user_password', 'Password', 'required');
     //Set the page title
     $data['title'] = 'Login';
     //Store the login errors
     $data['login_errors'] = '';
     //Get the menu
     $data['menu'] = $this->MenuModel->getMenu();
     //Check if the form has been submited
     if ($this->form_validation->run()) {
         //Recieve the the information passed by POST
         $email = $this->input->post('user_email');
         $password = $this->input->post('user_password');
         //Get and compare the input info with the database info
         $loginInfo = $this->UserModel->getLoginInfo($email);
         //If the user exist and is an active user an the password is correct, is log in
         if (count($loginInfo) > 0 && $loginInfo->user_status == 'active' && $password == $loginInfo->user_password) {
             $user_data = array('userId' => $loginInfo->user_id, 'userName' => $loginInfo->user_name, 'privileges' => $loginInfo->user_privileges);
             $this->session->set_userdata($user_data);
             header('location: ' . base_url());
         } else {
             $data['login_errors'] = 'Datos incorrectos';
             $this->load->view('templates/header', $data);
             $this->load->view('templates/site/menu', $data);
             $this->load->view('user/login', $data);
         }
     } else {
         $this->load->view('templates/header', $data);
         $this->load->view('templates/site/menu', $data);
         $this->load->view('user/login', $data);
     }
     $this->load->view('templates/footer');
 }
Example #3
0
function main()
{
    // Set day to show
    if (isset($_GET['day'])) {
        $day = $_GET['day'];
    } else {
        $day = date('Y-m-d');
    }
    create_html_start();
    // Check if there is POST-data
    check_post_values();
    // Show login or user own page
    if (user_logged()) {
        show_own_page($day);
    } else {
        show_login();
    }
    create_html_end();
}