qr_id route php getDog
This commit is contained in:
BIN
docs/dog-face.png
Normal file
BIN
docs/dog-face.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
28
docs/dog.sql
28
docs/dog.sql
@ -3,7 +3,7 @@
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: localhost
|
||||
-- Erstellungszeit: 14. Dez 2022 um 22:08
|
||||
-- Erstellungszeit: 15. Dez 2022 um 22:02
|
||||
-- Server-Version: 10.4.27-MariaDB
|
||||
-- PHP-Version: 8.1.12
|
||||
|
||||
@ -18,7 +18,7 @@ SET time_zone = "+00:00";
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
--
|
||||
-- Datenbank: `dog`
|
||||
-- Datenbank: `k200835_dog`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
@ -29,13 +29,13 @@ SET time_zone = "+00:00";
|
||||
|
||||
CREATE TABLE `dogs` (
|
||||
`id` int(11) NOT NULL,
|
||||
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`qr_id` char(31) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||
`qr_code` mediumblob NOT NULL,
|
||||
`picture` mediumblob NOT NULL
|
||||
`email` varchar(255) NOT NULL,
|
||||
`qr_id` char(31) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`phone` varchar(255) NOT NULL,
|
||||
`qr_code` mediumblob DEFAULT NULL,
|
||||
`picture` mediumblob DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
--
|
||||
@ -49,6 +49,16 @@ ALTER TABLE `dogs`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD UNIQUE KEY `index_qr_id` (`qr_id`),
|
||||
ADD UNIQUE KEY `index_email` (`email`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT für exportierte Tabellen
|
||||
--
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT für Tabelle `dogs`
|
||||
--
|
||||
ALTER TABLE `dogs`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
|
||||
1
docs/options.json
Normal file
1
docs/options.json
Normal file
File diff suppressed because one or more lines are too long
BIN
docs/qr-hope-fly.png
Normal file
BIN
docs/qr-hope-fly.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.1 KiB |
BIN
docs/qr-localhost-3000.png
Normal file
BIN
docs/qr-localhost-3000.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
BIN
docs/qr-localhost.png
Normal file
BIN
docs/qr-localhost.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
@ -41,5 +41,5 @@
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"homepage": "http://localhost/li"
|
||||
"homepage": "http://localhost/dog"
|
||||
}
|
||||
|
||||
24
php/php-dog/classes/Database.php
Normal file
24
php/php-dog/classes/Database.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class Database{
|
||||
|
||||
// CHANGE THE DB INFO ACCORDING TO YOUR DATABASE
|
||||
private $db_host = 'localhost';
|
||||
//private $db_host = '10.35.232.188:3306';
|
||||
private $db_name = 'k200835_dog';
|
||||
private $db_username = 'k200835_user_dog';
|
||||
private $db_password = 'X0pEiBsXN3RLazGhQVvP';
|
||||
|
||||
public function dbConnection(){
|
||||
|
||||
try{
|
||||
$conn = new PDO('mysql:host='.$this->db_host.';dbname='.$this->db_name,$this->db_username,$this->db_password);
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
return $conn;
|
||||
}
|
||||
catch(PDOException $e){
|
||||
echo "Connection error ".$e->getMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
69
php/php-dog/getDog.php
Normal file
69
php/php-dog/getDog.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: access");
|
||||
header("Access-Control-Allow-Methods: POST");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
session_start();
|
||||
|
||||
require __DIR__.'/classes/Database.php';
|
||||
//require __DIR__.'/classes/JwtHandler.php';
|
||||
|
||||
function msg($success,$status,$message,$fields,$data = []){
|
||||
return ([
|
||||
'success' => $success,
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'fields' => $message,
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
$db_connection = new Database();
|
||||
$conn = $db_connection->dbConnection();
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"));
|
||||
$returnData = [];
|
||||
$fields = ['fields' => ['qr_id']];
|
||||
|
||||
// IF REQUEST METHOD IS NOT EQUAL TO POST
|
||||
if($_SERVER["REQUEST_METHOD"] != "POST")
|
||||
{
|
||||
$returnData = msg(0,404,'Page Not Found!',$fields,null);
|
||||
}
|
||||
// CHECKING EMPTY FIELDS
|
||||
elseif(!isset($data->qr_id)
|
||||
|| empty(trim($data->qr_id))
|
||||
)
|
||||
{
|
||||
$returnData = msg(0,422,'Please Fill in all Required Fields!',$fields, null);
|
||||
|
||||
}
|
||||
// IF THERE ARE NO EMPTY FIELDS THEN-
|
||||
else
|
||||
{
|
||||
$qr_id = trim($data->qr_id);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
$fetch_user_by_email = "SELECT * FROM `dogs` WHERE `qr_id`=:qr_id";
|
||||
$query_stmt = $conn->prepare($fetch_user_by_email);
|
||||
$query_stmt->bindValue(':qr_id', $email,PDO::PARAM_STR);
|
||||
$query_stmt->execute();
|
||||
|
||||
// IF THE dog IS FOUNDED BY qr_id
|
||||
if($query_stmt->rowCount())
|
||||
{
|
||||
$row = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$returnData = msg(1,200,'get dog',$fields,$row);
|
||||
}
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
$returnData = msg(0,500,$e->getMessage(),$fields,null);
|
||||
}
|
||||
|
||||
}
|
||||
echo json_encode($returnData);
|
||||
18
php/php-dog/getUser.php
Normal file
18
php/php-dog/getUser.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: access");
|
||||
header("Access-Control-Allow-Methods: GET");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
session_start();
|
||||
|
||||
require __DIR__.'/classes/Database.php';
|
||||
require __DIR__.'/AuthMiddleware.php';
|
||||
|
||||
$allHeaders = getallheaders();
|
||||
$db_connection = new Database();
|
||||
$conn = $db_connection->dbConnection();
|
||||
$auth = new Auth($conn, $allHeaders);
|
||||
|
||||
echo json_encode($auth->isValid());
|
||||
106
php/php-dog/login.php
Normal file
106
php/php-dog/login.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: access");
|
||||
header("Access-Control-Allow-Methods: POST");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
session_start();
|
||||
|
||||
require __DIR__.'/classes/Database.php';
|
||||
//require __DIR__.'/classes/JwtHandler.php';
|
||||
|
||||
function msg($success,$status,$message,$extra = []){
|
||||
return array_merge([
|
||||
'success' => $success,
|
||||
'status' => $status,
|
||||
'message' => $message
|
||||
],$extra);
|
||||
}
|
||||
|
||||
$db_connection = new Database();
|
||||
$conn = $db_connection->dbConnection();
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"));
|
||||
$returnData = [];
|
||||
|
||||
// IF REQUEST METHOD IS NOT EQUAL TO POST
|
||||
if($_SERVER["REQUEST_METHOD"] != "POST"):
|
||||
$returnData = msg(0,404,'Page Not Found!');
|
||||
|
||||
// CHECKING EMPTY FIELDS
|
||||
elseif(!isset($data->email)
|
||||
|| !isset($data->password)
|
||||
|| empty(trim($data->email))
|
||||
|| empty(trim($data->password))
|
||||
):
|
||||
|
||||
$fields = ['fields' => ['email','password']];
|
||||
$returnData = msg(0,422,'Please Fill in all Required Fields!',$fields);
|
||||
|
||||
// IF THERE ARE NO EMPTY FIELDS THEN-
|
||||
else:
|
||||
$email = trim($data->email);
|
||||
$password = trim($data->password);
|
||||
|
||||
// CHECKING THE EMAIL FORMAT (IF INVALID FORMAT)
|
||||
if(!filter_var($email, FILTER_VALIDATE_EMAIL)):
|
||||
$returnData = msg(0,422,'Invalid Email Address!');
|
||||
|
||||
// IF PASSWORD IS LESS THAN 8 THE SHOW THE ERROR
|
||||
elseif(strlen($password) < 8):
|
||||
$returnData = msg(0,422,'Your password must be at least 8 characters long!');
|
||||
|
||||
// THE USER IS ABLE TO PERFORM THE LOGIN ACTION
|
||||
else:
|
||||
try{
|
||||
|
||||
$fetch_user_by_email = "SELECT * FROM `users` WHERE `email`=:email";
|
||||
$query_stmt = $conn->prepare($fetch_user_by_email);
|
||||
$query_stmt->bindValue(':email', $email,PDO::PARAM_STR);
|
||||
$query_stmt->execute();
|
||||
|
||||
// IF THE USER IS FOUNDED BY EMAIL
|
||||
if($query_stmt->rowCount()):
|
||||
$row = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$check_password = password_verify($password, $row['password']);
|
||||
|
||||
// VERIFYING THE PASSWORD (IS CORRECT OR NOT?)
|
||||
// IF PASSWORD IS CORRECT THEN SEND THE LOGIN TOKEN
|
||||
if ($check_password):
|
||||
|
||||
// $jwt = new JwtHandler();
|
||||
$user = array(
|
||||
'id' => $row['id'],
|
||||
'vorname' => $row['vorname'],
|
||||
'nachname' => $row['nachname'],
|
||||
'email' => $row['email']
|
||||
);
|
||||
$_SESSION['user'] = $user;
|
||||
|
||||
$returnData = [
|
||||
'success' => 1,
|
||||
'message' => 'You have successfully logged in.',
|
||||
'user' => $user,
|
||||
'session' => $_SESSION
|
||||
];
|
||||
|
||||
// IF INVALID PASSWORD
|
||||
else:
|
||||
$returnData = msg(0,422,'Invalid Password!');
|
||||
endif;
|
||||
|
||||
// IF THE USER IS NOT FOUNDED BY EMAIL THEN SHOW THE FOLLOWING ERROR
|
||||
else:
|
||||
$returnData = msg(0,422,'Invalid Email Address!');
|
||||
endif;
|
||||
}
|
||||
catch(PDOException $e){
|
||||
$returnData = msg(0,500,$e->getMessage());
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
echo json_encode($returnData);
|
||||
11
php/php-dog/logout.php
Normal file
11
php/php-dog/logout.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: access");
|
||||
header("Access-Control-Allow-Methods: POST");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
session_start();
|
||||
session_destroy();
|
||||
session_abort();
|
||||
?>
|
||||
94
php/php-dog/register.php
Normal file
94
php/php-dog/register.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: access");
|
||||
header("Access-Control-Allow-Methods: POST");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
session_start();
|
||||
|
||||
require __DIR__ . '/classes/Database.php';
|
||||
$db_connection = new Database();
|
||||
$conn = $db_connection->dbConnection();
|
||||
|
||||
function msg($success, $status, $message, $extra = [])
|
||||
{
|
||||
return array_merge([
|
||||
'success' => $success,
|
||||
'status' => $status,
|
||||
'message' => $message
|
||||
], $extra);
|
||||
}
|
||||
|
||||
// DATA FORM REQUEST
|
||||
$data = json_decode(file_get_contents("php://input"));
|
||||
$returnData = [];
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] != "POST") :
|
||||
|
||||
$returnData = msg(0, 404, 'Page Not Found!');
|
||||
|
||||
elseif (
|
||||
!isset($data->vorname)
|
||||
|| !isset($data->nachname)
|
||||
|| !isset($data->email)
|
||||
|| !isset($data->password)
|
||||
|| empty(trim($data->vorname))
|
||||
|| empty(trim($data->nachname))
|
||||
|| empty(trim($data->email))
|
||||
|| empty(trim($data->password))
|
||||
) :
|
||||
|
||||
$fields = ['fields' => ['vorname', 'nachname', 'email', 'password']];
|
||||
$returnData = msg(0, 422, 'Please Fill in all Required Fields!', $fields);
|
||||
|
||||
// IF THERE ARE NO EMPTY FIELDS THEN-
|
||||
else :
|
||||
|
||||
$vorname = trim($data->vorname);
|
||||
$nachname = trim($data->nachname);
|
||||
$email = trim($data->email);
|
||||
$password = trim($data->password);
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) :
|
||||
$returnData = msg(0, 422, 'Invalid Email Address!');
|
||||
|
||||
elseif (strlen($password) < 8) :
|
||||
$returnData = msg(0, 422, 'Your password must be at least 8 characters long!');
|
||||
|
||||
elseif (strlen($nachname) < 3) :
|
||||
$returnData = msg(0, 422, 'Your name must be at least 3 characters long!');
|
||||
|
||||
else :
|
||||
try {
|
||||
|
||||
$check_email = "SELECT `email` FROM `users` WHERE `email`=:email";
|
||||
$check_email_stmt = $conn->prepare($check_email);
|
||||
$check_email_stmt->bindValue(':email', $email, PDO::PARAM_STR);
|
||||
$check_email_stmt->execute();
|
||||
|
||||
if ($check_email_stmt->rowCount()) :
|
||||
$returnData = msg(0, 422, 'This E-mail already in use!');
|
||||
|
||||
else :
|
||||
$insert_query = "INSERT INTO `users`(`vorname`,`nachname`,`email`,`password`) VALUES(:vorname,:nachname,:email,:password)";
|
||||
|
||||
$insert_stmt = $conn->prepare($insert_query);
|
||||
|
||||
// DATA BINDING
|
||||
$insert_stmt->bindValue(':vorname', htmlspecialchars(strip_tags($vorname)), PDO::PARAM_STR);
|
||||
$insert_stmt->bindValue(':nachname', htmlspecialchars(strip_tags($nachname)), PDO::PARAM_STR);
|
||||
$insert_stmt->bindValue(':email', $email, PDO::PARAM_STR);
|
||||
$insert_stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT), PDO::PARAM_STR);
|
||||
|
||||
$insert_stmt->execute();
|
||||
|
||||
$returnData = msg(1, 201, 'You have successfully registered.');
|
||||
|
||||
endif;
|
||||
} catch (PDOException $e) {
|
||||
$returnData = msg(0, 500, $e->getMessage());
|
||||
}
|
||||
endif;
|
||||
endif;
|
||||
|
||||
echo json_encode($returnData);
|
||||
23
php/php-dog/session.php
Normal file
23
php/php-dog/session.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: access");
|
||||
header("Access-Control-Allow-Methods: GET");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
session_start();
|
||||
$return =
|
||||
[
|
||||
"success" => 0,
|
||||
"user" => null
|
||||
];
|
||||
|
||||
if (isset($_SESSION['user'])) {
|
||||
$return =
|
||||
[
|
||||
"success" => 1,
|
||||
"user" => $_SESSION['user']
|
||||
];
|
||||
}
|
||||
echo json_encode($return);
|
||||
?>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.4 KiB |
@ -5,6 +5,7 @@ import "./App.css";
|
||||
import Login from './components/Login';
|
||||
import Register from './components/Register';
|
||||
import Home from './components/Home';
|
||||
import Dog from './components/Dog';
|
||||
|
||||
type UserT =
|
||||
{
|
||||
@ -28,6 +29,7 @@ function App()
|
||||
{ user && <Route path="/" element={<Home/>} /> }
|
||||
{user && (
|
||||
<>
|
||||
<Route path="/:qr_id" element={<Dog/>} />
|
||||
<Route path="/login" element={<Login/>} />
|
||||
<Route path="/reg" element={<Register/>} />
|
||||
</>
|
||||
|
||||
13
src/components/Dog.tsx
Normal file
13
src/components/Dog.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import React from 'react'
|
||||
import { useParams } from "react-router-dom";
|
||||
|
||||
export default function Dog()
|
||||
{
|
||||
const params = useParams();
|
||||
return (
|
||||
<div>
|
||||
<h1>Dog</h1>
|
||||
<p>{Object.keys(params)[0]}: {Object.values(params)[0]}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user