riainvoice/application/modules/sessions/models/Mdl_sessions.php
2021-10-01 23:34:16 +05:30

90 lines
3.0 KiB
PHP

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* InvoicePlane
*
* @author InvoicePlane Developers & Contributors
* @copyright Copyright (c) 2012 - 2017 InvoicePlane.com
* @license https://invoiceplane.com/license.txt
* @link https://invoiceplane.com
*/
/**
* Class Mdl_Sessions
*/
class Mdl_Sessions extends CI_Model
{
/**
* @param $email
* @param $password
* @return bool
*/
public function auth($email, $password)
{
$this->db->join('ip_user_custom cus','cus.user_id = ip.user_id');
$this->db->where('ip.user_email', $email);
$this->db->where('cus.user_custom_fieldid',63);
$this->db->from('ip_users ip');
$query = $this->db->get();
if ($query->num_rows()) {
$user = $query->row();
$this->load->library('crypt');
/**
* Password hashing changed after 1.2.0
* Check to see if user has logged in since the password change
*/
if (!$user->user_psalt) {
/**
* The user has not logged in, so we're going to attempt to
* update their record with the updated hash
*/
if (md5($password) == $user->user_password) {
/**
* The md5 login validated - let's update this user
* to the new hash
*/
$salt = $this->crypt->salt();
$hash = $this->crypt->generate_password($password, $salt);
$db_array = array(
'user_psalt' => $salt,
'user_password' => $hash
);
$this->db->where('user_id', $user->user_id);
$this->db->update('ip_users', $db_array);
$this->db->where('user_email', $email);
$user = $this->db->get('ip_users')->row();
} else {
/**
* The password didn't verify against original md5
*/
return false;
}
}
if ($this->crypt->check_password($user->user_password, $password)) {
$session_data = array(
'user_type' => $user->user_type,
'user_id' => $user->user_id,
'user_name' => $user->user_name,
'user_email' => $user->user_email,
'user_company' => $user->user_company,
'user_language' => isset($user->user_language) ? $user->user_language : 'system',
'user_fieldid' => $user->user_custom_fieldid, // field for getting Department Id
'user_value' => $user->user_custom_fieldvalue, // field for getting Department Value
);
$this->session->set_userdata($session_data);
return true;
}
}
return false;
}
}