/** * Constructor */ public function __construct(Session $session) { $this->session = $session; $this->unique = Client::getHash(); if ($this->session->active() !== true) { throw new Exception('Session needs to be started before using the Auth class.'); } $this->session->setOnce($this->key . '.info', array('fail_count' => 0, 'fail_total' => 0, 'last_attempt' => 0, 'last_active' => 0, 'login_time' => 0, 'login_hash' => '')); }
/** * Look for a list of ips in a file and deny requests from any of them */ public function denyFrom($file = '') { if (!empty($file) && is_file($file)) { $ip = Client::getIp(); $list = (include $file); $error = ''; if (is_array($list)) { foreach ($list as $entry) { if (!empty($entry) && !empty($ip) && $entry == $ip) { $error = 'This application does not accept requests from your network.'; break; } } } if (!empty($error)) { throw new Exception('Runtime error: ' . $error, 401); } } }
/** * Send a rendered template file HTML message */ public function sendTemplate($file = '', $data = array()) { if (!empty($file) && is_file($file)) { $tpl_base = dirname($file); $tpl_file = '/' . basename($file); $view = new View(); $view->setPlublicPath($tpl_base); $view->addRenderPath($tpl_base); $view->setTemplate($tpl_file); $view->set('url', Server::getUrl()); $view->set('ip', Client::getIp()); $view->set('browser', Client::getAgent()); $view->set('date', date('l jS \\of F Y h:i A T')); return $this->sendHtml($view->render()); } return false; }