Admin page

This commit is contained in:
vitaliy 2025-01-24 12:38:54 +03:00
parent 7162d6bc18
commit 5d09dee273
18 changed files with 204 additions and 167 deletions

View File

@ -1,17 +0,0 @@
<?php
require_once __DIR__ . '/../model/AboutModel.php';
require_once __DIR__ . '/../view/View.php';
class AboutController {
public static function actionIndex(){
$result = AboutModel::getData();
echo(View::render(['box' => $result,
'body' => 'ДОМОЙ!',
'auth'=> false ], 'tpl_layout.php' ));
print("А теперь перерыв !!");
}
}

View File

@ -0,0 +1,15 @@
<?php
session_start();
require_once __DIR__ . '/../view/View.php';
class AdminController {
public function actionIndex(){
if (isset($_SESSION['IS_AUTH'])
AND $_SESSION['IS_AUTH'] == true ) {
echo(View::render( ['content' => ""], 'layout_admin.php' ));
} else {
header('Location: http://localhost:8080/login');
}
}
}

View File

@ -0,0 +1,38 @@
<?php
ini_set('session.gc_maxlifetime', 3600*3);
session_start();
// Valid constant names
class AuthController {
const PASSWD = 123;
const LOGIN = "none@none.ru";
const DOMAIN = 'http://localhost:8080/';
public $login = Null;
public $password = Null;
public function __construct()
{
$this->login = $_POST['login'];
$this -> password = $_POST['password'];
}
public function actionLogin(){
if (( $this->login == self::LOGIN ) AND ( $this -> password == self::PASSWD )) {
// редирект в админку
$_SESSION['IS_AUTH'] = true;
header("Location:". self::DOMAIN . "admin");
} else {
// редирект на форму логина с предупреждением
header('Location:'. self::DOMAIN . "login" );
}
}
public function actionLogout(){
session_unset();
session_destroy();
// echo('print Logout');
header( 'Location:'. self::DOMAIN );
}
}

View File

@ -1,6 +1,8 @@
<?php
require_once __DIR__ . '/../view/View.php';
require_once __DIR__ . '/../model/MusicModel.php';
class MainController {
//todo: Написать actionIndex отображение главной
@ -8,7 +10,8 @@ class MainController {
public function actionIndex(){
echo(View::render( [], 'index_tpl.php' ));
$result = MusicModel::getData();
echo(View::render( ['box' => $result ], 'index_tpl.php' ));
}
public function actionNotFound(){

View File

@ -0,0 +1,35 @@
<?php
session_start();
require_once __DIR__ . '/../view/View.php';
class UploadController {
public function actionIndex(){
// todo: Вынести проверку авторизации в отдельный
// модуль
if (isset($_SESSION['IS_AUTH'])
AND $_SESSION['IS_AUTH'] == true ) {
$portial = View::render( [], 'upload_tpl.php' );
// echo($portial);
// exit(0);
echo(View::render( ['content'=> $portial ], 'layout_admin.php' ));
} else {
// var_dump()
header('Location: http://localhost:8080/login');
}
}
public function actionAddfile(){
$uploaddir = '/home/vitaliy/project/itmo/php_engine/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
var_dump($uploadfile);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo "Файл не содержит ошибок и успешно загрузился на сервер.\n";
} else {
echo "Возможная атака на сервер через загрузку файла!\n";
}
}
}

View File

@ -1,19 +0,0 @@
<?php
class AboutModel {
static function getData (){
$box = [];
if ($handle = opendir('/home/vitaliy/project/itmo/php_winter_2023/engine/upload')) {
while (false !== ($entry = readdir($handle))) {
$ext = pathinfo($entry, PATHINFO_EXTENSION);
if ($ext == 'mp3') {
array_push($box, './upload/'.$entry);
}
}
closedir($handle);
}
return $box;
}
}

19
app/model/MusicModel.php Normal file
View File

@ -0,0 +1,19 @@
<?php
class MusicModel
{
static function getData()
{
$box = [];
if ($handle = opendir('./uploads')) {
while (false !== ($entry = readdir($handle))) {
$ext = pathinfo($entry, PATHINFO_EXTENSION);
if ($ext == 'mp3') {
array_push($box, "./uploads/$entry");
}
}
closedir($handle);
}
return $box;
}
}

View File

@ -1,13 +0,0 @@
<!-- Тип кодирования данных, enctype, требуется указывать только так, как показывает пример --><form enctype="multipart/form-data" action="file_upload.php" method="POST">
<!-- Поле MAX_FILE_SIZE требуется указывать перед полем загрузки файла -->
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
<!-- Название элемента input определяет название элемента в суперглобальном массиве $_FILES -->
Отправить файл: <input name="userfile" type="file" />
<input type="submit" value="Отправить файл" />
</form>
<!-- <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" for="file_input">Upload file</label> -->
<!-- <!-- <!-- <!-- <!-- <input class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400" aria-describedby="file_input_help" id="file_input" type="file"> --> --> --> --> -->
<!-- <!-- <!-- <p class="mt-1 text-sm text-gray-500 dark:text-gray-300" id="file_input_help" value="Отправить файл">SVG, PNG, JPG or GIF (MAX. 800x400px).</p> --> --> -->

View File

@ -31,6 +31,58 @@
</div>
</nav>
<div class="flex border-b">
<button id="tab1" class="px-4 py-2 border-b-2 border-blue-500 text-blue-500 font-medium active" onclick="showTab('tab1')">Вкладка 1</button>
<button id="tab2" class="px-4 py-2 border-b-2 border-transparent text-gray-500 font-medium hover:text-gray-700 hover:border-gray-300" onclick="showTab('tab2')">Вкладка 2</button>
<button id="tab3" class="px-4 py-2 border-b-2 border-transparent text-gray-500 font-medium hover:text-gray-700 hover:border-gray-300" onclick="showTab('tab3')">Вкладка 3</button>
</div>
<div id="content1" class="p-4">
<?php foreach ($box as $item): ?>
<audio controls>
<source src="<?php echo $item ?>" type="audio/mpeg" />
</audio>
<?php endforeach; ?>
</div>
<div id="content2" class="p-4 hidden">
Содержимое вкладки 2
</div>
<div id="content3" class="p-4 hidden">
Содержимое вкладки 3
</div>
<script>
function showTab(tabId) {
const tabs = document.querySelectorAll('.flex button');
const contents = document.querySelectorAll('.p-4');
tabs.forEach(tab => {
tab.classList.remove('active');
tab.classList.remove('border-blue-500');
tab.classList.remove('text-blue-500');
tab.classList.add('border-transparent');
tab.classList.add('text-gray-500');
});
contents.forEach(content => {
content.classList.add('hidden');
});
document.getElementById(tabId).classList.add('active');
document.getElementById(tabId).classList.add('border-blue-500');
document.getElementById(tabId).classList.add('text-blue-500');
document.getElementById(tabId).classList.remove('border-transparent');
document.getElementById(tabId).classList.remove('text-gray-500');
document.getElementById(`content${tabId.slice(-1)}`).classList.remove('hidden');
}
</script>
</body>
</html>

View File

@ -56,31 +56,29 @@
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<a href="./upload" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 18 20">
<path d="M17 5.923A1 1 0 0 0 16 5h-3V4a4 4 0 1 0-8 0v1H2a1 1 0 0 0-1 .923L.086 17.846A2 2 0 0 0 2.08 20h13.84a2 2 0 0 0 1.994-2.153L17 5.923ZM7 9a1 1 0 0 1-2 0V7h2v2Zm0-5a2 2 0 1 1 4 0v1H7V4Zm6 5a1 1 0 1 1-2 0V7h2v2Z"/>
</svg>
<span class="flex-1 ms-3 whitespace-nowrap">Products</span>
<span class="flex-1 ms-3 whitespace-nowrap">Загрузка</span>
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<a href="./logout" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 16">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 8h11m0 0L8 4m4 4-4 4m4-11h3a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-3"/>
</svg>
<span class="flex-1 ms-3 whitespace-nowrap">Sign In</span>
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M5 5V.13a2.96 2.96 0 0 0-1.293.749L.879 3.707A2.96 2.96 0 0 0 .13 5H5Z"/>
<path d="M6.737 11.061a2.961 2.961 0 0 1 .81-1.515l6.117-6.116A4.839 4.839 0 0 1 16 2.141V2a1.97 1.97 0 0 0-1.933-2H7v5a2 2 0 0 1-2 2H0v11a1.969 1.969 0 0 0 1.933 2h12.134A1.97 1.97 0 0 0 16 18v-3.093l-1.546 1.546c-.413.413-.94.695-1.513.81l-3.4.679a2.947 2.947 0 0 1-1.85-.227 2.96 2.96 0 0 1-1.635-3.257l.681-3.397Z"/>
<path d="M8.961 16a.93.93 0 0 0 .189-.019l3.4-.679a.961.961 0 0 0 .49-.263l6.118-6.117a2.884 2.884 0 0 0-4.079-4.078l-6.117 6.117a.96.96 0 0 0-.263.491l-.679 3.4A.961.961 0 0 0 8.961 16Zm7.477-9.8a.958.958 0 0 1 .68-.281.961.961 0 0 1 .682 1.644l-.315.315-1.36-1.36.313-.318Zm-5.911 5.911 4.236-4.236 1.359 1.359-4.236 4.237-1.7.339.341-1.699Z"/>
</svg>
<span class="flex-1 ms-3 whitespace-nowrap">Sign Up</span>
<span class="flex-1 ms-3 whitespace-nowrap">Log Out</span>
</a>
</li>
</ul>
</div>
</aside>
@ -97,90 +95,14 @@
</div>
<div class="flex items-center justify-center h-24 rounded bg-gray-50 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="flex items-center justify-center h-24 rounded bg-gray-50 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
</div>
<div class="flex items-center justify-center h-48 mb-4 rounded bg-gray-50 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div class="flex items-center justify-center rounded bg-gray-50 h-28 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="flex items-center justify-center rounded bg-gray-50 h-28 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="flex items-center justify-center rounded bg-gray-50 h-28 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="flex items-center justify-center rounded bg-gray-50 h-28 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
</div>
<div class="flex items-center justify-center h-48 mb-4 rounded bg-gray-50 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="grid grid-cols-2 gap-4">
<div class="flex items-center justify-center rounded bg-gray-50 h-28 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="flex items-center justify-center rounded bg-gray-50 h-28 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="flex items-center justify-center rounded bg-gray-50 h-28 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</p>
</div>
<div class="flex items-center justify-center rounded bg-gray-50 h-28 dark:bg-gray-800">
<p class="text-2xl text-gray-400 dark:text-gray-500">
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
<?php if ($content): ?>
<?php echo $content ?>
<?php else: ?>
<?php echo "Нужен контент!" ?>
<?php endif; ?>
</p>
</div>
</div>

View File

@ -40,7 +40,8 @@
class="block w-full px-4 py-2 mt-2 text-purple-700 bg-white
border rounded-md focus:border-purple-400 focus:ring-purple-300
focus:outline-none focus:ring focus:ring-opacity-40"
name="login">
name="login"
value='none@none.ru'>
</div>
<div class="mt-4">
<div>
@ -49,7 +50,8 @@
class="block w-full px-4 py-2 mt-2 text-purple-700 bg-white
border rounded-md focus:border-purple-400 focus:ring-purple-300
focus:outline-none focus:ring focus:ring-opacity-40"
name="password">
name="password"
value=123>
</div>
<a href="#" class="text-xs text-gray-600 hover:underline">Forget Password?</a>
<div class="mt-6">

View File

@ -0,0 +1,11 @@
<!-- Тип кодирования данных, enctype, требуется указывать только так, как показывает пример -->
<form enctype="multipart/form-data" action="file_upload" method="POST">
<!-- Поле MAX_FILE_SIZE требуется указывать перед полем загрузки файла -->
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<!-- Название элемента input определяет название элемента в суперглобальном массиве $_FILES -->
<input name="userfile" type="file" />
<input class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" type="submit" value="Отправить файл" />
</form>

View File

@ -1,15 +0,0 @@
<?php

View File

@ -2,9 +2,13 @@
return array (
'news' => 'news/index', // actionIndex в NewsController
'products' => 'product/list', // actionList в ProductController
'about' => 'about/index',
'login' => 'login/index',
"auth" => 'auth/index'
'auth' => 'auth/login',
'logout' => 'auth/logout',
'admin' => 'admin/index',
'upload' => 'upload/index',
'file_upload' => 'upload/addfile'
);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 327 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 KiB