Esempio n. 1
0
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;
});
// Registering event listener for error 500
Event::listen("500", function () {
    Logger::debug("Page " . $_SERVER["REQUEST_URI"] . " Internal Server Error");
    header("HTTP/1.0 500 Internal Server Error");
    include APPPATH . "/View/errors/500.html";
    exit;
});
// Registering event listener for error 503
Event::listen("503", function () {
    Logger::debug("Page " . $_SERVER["REQUEST_URI"] . " Service Unavailable");
    header("HTTP/1.0 503 Service Unavailable");
    include APPPATH . "View/errors/503.html";
    exit;
});
// Registering event listener when a route is found
Event::listen("sugi.router.match", function ($event) {
    $method = $event->getParam("action") . "Action";
    try {
        // Load the controller using reflection
        $class = new \ReflectionClass("\\Controller\\" . ucfirst($event->getParam("controller")));
        // Check we can create an instance of the class
        // Check the class has needed method and it is callable
        if ($class->isInstantiable() and $class->hasMethod($method) and $class->getMethod($method)->isPublic()) {
            $controller = $class->newInstance();
            $controller->{$method}($event->getParam("param"));
Esempio n. 2
0
 /**
  * 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;
 }