Browse Source

remove user account type selection features #14

main
ghost 1 year ago
parent
commit
a4dae88575
  1. BIN
      database/yggtracker.mwb
  2. 11
      src/app/controller/index.php
  3. 11
      src/app/controller/page.php
  4. 177
      src/app/controller/welcome.php
  5. 39
      src/app/view/theme/default/welcome.phtml
  6. 28
      src/config/bootstrap.php

BIN
database/yggtracker.mwb

Binary file not shown.

11
src/app/controller/index.php

@ -80,17 +80,6 @@ class AppControllerIndex @@ -80,17 +80,6 @@ class AppControllerIndex
403
);
}
// Require account type selection
if (is_null($user->public))
{
header(
sprintf(
'Location: %s/welcome',
trim($this->_website->getUrl(), '/')
)
);
}
}
public function render()

11
src/app/controller/page.php

@ -107,17 +107,6 @@ class AppControllerPage @@ -107,17 +107,6 @@ class AppControllerPage
403
);
}
// Require account type selection
if (is_null($user->public))
{
header(
sprintf(
'Location: %s/welcome',
trim($this->_website->getUrl(), '/')
)
);
}
}
private function _initLocale(string $value)

177
src/app/controller/welcome.php

@ -1,177 +0,0 @@ @@ -1,177 +0,0 @@
<?php
class AppControllerWelcome
{
private $_database;
private $_validator;
private $_website;
private $_session;
public function __construct(
AppModelDatabase $database,
AppModelValidator $validator,
AppModelWebsite $website,
AppModelSession $session,
)
{
$this->_database = $database;
$this->_validator = $validator;
$this->_website = $website;
$this->_session = $session;
}
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,
$data,
$code
);
$appControllerResponse->render();
exit;
}
public function render()
{
$error = [];
if (!$this->_validator->host($this->_session->getAddress(), $error))
{
$this->_response(
sprintf(
_('Error - %s'),
$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'),
$error,
500
);
}
// 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'),
$this->_website->getName()
),
_('Welcome back!'),
sprintf(
_('You already have selected account type to %s'),
$user->public ? _('Distributed') : _('Local')
),
405
);
}
if (isset($_POST['public']))
{
if ($this->_database->updateUserPublic($user->userId, (bool) $_POST['public'], time()))
{
$this->_response(
sprintf(
_('Success - %s'),
$this->_website->getName()
),
_('Success!'),
sprintf(
_('Account type successfully changed to %s'),
$_POST['public'] ? _('Distributed') : _('Local')
),
);
}
}
require_once __DIR__ . '/module/head.php';
$appControllerModuleHead = new AppControllerModuleHead(
$this->_website->getUrl(),
sprintf(
_('Welcome to %s'),
$this->_website->getName()
),
[
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/common.css?%s',
CSS_VERSION
),
],
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/framework.css?%s',
CSS_VERSION
),
],
]
);
require_once __DIR__ . '/module/header.php';
$appControllerModuleHeader = new AppControllerModuleHeader();
require_once __DIR__ . '/module/footer.php';
$appControllerModuleFooter = new AppControllerModuleFooter();
include __DIR__ . '../../view/theme/default/welcome.phtml';
}
}

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

@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
<!DOCTYPE html>
<html>
<?php $appControllerModuleHead->render() ?>
<body>
<?php $appControllerModuleHeader->render() ?>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<div class="padding-16 margin-y-8 border-radius-3 background-color-night text-center">
<div class="margin-b-24 padding-b-16 border-bottom-default">
<h1 class=""><?php echo _('Welcome, stranger!') ?></h1>
</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 $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">
<input type="radio" id="public-1" name="public" value="1" checked="checked" />
<?php echo _('Allow address distribution') ?>
</label>
<label class="text-color-pink margin-y-8 margin-x-4" for="public-0">
<input type="radio" id="public-0" name="public" value="0" />
<?php echo _('Keep activity local') ?>
</label>
</div>
<div class="text-center">
<input type="submit" value="<?php echo _('confirm') ?>" />
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<?php $appControllerModuleFooter->render() ?>
</body>
</html>

28
src/config/bootstrap.php

@ -76,34 +76,6 @@ if (isset($request['_route_'])) @@ -76,34 +76,6 @@ if (isset($request['_route_']))
break;
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(
new AppModelDatabase(
Environment::config('database')
),
new AppModelValidator(
Environment::config('validator')
),
new AppModelWebsite(
Environment::config('website')
),
new AppModelSession(
$_SERVER['REMOTE_ADDR']
)
);
$appControllerWelcome->render();
break;
case 'submit':
require_once __DIR__ . '/../app/model/database.php';

Loading…
Cancel
Save