Move the cloud.code generation to the DataBase class

This commit is contained in:
Gregory Trolliet 2020-11-25 23:15:38 +01:00
parent 0980d0a82f
commit 3ff96924fb
3 changed files with 58 additions and 19 deletions

View file

@ -29,7 +29,7 @@ if (empty($_POST)) {
</div>
<?php
} else {
$token = bin2hex(random_bytes(DataBase::CLOUD_CODE_LENGTH));
/*$token = bin2hex(random_bytes(DataBase::CLOUD_CODE_LENGTH));*/
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
$size = $_POST['fsize'];
} else {
@ -45,16 +45,12 @@ if (empty($_POST)) {
} else {
$duration = DataBase::DEFAULT_DURATION;
}
$cpt = 0;
while (!$db->createCloud($token, $text, $size, $duration) && $cpt < 10) {
$token = bin2hex(random_bytes($length));
$cpt++;
// TODO what to do if no cloud created?
}
$viewUrl = 'result.php?id=' . $token;
$viewName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $viewUrl;
$voteUrl = 'index.php?id=' . $token;
$voteName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $voteUrl;
if ($cloud = $db->createCloud($text, $size, $duration)) {
$viewUrl = 'result.php?id=' . $cloud['code'];
$viewName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $viewUrl;
$voteUrl = 'index.php?id=' . $cloud['code'];
$voteName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $voteUrl;
?>
<h2><?php echo L::cloud_links_warning ?></h2>
@ -73,5 +69,10 @@ if (empty($_POST)) {
</div>
</div>
<?php
} else {
?>
<h2><?php echo L::create_errorCode ?></h2>
<?php
}
}
include('templates/footer.php');