Browse Source

update dependencies

main
ghost 1 year ago
parent
commit
623375484e
  1. 84
      src/app/controller/user.php
  2. 99
      src/app/controller/welcome.php
  3. 2
      src/app/view/theme/default/welcome.phtml
  4. 20
      src/config/bootstrap.php

84
src/app/controller/user.php

@ -4,90 +4,34 @@ class AppControllerUser
{ {
private $_database; private $_database;
private $_validator; private $_validator;
private $_website;
private $_user; private $_user;
public function __construct(string $address) public function __construct(
{ AppModelDatabase $database,
require_once __DIR__ . '/../model/database.php'; AppModelValidator $validator,
AppModelWebsite $website
$this->_database = new AppModelDatabase(
Environment::config('database')
);
require_once __DIR__ . '/../model/validator.php';
$this->_validator = new AppModelValidator(
Environment::config('validator')
);
// Validate address
$error = [];
if (!$this->_validator->host($address, $error))
{
$this->_response(
sprintf(
_('Error - %s'),
Environment::config('website')->name
),
_('406'),
print_r($error, true),
406
);
}
// Init user session
try
{
$this->_database->beginTransaction();
$this->_user = $this->_database->getUser(
$this->_database->initUserId(
$address,
Environment::config('website')->default->user->approved,
time()
) )
);
$this->_database->commit();
}
catch (Exception $error)
{ {
$this->_database->rollback(); $this->_database = $database;
$this->_validator = $validator;
$this->_response( $this->_website = $website;
sprintf(
_('Error - %s'),
Environment::config('website')->name
),
_('500'),
print_r($error, true),
500
);
} }
// Require account type selection private function _response(string $title, string $h1, mixed $data, int $code = 200)
if (is_null($this->getPublic()))
{ {
header( require_once __DIR__ . '/response.php';
sprintf(
'Location: %s/welcome',
trim($this->_config->url, '/')
)
);
}
}
private function _response(string $title, string $h1, string $text, int $code = 200) if (is_array($data))
{ {
require_once __DIR__ . '/response.php'; $data = implode('<br />', $data);
}
$appControllerResponse = new AppControllerResponse( $appControllerResponse = new AppControllerResponse(
$title, $title,
$h1, $h1,
$text, $data,
$code $code
); );

99
src/app/controller/welcome.php

@ -2,26 +2,37 @@
class AppControllerWelcome class AppControllerWelcome
{ {
private $_user; private $_database;
private $_validator;
public function __construct() private $_website;
private $_session;
public function __construct(
AppModelDatabase $database,
AppModelValidator $validator,
AppModelWebsite $website,
AppModelSession $session,
)
{ {
require_once __DIR__ . '/user.php'; $this->_database = $database;
$this->_validator = $validator;
$this->_user = new AppControllerUser( $this->_website = $website;
$_SERVER['REMOTE_ADDR'] $this->_session = $session;
);
} }
private function _response(string $title, string $h1, mixed $data, int $code = 200)
private function _response(string $title, string $h1, string $text, int $code = 200)
{ {
require_once __DIR__ . '/response.php'; require_once __DIR__ . '/response.php';
if (is_array($data))
{
$data = implode('<br />', $data);
}
$appControllerResponse = new AppControllerResponse( $appControllerResponse = new AppControllerResponse(
$title, $title,
$h1, $h1,
$text, $data,
$code $code
); );
@ -32,30 +43,76 @@ class AppControllerWelcome
public function render() public function render()
{ {
if (!$address = $this->_user->getAddress()) $error = [];
if (!$this->_validator->host($this->_session->getAddress(), $error))
{ {
$this->_response( $this->_response(
sprintf( sprintf(
_('Error - %s'), _('Error - %s'),
Environment::config('website')->name $this->_website->getName()
),
_('406'),
$error,
406
);
}
try
{
$this->_database->beginTransaction();
$user = $this->_database->getUser(
$this->_database->initUserId(
$this->_session->getAddress(),
$this->_website->getDefaultUserStatus(),
$this->_website->getDefaultUserApproved(),
time()
)
);
$this->_database->commit();
}
catch (Exception $error)
{
$this->_database->rollback();
$this->_response(
sprintf(
_('Error - %s'),
$this->_website->getName()
), ),
_('500'), _('500'),
_('Could not init user'), $error,
500 500
); );
} }
if (!is_null($this->_user->getPublic())) // Access denied
if (!$user->status)
{
$this->_response(
sprintf(
_('Error - %s'),
$this->_website->getName()
),
_('403'),
_('Access denied'),
403
);
}
if (!is_null($user->public))
{ {
$this->_response( $this->_response(
sprintf( sprintf(
_('Welcome back - %s'), _('Welcome back - %s'),
Environment::config('website')->name $this->_website->getName()
), ),
_('Welcome back!'), _('Welcome back!'),
sprintf( sprintf(
_('You already have selected account type to %s'), _('You already have selected account type to %s'),
$this->_user->getPublic() ? _('Distributed') : _('Local') $user->public ? _('Distributed') : _('Local')
), ),
405 405
); );
@ -63,12 +120,12 @@ class AppControllerWelcome
if (isset($_POST['public'])) if (isset($_POST['public']))
{ {
if ($this->_user->updateUserPublic((bool) $_POST['public'], time())) if ($this->_database->updateUserPublic($user->userId, (bool) $_POST['public'], time()))
{ {
$this->_response( $this->_response(
sprintf( sprintf(
_('Success - %s'), _('Success - %s'),
Environment::config('website')->name $this->_website->getName()
), ),
_('Success!'), _('Success!'),
sprintf( sprintf(
@ -82,10 +139,10 @@ class AppControllerWelcome
require_once __DIR__ . '/module/head.php'; require_once __DIR__ . '/module/head.php';
$appControllerModuleHead = new AppControllerModuleHead( $appControllerModuleHead = new AppControllerModuleHead(
Environment::config('website')->url, $this->_website->getUrl(),
sprintf( sprintf(
_('Welcome to %s'), _('Welcome to %s'),
Environment::config('website')->name $this->_website->getName()
), ),
[ [
[ [

2
src/app/view/theme/default/welcome.phtml

@ -13,7 +13,7 @@
</div> </div>
<p class="margin-b-8"><?php echo _('YGGtracker uses Yggdrasil address to identify users without registration') ?></p> <p class="margin-b-8"><?php echo _('YGGtracker uses Yggdrasil address to identify users without registration') ?></p>
<p class="margin-b-16"><?php echo _('address below could be shared with independent nodes to allow you manage own content everywhere') ?></p> <p class="margin-b-16"><?php echo _('address below could be shared with independent nodes to allow you manage own content everywhere') ?></p>
<h2 class="margin-b-16"><?php echo $address ?></h2> <h2 class="margin-b-16"><?php echo $user->address ?></h2>
<form name="public" action="welcome" method="post"> <form name="public" action="welcome" method="post">
<div class="margin-b-16"> <div class="margin-b-16">
<label class="text-color-green margin-y-8 margin-x-4" for="public-1"> <label class="text-color-green margin-y-8 margin-x-4" for="public-1">

20
src/config/bootstrap.php

@ -78,9 +78,27 @@ if (isset($request['_route_']))
case 'welcome': case 'welcome':
require_once __DIR__ . '/../app/model/database.php';
require_once __DIR__ . '/../app/model/validator.php';
require_once __DIR__ . '/../app/model/website.php';
require_once __DIR__ . '/../app/model/session.php';
require_once __DIR__ . '/../app/controller/welcome.php'; require_once __DIR__ . '/../app/controller/welcome.php';
$appControllerWelcome = new AppControllerWelcome(); $appControllerWelcome = new AppControllerWelcome(
new AppModelDatabase(
Environment::config('database')
),
new AppModelValidator(
Environment::config('validator')
),
new AppModelWebsite(
Environment::config('website')
),
new AppModelSession(
$_SERVER['REMOTE_ADDR']
)
);
$appControllerWelcome->render(); $appControllerWelcome->render();

Loading…
Cancel
Save