Advertisement
bystefu1

Login Controller

Jan 4th, 2020
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Login extends CI_Controller {
  4.  
  5.     function __construct() {
  6.         parent::__construct();
  7.         $this->load->model('login_model');
  8.     }
  9.     public function index() {
  10.         //check if i can pass some data to view
  11.         $data['title_header'] = 'Login title';
  12.         $this->load->view('foundation/header', $data);
  13.  
  14.         //security inputs in controller, if some data are sents
  15.         $this->check_login();
  16.  
  17.         //loading login page
  18.         $this->load->view("login_view");
  19.         $this->load->view('foundation/footer');
  20.     }
  21.     private function check_login() {
  22.         //check if is not empty
  23.         if (!$this->input->post('username') && !$this->input->post('password')) {
  24.             return;
  25.         }
  26.         //if i have some value i begin the test...
  27.         $this->load->library('form_validation');
  28.         $this->form_validation->set_rules('username', 'Name', 'required|max_length[20]');
  29.         $this->form_validation->set_rules('password', 'Password', 'required|max_length[20]');
  30.         //
  31.         if ($this->form_validation->run()) {
  32.             //if everything is ok, let's check in db
  33.             $params = array(
  34.                 'username' => $this->input->post('username'),
  35.                 'password' => $this->input->post('password'),
  36.                 /* and username and password is secure by form validation? */
  37.             );
  38.            
  39.             $this->login_model->check_login_database($params);
  40.         } else {
  41.             //how i know what is wrong?name or password?i'm confuse
  42.             $this->session->set_flashdata('login', array('class' => 'alert alert-danger', 'message' => 'Something is wrong'));
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement