| Server IP : 162.214.74.102 / Your IP : 216.73.216.139 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/public_html/lrsys_apps/school/application/controllers/ |
Upload File : |
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/*
* @author : Joyonto Roy
* 30th July, 2014
* Creative Item
* www.creativeitem.com
* http://codecanyon.net/user/joyontaroy
*/
class Login extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('crud_model');
$this->load->database();
$this->load->library('session');
/* cache control */
$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header("Expires: Mon, 26 Jul 2010 05:00:00 GMT");
}
//Default function, redirects to logged in user area
public function index() {
if ($this->session->userdata('admin_login') == 1)
redirect(base_url() . 'index.php?admin/dashboard', 'refresh');
if ($this->session->userdata('teacher_login') == 1)
redirect(base_url() . 'index.php?teacher/dashboard', 'refresh');
if ($this->session->userdata('student_login') == 1)
redirect(base_url() . 'index.php?student/dashboard', 'refresh');
if ($this->session->userdata('parent_login') == 1)
redirect(base_url() . 'index.php?parents/dashboard', 'refresh');
if ($this->session->userdata('librarian_login') == 1)
redirect(base_url() . 'index.php?librarian/dashboard', 'refresh');
$this->load->view('backend/login');
}
//Ajax login function
function ajax_login() {
$response = array();
//Recieving post input of email, password from ajax request
$email = $_POST["email"];
$password = sha1($_POST["password"]);
$response['submitted_data'] = $_POST;
//Validating login
$login_status = $this->validate_login($email, $password);
$response['login_status'] = $login_status;
if ($login_status == 'success') {
$response['redirect_url'] = '';
}
//Replying ajax request with validation response
echo json_encode($response);
}
//Validating login from ajax request
function validate_login($email = '', $password = '') {
$credential = array('email' => $email, 'password' => $password);
// Checking login credential for admin
$query = $this->db->get_where('admin', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$this->session->set_userdata('admin_login', '1');
$this->session->set_userdata('admin_id', $row->admin_id);
$this->session->set_userdata('login_user_id', $row->admin_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'admin');
return 'success';
}
// Checking login credential for teacher
$query = $this->db->get_where('teacher', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$this->session->set_userdata('teacher_login', '1');
$this->session->set_userdata('teacher_id', $row->teacher_id);
$this->session->set_userdata('login_user_id', $row->teacher_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'teacher');
return 'success';
}
// Checking login credential for student
$query = $this->db->get_where('student', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$this->session->set_userdata('student_login', '1');
$this->session->set_userdata('student_id', $row->student_id);
$this->session->set_userdata('login_user_id', $row->student_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'student');
return 'success';
}
// Checking login credential for parent
$query = $this->db->get_where('parent', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$this->session->set_userdata('parent_login', '1');
$this->session->set_userdata('parent_id', $row->parent_id);
$this->session->set_userdata('login_user_id', $row->parent_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'parent');
return 'success';
}
// Checking login credential for librarian
$query = $this->db->get_where('librarian', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$this->session->set_userdata('librarian_login', '1');
$this->session->set_userdata('librarian_id', $row->librarian_id);
$this->session->set_userdata('login_user_id', $row->librarian_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'librarian');
return 'success';
}
return 'invalid';
}
/* * *DEFAULT NOR FOUND PAGE**** */
function four_zero_four() {
$this->load->view('four_zero_four');
}
// PASSWORD RESET BY EMAIL
function forgot_password()
{
$this->load->view('backend/forgot_password');
}
function ajax_forgot_password()
{
$resp = array();
$resp['status'] = 'false';
$email = $_POST["email"];
$reset_account_type = '';
//resetting user password here
$new_password = substr( md5( rand(100000000,20000000000) ) , 0,7);
// Checking credential for admin
$query = $this->db->get_where('admin' , array('email' => $email));
if ($query->num_rows() > 0)
{
$reset_account_type = 'admin';
$this->db->where('email' , $email);
$this->db->update('admin' , array('password' => sha1($new_password)));
$resp['status'] = 'true';
}
// Checking credential for student
$query = $this->db->get_where('student' , array('email' => $email));
if ($query->num_rows() > 0)
{
$reset_account_type = 'student';
$this->db->where('email' , $email);
$this->db->update('student' , array('password' => sha1($new_password)));
$resp['status'] = 'true';
}
// Checking credential for teacher
$query = $this->db->get_where('teacher' , array('email' => $email));
if ($query->num_rows() > 0)
{
$reset_account_type = 'teacher';
$this->db->where('email' , $email);
$this->db->update('teacher' , array('password' => sha1($new_password)));
$resp['status'] = 'true';
}
// Checking credential for parent
$query = $this->db->get_where('parent' , array('email' => $email));
if ($query->num_rows() > 0)
{
$reset_account_type = 'parent';
$this->db->where('email' , $email);
$this->db->update('parent' , array('password' => sha1($new_password)));
$resp['status'] = 'true';
}
// send new password to user email
$this->email_model->password_reset_email($new_password , $reset_account_type , $email);
$resp['submitted_data'] = $_POST;
echo json_encode($resp);
}
/* * *****LOGOUT FUNCTION ****** */
function logout() {
$this->session->sess_destroy();
$this->session->set_flashdata('logout_notification', 'logged_out');
redirect(base_url(), 'refresh');
}
}