Jeff Davidson
Jeff Davidson

Reputation: 1929

Can't locate file

After working with some files and trying to get this figured out I do still have an issue somewhere. Its saying its unable to locate the model specified which is my login attempts. I am modeling my own thing against the Tank Library. There’s some ideas I’m using my coding it to my own needs.

libraries/Kow_auth.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* KOW Auth Library
* Authentication Library for Code Igniter
* @author Jeffrey Davidson
* @version 1.0.0
* @copyright 2012
*/

class Kow_auth
{
protected $CI;

function __construct()
{
    //assign the CI superglobal to $CI
    $this->CI =& get_instance();             
}

function is_max_login_attempts_exceeded($user_id)
{
    $this->CI->load->model('kow_auth/login_attempts');
    return $this->CI->login_attempts->get_attempts_num($user_id) >= 5;
}    
} 

?>  

models/Kow_auth/login_attempts

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Login_attempts
 *
 *  This model serves to watch on all attempts to login on the site
 * (to protect the site from brute-force attack to user database)
 *
 * @package Kow_auth
 * @author Jeffrey Davidson
 */
class Login_attempts extends CI_Model
{
function __construct()
{
  parent::__construct();
}

function get_attempts_num($user_id)
{
  $this->db->select('failed_attempts');
  $this->db->where('user_id', $user_id);
  $query = $this->db->get('users_logins');

  if ($query->num_rows() > 0)
    {
        $row = $query->row();
        return $row->failed_attempts;
    } 
    else
    {
        return false;      
    }
}

}   

Upvotes: 1

Views: 147

Answers (1)

Damien Pirsy
Damien Pirsy

Reputation: 25435

The code looks right. Only things I feel to say is pay attention to names. Based on your code your model should reside in the file:

models/kow_auth/login_attempts.php

with lower-case folder name.

Upvotes: 1

Related Questions