Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Restrict extends CI_Controller {
  5.  
  6.     public function index(){
  7.         $data = array(
  8.             'scripts' => array(
  9.                 "util.js",
  10.                 "login.js"
  11.                 )
  12.              );
  13.         $this->template->show('login.php', $data);
  14.    
  15.     }
  16.  
  17.     public function ajax_login(){
  18.  
  19.         $result = false;
  20.         $id = false;
  21.  
  22.         $json = array();
  23.         $json['status'] = 1;
  24.         $json['error_list'] = array();
  25.  
  26.         $username = $this->input->post("username");
  27.         $password = $this->input->post("password");
  28.  
  29.         if (empty($username)) {
  30.             $json['status'] = 0;
  31.             $json['error_list']['#username'] = "Usuário não pode ser vazio!";
  32.         }else {
  33.             $this->load->model("users_model");
  34.             $result = $this->users_model->get_user_data($username);
  35.         }if ($result) {
  36.             $id = $result->$id;
  37.             $password_hash = $result->$password_hash;
  38.             if (password_verify($password, $password_hash)) {
  39.                 $this->session->set_userdata("id", $id);
  40.             }else {
  41.                 $json['status'] = 0;
  42.             }
  43.         }else {
  44.             $json['status'] = 0;
  45.         }
  46.         if ($json['status'] == 0 ) {
  47.             $json['error_list']['#btn_login'] = "Usuário e/ou senha incorretos!";
  48.         }
  49.         echo json_encode($json);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement