· 6 years ago · Jun 10, 2019, 03:40 PM
1<?php
2defined('BASEPATH') OR exit('No direct script access allowed');
3
4class Welcome extends CI_Controller {
5
6 /**
7 * Index Page for this controller.
8 *
9 * Maps to the following URL
10 * http://example.com/index.php/welcome
11 * - or -
12 * http://example.com/index.php/welcome/index
13 * - or -
14 * Since this controller is set as the default controller in
15 * config/routes.php, it's displayed at http://example.com/
16 *
17 * So any other public methods not prefixed with an underscore will
18 * map to /index.php/welcome/<method_name>
19 * @see https://codeigniter.com/user_guide/general/urls.html
20 */
21
22
23
24 public function __construct(){
25 parent::__construct();
26
27 $this->load->model('admin_model'); //Load the Model here
28 $this->load->helper('url');
29 $this->load->helper(array('form', 'url'));
30 $this->load->library('session');
31 $this->load->model('Security_model');
32 $this->load->model('AdminLogs_model');
33
34 }
35
36
37
38 public function index()
39 {
40 //$this->load->view('welcome_message');
41
42 redirect('login', 'refresh');
43 }
44
45 public function login()
46 {
47
48
49 $captcha= $this->input->post('g-recaptcha-response');
50
51 $email = $this->input->post('email');
52 //echo "<br>";
53 $pass = $this->input->post('pass');
54 //echo "<br>";
55 // echo $this->input->post('g-recaptcha-response');
56 $secretKey = "6LeeXqAUAAAAAK4KtAaKlb50CZD9ZeJN_j2av43j";
57 //$this->load->view('welcome_message');
58
59 //if($this->admin_model->login("1");
60 //redirect('admin/index', 'refresh');
61
62 $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) . '&response=' . urlencode($captcha);
63
64 $response = file_get_contents($url);
65 $responseKeys = json_decode($response,true);
66
67 if(!$responseKeys["success"]) {
68
69 redirect('login', 'refresh');
70 }
71
72 if($this->admin_model->verify_email($email,$pass)!=true){
73 //$data['error'] =$this->admin_model->errorMessage();
74 $this->session->set_flashdata('message', $this->admin_model->errorMessage());
75 //$this->load->view('welcome_message',$data);
76 redirect('login', 'refresh');
77 }
78
79
80
81 else{
82
83 $this->AdminLogs_model->login_admin($this->admin_model->get_adminID($email,$pass));
84
85
86
87 //Get Admin Details for Session
88 $id = $this->admin_model->get_adminID($email,$pass);
89 $adminData = $this->admin_model->getAdmin($id);
90
91 $newdata = array(
92 'id'=> $id,
93 'Fullname' => $this->Security_model->secured_decrypt($adminData->FN)." ".$this->Security_model->secured_decrypt($adminData->MN)." ".$this->Security_model->secured_decrypt($adminData->LN),
94 'email' => $this->Security_model->secured_decrypt($adminData->email),
95 'adminType' => $adminData->adminType,
96 'pic' => $adminData->pic,
97 'logged_in' => TRUE
98 );
99
100 $this->session->set_userdata($newdata);
101
102 redirect('admin/dashboard', 'refresh');
103
104 }
105
106
107 }
108
109
110 public function logout()
111 {
112
113 $array_items = array('id','Fullname','adminType','pic','logged_in', 'email');
114 $this->session->unset_userdata($array_items);
115
116 redirect('login', 'refresh');
117
118
119
120 }
121
122
123}