SHARE
TWEET

Untitled

a guest Dec 8th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3.  
  4. class Login extends CI_Controller
  5. {
  6.  
  7.     var $API = "";
  8.  
  9.     public function __construct()
  10.     {
  11.         parent::__construct();
  12.         $this->load->library('form_validation');
  13.         $this->API = "https://192.168.1.36:8443/saber-cia-api/";
  14.         //$this->API = "http://localhost/fake_login/";
  15.     }
  16.  
  17.     public function index()
  18.     {
  19.         $this->load->view('login/v_login');
  20.     }
  21.  
  22.  
  23.  
  24.     public function doLogin()
  25.     {
  26.         $data = array(
  27.             'username' => $this->input->post('username'),
  28.             'password' => $this->input->post('password')
  29.         );
  30.  
  31.         $header = array(
  32.             'Content-Type: application/json'
  33.         );
  34.  
  35.         $response = $this->rest->send("POST", "login", $header, $data);
  36.         // $req = json_encode($data);
  37.  
  38.         // $ch = curl_init($this->API."login");
  39.         // // $ch = curl_init($this->API . "login.html");
  40.         // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  41.         // curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
  42.         // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  43.         // //start for https request
  44.         // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  45.         // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  46.         // //end for https request
  47.         // curl_setopt(
  48.         //  $ch,
  49.         //  CURLOPT_HTTPHEADER,
  50.         //  array(
  51.         //      'Content-Type: application/json'
  52.         //  )
  53.         // );
  54.  
  55.         // $result = curl_exec($ch);
  56.  
  57.         // curl_close($ch);
  58.         // // do anything you want with your response
  59.         // //echo $result;
  60.  
  61.         // $response = json_decode($result, true);
  62.  
  63.         if ($response['code'] != 200) {
  64.             $this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">Wrong password!</div>');
  65.             redirect('login');
  66.         }
  67.  
  68.         $session = array(
  69.             'username' => $response['data']['username'],
  70.             'role' => $response['data']['role'],
  71.             'token' => $response['data']['token'],
  72.             'firstName' => $response['data']['first_name']
  73.         );
  74.  
  75.         $this->session->set_userdata($session);
  76.         redirect('admin/dashboard');
  77.     }
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top