Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') or exit('No direct script access allowed');
- class Login extends CI_Controller
- {
- var $API = "";
- public function __construct()
- {
- parent::__construct();
- $this->load->library('form_validation');
- $this->API = "https://192.168.1.36:8443/saber-cia-api/";
- //$this->API = "http://localhost/fake_login/";
- }
- public function index()
- {
- $this->load->view('login/v_login');
- }
- public function doLogin()
- {
- $data = array(
- 'username' => $this->input->post('username'),
- 'password' => $this->input->post('password')
- );
- $header = array(
- 'Content-Type: application/json'
- );
- $response = $this->rest->send("POST", "login", $header, $data);
- // $req = json_encode($data);
- // $ch = curl_init($this->API."login");
- // // $ch = curl_init($this->API . "login.html");
- // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- // curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
- // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // //start for https request
- // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- // //end for https request
- // curl_setopt(
- // $ch,
- // CURLOPT_HTTPHEADER,
- // array(
- // 'Content-Type: application/json'
- // )
- // );
- // $result = curl_exec($ch);
- // curl_close($ch);
- // // do anything you want with your response
- // //echo $result;
- // $response = json_decode($result, true);
- if ($response['code'] != 200) {
- $this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">Wrong password!</div>');
- redirect('login');
- }
- $session = array(
- 'username' => $response['data']['username'],
- 'role' => $response['data']['role'],
- 'token' => $response['data']['token'],
- 'firstName' => $response['data']['first_name']
- );
- $this->session->set_userdata($session);
- redirect('admin/dashboard');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement