/** * Returns self * * @return Model\Auth */ public static function singleton() { if (!static::$self) { // BaseAuth with settings from configuration file static::$self = new self(Config::get("auth")); } return static::$self; }
ini_set("html_errors", ini_get("display_errors")); // Set the default time zone date_default_timezone_set("Europe/Sofia"); // Composer include BASEPATH . "vendor/autoload.php"; // Setting path for auto config loader Config::$path = APPPATH . "config"; // PDO DB Handler Container::set("db", function () { $config = Config::get("db"); $db = new PDO($config["dsn"], $config["user"], $config["pass"]); // Set error handling to Exception $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Fetch return results as associative array $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); if (Config::get("db.dsn") == "sqlite::memory:") { $sql = file_get_contents(APPPATH . "Model/db.sql"); $db->exec($sql); } return $db; }); // return if we are coming form CLI (crontab jobs for example) if (php_sapi_name() == "cli") { return; } // Registering event listener for error 404, or when a route is not found Event::listen(array("404", "sugi.router.nomatch"), function () { Logger::debug("Page " . $_SERVER["REQUEST_URI"] . " Not Found"); header("HTTP/1.0 404 Not Found"); include APPPATH . "View/errors/404.html"; exit;
/** * Sending email for forgot password. * * @param string $email * @param string $username * @param string $token Forgot password token * @param string $lang Language for the mail */ public function sendForgotPasswordMail($email, $username, $token, $lang) { $url = Request::getScheme() . "://" . Request::getHost() . "/auth/reset?user={$username}&token={$token}"; if (!($body = File::get(APPPATH . "mails/forgot.{$lang}.txt"))) { $body = File::get(APPPATH . "mails/forgot.en.txt", null); } $body = str_replace(array("{email}", "{username}", "{token}", "{lang}", "{url}"), array($email, $username, $token, $lang, $url), $body); if (!($html = File::get(APPPATH . "mails/forgot.{$lang}.html"))) { $html = File::get(APPPATH . "mails/forgot.en.html", null); } $html = str_replace(array("{email}", "{username}", "{token}", "{lang}", "{url}"), array($email, $username, $token, $lang, $url), $html); Logger::debug($body); if (!DEBUG) { return Mail::send($email, "Forgot password request", $body, $html, Config::get("mailer.from")); } return $body; }