File: /home/cafsindia/hrms_cafsinfotech_in/application/models/Otp_model.php
<?php
class Otp_model extends CI_Model {
private $table = 'otp_attempts';
public function get($user_name) {
return $this->db->get_where($this->table, ['user_name' => $user_name])->row_array();
}
public function increment_attempt($user_name) {
$now = date('Y-m-d H:i:s');
$row = $this->get($user_name);
if ($row) {
$data = [
'attempts' => $row['attempts'] + 1,
'last_attempt' => $now
];
$this->db->where('user_name', $user_name)->update($this->table, $data);
} else {
$data = [
'user_name' => $user_name,
'attempts' => 1,
'last_attempt' => $now
];
$this->db->insert($this->table, $data);
}
}
public function set_lock($user_name, $minutes = 15) {
$lock_time = date('Y-m-d H:i:s', time() + $minutes * 60);
$this->db->where('user_name', $user_name)->update($this->table, [
'lock_time' => $lock_time
]);
}
public function reset($user_name) {
$this->db->where('user_name', $user_name)->update($this->table, [
'attempts' => 0, 'lock_time' => null
]);
}
public function get_status($user_name) {
$row = $this->get($user_name);
if (!$row) return ['attempts' => 0, 'lock_time' => null];
return ['attempts' => $row['attempts'], 'lock_time' => $row['lock_time']];
}
}