mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-01-23 13:14:17 +00:00
update dependencies
This commit is contained in:
parent
246944e74e
commit
623375484e
@ -4,90 +4,34 @@ class AppControllerUser
|
||||
{
|
||||
private $_database;
|
||||
private $_validator;
|
||||
private $_website;
|
||||
|
||||
private $_user;
|
||||
|
||||
public function __construct(string $address)
|
||||
public function __construct(
|
||||
AppModelDatabase $database,
|
||||
AppModelValidator $validator,
|
||||
AppModelWebsite $website
|
||||
)
|
||||
{
|
||||
require_once __DIR__ . '/../model/database.php';
|
||||
|
||||
$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->_response(
|
||||
sprintf(
|
||||
_('Error - %s'),
|
||||
Environment::config('website')->name
|
||||
),
|
||||
_('500'),
|
||||
print_r($error, true),
|
||||
500
|
||||
);
|
||||
}
|
||||
|
||||
// Require account type selection
|
||||
if (is_null($this->getPublic()))
|
||||
{
|
||||
header(
|
||||
sprintf(
|
||||
'Location: %s/welcome',
|
||||
trim($this->_config->url, '/')
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->_database = $database;
|
||||
$this->_validator = $validator;
|
||||
$this->_website = $website;
|
||||
}
|
||||
|
||||
private function _response(string $title, string $h1, string $text, int $code = 200)
|
||||
private function _response(string $title, string $h1, mixed $data, int $code = 200)
|
||||
{
|
||||
require_once __DIR__ . '/response.php';
|
||||
|
||||
if (is_array($data))
|
||||
{
|
||||
$data = implode('<br />', $data);
|
||||
}
|
||||
|
||||
$appControllerResponse = new AppControllerResponse(
|
||||
$title,
|
||||
$h1,
|
||||
$text,
|
||||
$data,
|
||||
$code
|
||||
);
|
||||
|
||||
|
@ -2,26 +2,37 @@
|
||||
|
||||
class AppControllerWelcome
|
||||
{
|
||||
private $_user;
|
||||
private $_database;
|
||||
private $_validator;
|
||||
private $_website;
|
||||
private $_session;
|
||||
|
||||
public function __construct()
|
||||
public function __construct(
|
||||
AppModelDatabase $database,
|
||||
AppModelValidator $validator,
|
||||
AppModelWebsite $website,
|
||||
AppModelSession $session,
|
||||
)
|
||||
{
|
||||
require_once __DIR__ . '/user.php';
|
||||
|
||||
$this->_user = new AppControllerUser(
|
||||
$_SERVER['REMOTE_ADDR']
|
||||
);
|
||||
$this->_database = $database;
|
||||
$this->_validator = $validator;
|
||||
$this->_website = $website;
|
||||
$this->_session = $session;
|
||||
}
|
||||
|
||||
|
||||
private function _response(string $title, string $h1, string $text, int $code = 200)
|
||||
private function _response(string $title, string $h1, mixed $data, int $code = 200)
|
||||
{
|
||||
require_once __DIR__ . '/response.php';
|
||||
|
||||
if (is_array($data))
|
||||
{
|
||||
$data = implode('<br />', $data);
|
||||
}
|
||||
|
||||
$appControllerResponse = new AppControllerResponse(
|
||||
$title,
|
||||
$h1,
|
||||
$text,
|
||||
$data,
|
||||
$code
|
||||
);
|
||||
|
||||
@ -32,30 +43,76 @@ class AppControllerWelcome
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (!$address = $this->_user->getAddress())
|
||||
$error = [];
|
||||
if (!$this->_validator->host($this->_session->getAddress(), $error))
|
||||
{
|
||||
$this->_response(
|
||||
sprintf(
|
||||
_('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'),
|
||||
_('Could not init user'),
|
||||
$error,
|
||||
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(
|
||||
sprintf(
|
||||
_('Welcome back - %s'),
|
||||
Environment::config('website')->name
|
||||
$this->_website->getName()
|
||||
),
|
||||
_('Welcome back!'),
|
||||
sprintf(
|
||||
_('You already have selected account type to %s'),
|
||||
$this->_user->getPublic() ? _('Distributed') : _('Local')
|
||||
$user->public ? _('Distributed') : _('Local')
|
||||
),
|
||||
405
|
||||
);
|
||||
@ -63,12 +120,12 @@ class AppControllerWelcome
|
||||
|
||||
if (isset($_POST['public']))
|
||||
{
|
||||
if ($this->_user->updateUserPublic((bool) $_POST['public'], time()))
|
||||
if ($this->_database->updateUserPublic($user->userId, (bool) $_POST['public'], time()))
|
||||
{
|
||||
$this->_response(
|
||||
sprintf(
|
||||
_('Success - %s'),
|
||||
Environment::config('website')->name
|
||||
$this->_website->getName()
|
||||
),
|
||||
_('Success!'),
|
||||
sprintf(
|
||||
@ -82,10 +139,10 @@ class AppControllerWelcome
|
||||
require_once __DIR__ . '/module/head.php';
|
||||
|
||||
$appControllerModuleHead = new AppControllerModuleHead(
|
||||
Environment::config('website')->url,
|
||||
$this->_website->getUrl(),
|
||||
sprintf(
|
||||
_('Welcome to %s'),
|
||||
Environment::config('website')->name
|
||||
$this->_website->getName()
|
||||
),
|
||||
[
|
||||
[
|
||||
|
@ -13,7 +13,7 @@
|
||||
</div>
|
||||
<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>
|
||||
<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">
|
||||
<div class="margin-b-16">
|
||||
<label class="text-color-green margin-y-8 margin-x-4" for="public-1">
|
||||
|
@ -78,9 +78,27 @@ if (isset($request['_route_']))
|
||||
|
||||
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';
|
||||
|
||||
$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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user