First commit
This commit is contained in:
commit
5dc2ac7922
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
8
.idea/PHP_Esercizio1.iml
generated
Normal file
8
.idea/PHP_Esercizio1.iml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
7
.idea/discord.xml
generated
Normal file
7
.idea/discord.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="ASK" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
21
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
21
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,21 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N802" />
|
||||
<option value="N806" />
|
||||
<option value="N801" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="int.setEnabled" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
8
.idea/laravel-idea.xml
generated
Normal file
8
.idea/laravel-idea.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="InertiaPackage">
|
||||
<option name="directoryPaths">
|
||||
<list />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/PHP_Esercizio1.iml" filepath="$PROJECT_DIR$/.idea/PHP_Esercizio1.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
20
.idea/php.xml
generated
Normal file
20
.idea/php.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MessDetectorOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCSFixerOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
</project>
|
5
composer.json
Normal file
5
composer.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"require": {
|
||||
"ext-mysqli": "*"
|
||||
}
|
||||
}
|
7
config/database-connection.php
Normal file
7
config/database-connection.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$servername = "172.17.0.1";
|
||||
$username = "root";
|
||||
$password = "password";
|
||||
$dbname = "i5ai2_db";
|
||||
error_log("Connessione al database");
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@ -0,0 +1,9 @@
|
||||
services:
|
||||
webserver:
|
||||
image: phpstorm/php-apache:latest
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- ./:/var/www/html
|
||||
environment:
|
||||
XDEBUG_CONFIG: client_host=archlaptop
|
56
form.php
Normal file
56
form.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
use services\Access;
|
||||
require_once('services/Access.php');
|
||||
session_start();
|
||||
|
||||
$login_error = null;
|
||||
if(isset($_SESSION['login_error'])){
|
||||
$login_error = $_SESSION['login_error'];
|
||||
unset($_SESSION['login_error']);
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
error_log("POST data: " . json_encode($_POST));
|
||||
$data = $_POST;
|
||||
if (!empty($data['username']) && !empty($data['password'])) {
|
||||
$result = Access::login($data['username'], $data['password']);
|
||||
if($result && $result->num_rows > 0) {
|
||||
$_SESSION['username'] = $data['username'];
|
||||
$_SESSION['password'] = $data['password'];
|
||||
header('Location: http://localhost:8080/index.php/');
|
||||
} else {
|
||||
$login_error = "Username o password errati";
|
||||
$_SESSION['login_error'] = $login_error;
|
||||
header('Location: http://localhost:8080/form.php/');
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>LOGIN</h1>
|
||||
|
||||
<form action="" method="post">
|
||||
<label>
|
||||
<input type="text" placeholder="username" name="username">
|
||||
</label>
|
||||
<label>
|
||||
<input type="password" placeholder="password" name="password">
|
||||
</label>
|
||||
<button type="submit">Entra</button>
|
||||
</form>
|
||||
<?php
|
||||
if($login_error) {
|
||||
echo $login_error;
|
||||
}
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
72
index.php
Normal file
72
index.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// Controlla se qualcuno è loggato lmao
|
||||
use services\Access;
|
||||
|
||||
require_once('services/Access.php');
|
||||
|
||||
session_start();
|
||||
$username = null;
|
||||
$password = null;
|
||||
if (isset($_SESSION['username'])) {
|
||||
$username = $_SESSION['username'];
|
||||
}
|
||||
if (isset($_SESSION['password'])) {
|
||||
$password = $_SESSION['password'];
|
||||
}
|
||||
|
||||
$loginResult = Access::login($username, $password);
|
||||
|
||||
if (!$username || !$password || !$loginResult || !$loginResult->num_rows == 1) {
|
||||
header('Location: http://localhost:8080/form.php/');
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-family: "FreeSans";
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 600px;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
th {
|
||||
border: 1px solid black;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1> Tabella Utenti </h1>
|
||||
<?php
|
||||
|
||||
|
||||
global $conn;
|
||||
include "config/database-connection.php";
|
||||
|
||||
$query = "SELECT * FROM users";
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
echo "<table>";
|
||||
echo "<tr> <th> ID </th> <th> DESCRIZIONE </th> <th> DATA_CREAZIONE </th> <th>ID_PERSONA </th> </tr>";
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
echo "<tr>" .
|
||||
"<th>" . $row["ID"] . "</th>" .
|
||||
"<th>" . $row["DESCRIZIONE"] . "</th>" .
|
||||
"<th>" . $row["DATA_CREAZIONE"] . "</th>" .
|
||||
"<th>" . $row["ID_PERSONA"] . "</th>" .
|
||||
" </tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
?>
|
||||
</body>
|
||||
|
||||
|
||||
|
70
search.php
Normal file
70
search.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use services\Search;
|
||||
|
||||
require_once 'services/Search.php';
|
||||
$search = new Search();
|
||||
$username = null;
|
||||
$data = $_GET;
|
||||
if (!empty($data['username'])) {
|
||||
$username = $data['username'];
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<html lang="it">
|
||||
<head>
|
||||
|
||||
<title>Cerca</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: "FreeSans";
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
th {
|
||||
border: 1px solid black;
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Cerca </h1>
|
||||
<?php
|
||||
$formRicerca = "<form><label><input type=\"text\" placeholder=\"username\" name=\"username\"></label><button type=\"submit\">Cerca</button></form>";
|
||||
|
||||
if (empty($username)) {
|
||||
echo $formRicerca;
|
||||
} else {
|
||||
$result = Search::searchByUsername($username);
|
||||
if ($result->num_rows == 0) {
|
||||
echo "Utente " . $username . " non trovato";
|
||||
echo $formRicerca;
|
||||
} else {
|
||||
$data = $result->fetch_assoc();
|
||||
echo "
|
||||
<table>
|
||||
<tr>
|
||||
<th>" . $data["ID"] . "</th>" .
|
||||
"<th>" . $data["NOME"] . "</th>" .
|
||||
"<th>" . $data["COGNOME"] . "</th>" .
|
||||
"<th>" . $data["DATA_NASCITA"] . "</th>" .
|
||||
"<th>" . $data["LUOGO_NASCITA"] . "</th>" .
|
||||
"<th>" . $data["CF"] . "</th>" .
|
||||
"</tr>
|
||||
</table>
|
||||
";
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
14
services/Access.php
Normal file
14
services/Access.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace services;
|
||||
include 'config/database-connection.php';
|
||||
|
||||
class Access
|
||||
{
|
||||
static function login($username, $password)
|
||||
{
|
||||
global $conn;
|
||||
$query = "SELECT * FROM users WHERE DESCRIZIONE = '$username' AND PASSWORD = '$password'";
|
||||
return $conn->query($query);
|
||||
}
|
||||
}
|
17
services/Search.php
Normal file
17
services/Search.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace services;
|
||||
include 'config/database-connection.php';
|
||||
|
||||
class Search
|
||||
{
|
||||
static function searchByUsername($username)
|
||||
{
|
||||
global $conn;
|
||||
$query = "SELECT persone.* FROM users
|
||||
RIGHT JOIN persone ON persone.ID = users.ID_PERSONA
|
||||
WHERE users.DESCRIZIONE = '$username'";
|
||||
return $conn->query($query);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user