Example of usage use Bluz\Proxy\Logger; Logger::error('Configuration not found');
See also: Instance::alert()
See also: Instance::critical()
See also: Instance::debug()
See also: Instance::emergency()
See also: Instance::error()
See also: Instance::info()
See also: Instance::notice()
See also: Instance::warning()
See also: Instance::log()
See also: Instance::get()
Author: Anton Shevchuk
Inheritance: use trait ProxyTrait
Example #1
0
 /**
  * @return void
  */
 public function end()
 {
     if ($messages = Logger::get('error')) {
         foreach ($messages as $message) {
             errorLog(new \ErrorException($message, 0, E_USER_ERROR));
         }
     }
     // return code 1 for invalid behaviour of application
     //        if ($exception = $this->getException()) {
     //            echo $exception->getMessage();
     //            exit(1);
     //        }
     exit;
 }
Example #2
0
 /**
  * @param array $data
  * @throws Exception
  * @throws ValidatorException
  * @return integer
  */
 public function createOne($data)
 {
     // password
     $password = $data['password'] ?? null;
     $password2 = $data['password2'] ?? null;
     if (empty($password)) {
         throw ValidatorException::exception('password', __('Password can\'t be empty'));
     }
     if ($password !== $password2) {
         throw ValidatorException::exception('password2', __('Password is not equal'));
     }
     if ($data['id'] == '') {
         unset($data['id']);
     }
     /** @var $row Row */
     $row = $this->getTable()->create();
     $row->setFromArray($data);
     $row->status = Table::STATUS_PENDING;
     $row->save();
     $userId = $row->id;
     // create auth
     Auth\Table::getInstance()->generateEquals($row, $password);
     // create activation token
     // valid for 5 days
     $actionRow = UsersActions\Table::getInstance()->generate($userId, UsersActions\Table::ACTION_ACTIVATION, 5);
     // send activation email
     // generate activation URL
     $activationUrl = Router::getFullUrl('users', 'activation', ['code' => $actionRow->code, 'id' => $userId]);
     $subject = "Activation";
     $body = Application::getInstance()->dispatch('users', 'mail/template', ['template' => 'registration', 'vars' => ['user' => $row, 'activationUrl' => $activationUrl, 'password' => $password]])->render();
     try {
         $mail = Mailer::create();
         $mail->Subject = $subject;
         $mail->msgHTML(nl2br($body));
         $mail->addAddress($data['email']);
         Mailer::send($mail);
     } catch (\Exception $e) {
         Logger::log('error', $e->getMessage(), ['module' => 'users', 'controller' => 'change-email', 'userId' => $userId]);
         throw new Exception('Unable to send email. Please contact administrator.');
     }
     // show notification and redirect
     Messages::addSuccess("Your account has been created and an activation link has" . "been sent to the e-mail address you entered.<br/>" . "Note that you must activate the account by clicking on the activation link" . "when you get the e-mail before you can login.");
     // wtf?
     // redirectTo('index', 'index');
     return $userId;
 }
Example #3
0
             throw new Exception('User with email "' . htmlentities($email) . '" already exists');
         }
         // generate change mail token and get full url
         $actionRow = UsersActions\Table::getInstance()->generate($userId, Table::ACTION_CHANGE_EMAIL, 5, ['email' => $email]);
         $changeUrl = Router::getFullUrl('users', 'change-email', ['token' => $actionRow->code]);
         $subject = __("Change email");
         $body = $this->dispatch('users', 'mail/template', ['template' => 'change-email', 'vars' => ['user' => $user, 'email' => $email, 'changeUrl' => $changeUrl, 'profileUrl' => Router::getFullUrl('users', 'profile')]])->render();
         try {
             $mail = Mailer::create();
             $mail->Subject = $subject;
             $mail->msgHTML(nl2br($body));
             $mail->addAddress($email);
             Mailer::send($mail);
             Messages::addNotice('Check your email and follow instructions in letter.');
         } catch (\Exception $e) {
             Logger::log('error', $e->getMessage(), ['module' => 'users', 'controller' => 'change-email', 'userId' => $userId]);
             throw new Exception('Unable to send email. Please contact administrator.');
         }
         // try back to index
         Response::redirectTo('users', 'profile');
     } catch (Exception $e) {
         Messages::addError($e->getMessage());
         $this->assign('email', $email);
     } catch (AuthException $e) {
         Messages::addError($e->getMessage());
         $this->assign('email', $email);
     }
 } elseif ($token) {
     // process activation
     $actionRow = UsersActions\Table::findRowWhere(['code' => $token, 'userId' => $userId]);
     if (!$actionRow) {
Example #4
0
use Bluz\Proxy\Layout;
use Bluz\Proxy\Logger;
use Bluz\Proxy\Messages;
use Bluz\Proxy\Response;
use Bluz\Proxy\Request;
/**
 * @route  /error/{$code}
 * @param  int $code
 * @param  string $message
 * @return array|null
 */
return function ($code, $message = '') {
    /**
     * @var Controller $this
     */
    Logger::error($message);
    switch ($code) {
        case 400:
            $title = __("Bad Request");
            $description = __("The server didn't understand the syntax of the request");
            break;
        case 401:
            $title = __("Unauthorized");
            $description = __("You are not authorized to view this page, please sign in");
            break;
        case 403:
            $title = __("Forbidden");
            $description = __("You don't have permissions to access this page");
            break;
        case 404:
            $title = __("Not Found");
Example #5
0
 /**
  * Log queries by Application
  *
  * @param string $sql
  * @param array $context
  * @return void
  */
 protected function log($sql, array $context = [])
 {
     $this->timer = microtime(true);
     $sql = str_replace('%', '%%', $sql);
     $sql = preg_replace('/\\?/', '"%s"', $sql, sizeof($context));
     // replace mask by data
     $log = vsprintf("db: " . $sql, $context);
     Logger::info($log);
 }
Example #6
0
 /**
  * Finally method
  * @return void
  */
 public function finish()
 {
     Logger::info('app:finish');
 }
Example #7
0
                throw new Exception('User is inactive');
            }
            // create activation token
            // valid for 5 days
            $actionRow = UsersActions\Table::getInstance()->generate($user->id, UsersActions\Table::ACTION_RECOVERY, 5);
            // send activation email
            // generate restore URL
            $resetUrl = Router::getFullUrl('users', 'recovery-reset', ['code' => $actionRow->code, 'id' => $user->id]);
            $subject = "Password Recovery";
            $body = $this->dispatch('users', 'mail-template', ['template' => 'recovery', 'vars' => ['user' => $user, 'resetUrl' => $resetUrl]])->render();
            try {
                $mail = Mailer::create();
                // subject
                $mail->Subject = $subject;
                $mail->MsgHTML(nl2br($body));
                $mail->AddAddress($user->email);
                Mailer::send($mail);
            } catch (\Exception $e) {
                // log it
                Logger::log('error', $e->getMessage(), ['module' => 'users', 'controller' => 'recovery', 'email' => $email]);
                throw new Exception('Unable to send email. Please contact administrator.');
            }
            // show notification and redirect
            Messages::addSuccess("Reset password instructions has been sent to your email address");
            $this->redirectTo('index', 'index');
        } catch (Exception $e) {
            Messages::addError($e->getMessage());
        }
        $view->email = $email;
    }
};
Example #8
0
 /**
  * @return void
  */
 public function finish()
 {
     if ($messages = Logger::get('error')) {
         foreach ($messages as $message) {
             errorLog($message);
         }
     }
     // return code 1 for invalid behaviour of application
     if ($exception = Response::getException()) {
         echo $exception->getMessage();
         exit(1);
     }
     exit;
 }
Example #9
0
 /**
  * Log queries by Application
  *
  * @param string $sql
  * @param array $context
  * @return void
  */
 protected function log($sql, array $context = [])
 {
     $sql = str_replace('%', '%%', $sql);
     $sql = preg_replace('/\\?/', '"%s"', $sql, sizeof($context));
     // replace mask by data
     $sql = vsprintf($sql, $context);
     Logger::info("db: " . $sql);
 }
 /**
  * Finish it
  * @return void
  */
 public function finish()
 {
     if ($messages = Logger::get('error')) {
         foreach ($messages as $message) {
             errorLog($message);
         }
     }
 }
Example #11
0
 /**
  * Post dispatch mount point
  *
  * @param  string $module
  * @param  string $controller
  * @param  array  $params
  * @return void
  */
 protected function postDispatch($module, $controller, $params = [])
 {
     Logger::info("<<<:dispatch:post: " . $module . '/' . $controller);
 }
Example #12
0
 /**
  * Finish it
  * @return void
  */
 public function end()
 {
     if ($messages = Logger::get('error')) {
         foreach ($messages as $message) {
             errorLog(new \ErrorException($message, 0, E_USER_ERROR));
         }
     }
 }