läuft schon
This commit is contained in:
26
docs/dog.sql
26
docs/dog.sql
@ -1,11 +1,11 @@
|
|||||||
-- phpMyAdmin SQL Dump
|
-- phpMyAdmin SQL Dump
|
||||||
-- version 5.1.3
|
-- version 5.2.0
|
||||||
-- https://www.phpmyadmin.net/
|
-- https://www.phpmyadmin.net/
|
||||||
--
|
--
|
||||||
-- Host: 10.35.232.188:3306
|
-- Host: localhost
|
||||||
-- Erstellungszeit: 16. Dez 2022 um 10:38
|
-- Erstellungszeit: 17. Dez 2022 um 00:33
|
||||||
-- Server-Version: 8.0.31
|
-- Server-Version: 10.4.27-MariaDB
|
||||||
-- PHP-Version: 7.4.32
|
-- PHP-Version: 8.1.12
|
||||||
|
|
||||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||||
START TRANSACTION;
|
START TRANSACTION;
|
||||||
@ -29,14 +29,14 @@ SET time_zone = "+00:00";
|
|||||||
|
|
||||||
CREATE TABLE `dogs` (
|
CREATE TABLE `dogs` (
|
||||||
`id` int(11) NOT NULL,
|
`id` int(11) NOT NULL,
|
||||||
`email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL,
|
`email` varchar(255) NOT NULL,
|
||||||
`qr_id` char(31) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL,
|
`qr_id` char(31) NOT NULL,
|
||||||
`name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL,
|
`name` varchar(255) NOT NULL DEFAULT '',
|
||||||
`password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL,
|
`password` varchar(255) NOT NULL,
|
||||||
`phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL,
|
`phone` varchar(255) NOT NULL DEFAULT '',
|
||||||
`qr_code` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
`qr_code` varchar(255) DEFAULT NULL,
|
||||||
`picture` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL
|
`picture` varchar(255) DEFAULT NULL
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Indizes der exportierten Tabellen
|
-- Indizes der exportierten Tabellen
|
||||||
|
|||||||
29
package-lock.json
generated
29
package-lock.json
generated
@ -15,6 +15,7 @@
|
|||||||
"@types/node": "^16.18.9",
|
"@types/node": "^16.18.9",
|
||||||
"@types/react": "^18.0.26",
|
"@types/react": "^18.0.26",
|
||||||
"@types/react-dom": "^18.0.9",
|
"@types/react-dom": "^18.0.9",
|
||||||
|
"axios": "^1.2.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-router-dom": "^6.4.5",
|
"react-router-dom": "^6.4.5",
|
||||||
@ -4748,6 +4749,29 @@
|
|||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-I88cFiGu9ryt/tfVEi4kX2SITsvDddTajXTOFmt2uK1ZVA8LytjtdeyefdQWEf5PU8w+4SSJDoYnggflB5tW4A==",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.15.0",
|
||||||
|
"form-data": "^4.0.0",
|
||||||
|
"proxy-from-env": "^1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/axios/node_modules/form-data": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||||
|
"dependencies": {
|
||||||
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.8",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/axobject-query": {
|
"node_modules/axobject-query": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz",
|
||||||
@ -13645,6 +13669,11 @@
|
|||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/proxy-from-env": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||||
|
},
|
||||||
"node_modules/psl": {
|
"node_modules/psl": {
|
||||||
"version": "1.9.0",
|
"version": "1.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
"@types/node": "^16.18.9",
|
"@types/node": "^16.18.9",
|
||||||
"@types/react": "^18.0.26",
|
"@types/react": "^18.0.26",
|
||||||
"@types/react-dom": "^18.0.9",
|
"@types/react-dom": "^18.0.9",
|
||||||
|
"axios": "^1.2.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-router-dom": "^6.4.5",
|
"react-router-dom": "^6.4.5",
|
||||||
|
|||||||
@ -79,7 +79,7 @@ class Auth
|
|||||||
protected function fetchUser($user_id)
|
protected function fetchUser($user_id)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$fetch_user_by_id = "SELECT id, email, name, qr_id FROM dogs WHERE id=:id";
|
$fetch_user_by_id = "SELECT id, email, qr_id FROM dogs WHERE id=:id";
|
||||||
$query_stmt = $this->db->prepare($fetch_user_by_id);
|
$query_stmt = $this->db->prepare($fetch_user_by_id);
|
||||||
$query_stmt->bindValue(':id', $user_id, PDO::PARAM_INT);
|
$query_stmt->bindValue(':id', $user_id, PDO::PARAM_INT);
|
||||||
$query_stmt->execute();
|
$query_stmt->execute();
|
||||||
|
|||||||
@ -9,7 +9,8 @@ class Database
|
|||||||
private $db_username = 'k200835_user_dog';
|
private $db_username = 'k200835_user_dog';
|
||||||
private $db_password = 'X0pEiBsXN3RLazGhQVvP';
|
private $db_password = 'X0pEiBsXN3RLazGhQVvP';
|
||||||
|
|
||||||
public function dbConnection(){
|
public function dbConnection()
|
||||||
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
class CMsg
|
class CMsg
|
||||||
{
|
{
|
||||||
$success;
|
var $success;
|
||||||
$status;
|
var $status;
|
||||||
$message;
|
var $message;
|
||||||
$fields;
|
var $fields;
|
||||||
$data;
|
var $data;
|
||||||
|
|
||||||
function __construct($success,$status = null,$message = null,$fields = null,$data = null)
|
function __construct($success,$status = null,$message = null,$fields = null,$data = null)
|
||||||
{
|
{
|
||||||
@ -36,17 +36,15 @@ class CMsg
|
|||||||
|
|
||||||
class CUser
|
class CUser
|
||||||
{
|
{
|
||||||
$id;
|
var $id;
|
||||||
$qr_id;
|
var $qr_id;
|
||||||
$email;
|
var $email;
|
||||||
$name;
|
|
||||||
|
|
||||||
function __construct($id,$qr_id,$email,$name)
|
function __construct($id,$qr_id,$email)
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->qr_id = $qr_id;
|
$this->qr_id = $qr_id;
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
$this->name = $name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -51,12 +51,12 @@ else
|
|||||||
if($query_stmt->rowCount())
|
if($query_stmt->rowCount())
|
||||||
{
|
{
|
||||||
$row = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
$row = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
$returnData = new CMsg((1,200,'get dog',$fields,$row);
|
$returnData = new CMsg(1,200,'get dog',$fields,$row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(PDOException $e)
|
catch(PDOException $e)
|
||||||
{
|
{
|
||||||
$returnData = new CMsg((0,500,$e->getMessage(),$fields);
|
$returnData = new CMsg(0,500,$e->getMessage(),$fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo $returnData->jsonarray();
|
echo $returnData->jsonarray();
|
||||||
|
|||||||
@ -14,44 +14,63 @@ $db_connection = new Database();
|
|||||||
$conn = $db_connection->dbConnection();
|
$conn = $db_connection->dbConnection();
|
||||||
|
|
||||||
$data = json_decode(file_get_contents("php://input"));
|
$data = json_decode(file_get_contents("php://input"));
|
||||||
|
// $data = json_decode(
|
||||||
|
// '{
|
||||||
|
// "email": "a@a.a",
|
||||||
|
// "password": "qwertzui"
|
||||||
|
// }'
|
||||||
|
// );
|
||||||
$returnData = new CMsg(0);
|
$returnData = new CMsg(0);
|
||||||
|
|
||||||
// IF REQUEST METHOD IS NOT EQUAL TO POST
|
// IF REQUEST METHOD IS NOT EQUAL TO POST
|
||||||
if($_SERVER["REQUEST_METHOD"] != "POST")
|
// if($_SERVER["REQUEST_METHOD"] != "POST")
|
||||||
{
|
// {
|
||||||
$returnData = new CMsg(0,404,'Page Not Found!');
|
// $returnData = new CMsg(0,404,'Page Not Found!');
|
||||||
}
|
// echo $returnData->jsonarray();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
// CHECKING EMPTY FIELDS
|
// CHECKING EMPTY FIELDS
|
||||||
elseif(
|
if(
|
||||||
!isset($data->qr_id)
|
!isset($data->email)
|
||||||
|| !isset($data->password)
|
|| !isset($data->password)
|
||||||
|| empty(trim($data->qr_id))
|
|| empty(trim($data->email))
|
||||||
|| empty(trim($data->password))
|
|| empty(trim($data->password))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$fields = ['fields' => ['qr_id','password']];
|
$fields = ['fields' => ['email','password']];
|
||||||
$returnData = new CMsg(0,422,'Please Fill in all Required Fields!',$fields);
|
$returnData = new CMsg(0,422,'Please Fill in all Required Fields!',$fields);
|
||||||
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IF THERE ARE NO EMPTY FIELDS THEN-
|
// IF THERE ARE NO EMPTY FIELDS THEN-
|
||||||
else
|
$email = trim($data->email);
|
||||||
|
$password = trim($data->password);
|
||||||
|
|
||||||
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
|
||||||
{
|
{
|
||||||
$qr_id = trim($data->qr_id);
|
$returnData = new CMsg(0, 422, 'Invalid Email Address!');
|
||||||
$password = trim($data->password);
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// IF PASSWORD IS LESS THAN 8 THE SHOW THE ERROR
|
// IF PASSWORD IS LESS THAN 8 THE SHOW THE ERROR
|
||||||
if(strlen($password) < 8)
|
if(strlen($password) < 8)
|
||||||
{
|
{
|
||||||
$returnData = new CMsg(0,422,'Your password must be at least 8 characters long!');
|
$returnData = new CMsg(0,422,'Your password must be at least 8 characters long!');
|
||||||
}
|
echo $returnData->jsonarray();
|
||||||
// THE USER IS ABLE TO PERFORM THE LOGIN ACTION
|
return;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
try{
|
|
||||||
|
|
||||||
$fetch_user_by_qrid = "SELECT id, name, qr_id, email FROM `dogs` WHERE `qr_id`=:qr_id";
|
// THE USER IS ABLE TO PERFORM THE LOGIN ACTION
|
||||||
$query_stmt = $conn->prepare($fetch_user_by_qrid);
|
|
||||||
$query_stmt->bindValue(':qr_id', $qr_id,PDO::PARAM_STR);
|
try
|
||||||
|
{
|
||||||
|
$fetch_user_by_email = "SELECT id, qr_id, email, password FROM `dogs` WHERE `email`=:email";
|
||||||
|
$query_stmt = $conn->prepare($fetch_user_by_email);
|
||||||
|
$query_stmt->bindValue(':email', $email,PDO::PARAM_STR);
|
||||||
$query_stmt->execute();
|
$query_stmt->execute();
|
||||||
|
|
||||||
// IF THE USER IS FOUNDED BY EMAIL
|
// IF THE USER IS FOUNDED BY EMAIL
|
||||||
@ -59,6 +78,7 @@ else
|
|||||||
{
|
{
|
||||||
$row = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
$row = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
$check_password = password_verify($password, $row['password']);
|
$check_password = password_verify($password, $row['password']);
|
||||||
|
// $check_password = $password == $row['password'];
|
||||||
|
|
||||||
// VERIFYING THE PASSWORD (IS CORRECT OR NOT?)
|
// VERIFYING THE PASSWORD (IS CORRECT OR NOT?)
|
||||||
// IF PASSWORD IS CORRECT THEN SEND THE LOGIN TOKEN
|
// IF PASSWORD IS CORRECT THEN SEND THE LOGIN TOKEN
|
||||||
@ -67,8 +87,7 @@ else
|
|||||||
// $jwt = new JwtHandler();
|
// $jwt = new JwtHandler();
|
||||||
$user = new CUser( $row['id'],
|
$user = new CUser( $row['id'],
|
||||||
$row['qr_id'],
|
$row['qr_id'],
|
||||||
$row['email'],
|
$row['email']
|
||||||
$row['name']
|
|
||||||
);
|
);
|
||||||
$_SESSION['user'] = $user;
|
$_SESSION['user'] = $user;
|
||||||
|
|
||||||
@ -91,12 +110,10 @@ else
|
|||||||
{
|
{
|
||||||
$returnData = new CMsg(0,422,'Invalid Email Address!');
|
$returnData = new CMsg(0,422,'Invalid Email Address!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(PDOException $e)
|
catch(PDOException $e)
|
||||||
{
|
{
|
||||||
$returnData = new CMsg(0,500,$e->getMessage());
|
$returnData = new CMsg(0,500,$e->getMessage());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $returnData->jsonarray();
|
echo $returnData->jsonarray();
|
||||||
|
|||||||
@ -19,69 +19,90 @@ $returnData = new CMsg(0);
|
|||||||
if ($_SERVER["REQUEST_METHOD"] != "POST")
|
if ($_SERVER["REQUEST_METHOD"] != "POST")
|
||||||
{
|
{
|
||||||
$returnData = new CMsg(0, 404, 'Page Not Found!');
|
$returnData = new CMsg(0, 404, 'Page Not Found!');
|
||||||
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
elseif (
|
|
||||||
!isset($data->qr_id)
|
if (
|
||||||
|| !isset($data->nachname)
|
!isset($data->email)
|
||||||
|| !isset($data->email)
|
|
||||||
|| !isset($data->password)
|
|| !isset($data->password)
|
||||||
|| empty(trim($data->vorname))
|
|
||||||
|| empty(trim($data->nachname))
|
|
||||||
|| empty(trim($data->email))
|
|| empty(trim($data->email))
|
||||||
|| empty(trim($data->password))
|
|| empty(trim($data->password))
|
||||||
) :
|
)
|
||||||
|
{
|
||||||
|
|
||||||
$fields = ['fields' => ['vorname', 'nachname', 'email', 'password']];
|
$fields = ['fields' => ['email', 'password']];
|
||||||
$returnData = new CMsg(0, 422, 'Please Fill in all Required Fields!', $fields);
|
$returnData = new CMsg(0, 422, 'Please Fill in all Required Fields!', $fields);
|
||||||
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// IF THERE ARE NO EMPTY FIELDS THEN-
|
// IF THERE ARE NO EMPTY FIELDS THEN-
|
||||||
else :
|
$email = trim($data->email);
|
||||||
|
$password = trim($data->password);
|
||||||
|
|
||||||
$vorname = trim($data->vorname);
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
|
||||||
$nachname = trim($data->nachname);
|
{
|
||||||
$email = trim($data->email);
|
$returnData = new CMsg(0, 422, 'Invalid Email Address!');
|
||||||
$password = trim($data->password);
|
echo $returnData->jsonarray();
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) :
|
return;
|
||||||
$returnData = msg(0, 422, 'Invalid Email Address!');
|
}
|
||||||
|
|
||||||
elseif (strlen($password) < 8) :
|
if (strlen($password) < 8)
|
||||||
|
{
|
||||||
$returnData = new CMsg(0, 422, 'Your password must be at least 8 characters long!');
|
$returnData = new CMsg(0, 422, 'Your password must be at least 8 characters long!');
|
||||||
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
elseif (strlen($nachname) < 3) :
|
try
|
||||||
$returnData = new CMsg(0, 422, 'Your name must be at least 3 characters long!');
|
{
|
||||||
|
$maxtries = 100000; // prevent endless loop, most unlikely
|
||||||
|
$tries = 0;
|
||||||
|
|
||||||
else :
|
$qr_id = random_str(6);
|
||||||
try {
|
$count = 1;
|
||||||
|
while($count >= 1 && $tries < $maxtries)
|
||||||
|
{
|
||||||
|
$qr_id = random_str(6);
|
||||||
|
|
||||||
$check_email = "SELECT `email` FROM `users` WHERE `email`=:email";
|
$check_qr_id = "SELECT `qr_id` FROM `dogs` WHERE `qr_id`=:qr_id";
|
||||||
$check_email_stmt = $conn->prepare($check_email);
|
$check_qr_id_stmt = $conn->prepare($check_qr_id);
|
||||||
$check_email_stmt->bindValue(':email', $email, PDO::PARAM_STR);
|
$check_qr_id_stmt->bindValue(':qr_id', $qr_id, PDO::PARAM_STR);
|
||||||
$check_email_stmt->execute();
|
$check_qr_id_stmt->execute();
|
||||||
|
|
||||||
if ($check_email_stmt->rowCount()) :
|
$count = $check_qr_id_stmt->rowCount();
|
||||||
$returnData = new CMsg(0, 422, 'This E-mail already in use!');
|
++$tries;
|
||||||
|
}
|
||||||
else :
|
if ($tries >= $maxtries)
|
||||||
$insert_query = "INSERT INTO `users`(`vorname`,`nachname`,`email`,`password`) VALUES(:vorname,:nachname,:email,:password)";
|
{
|
||||||
|
$result = new CMsg(
|
||||||
|
0,
|
||||||
|
507,
|
||||||
|
'Too many users registered on the server, try it again later');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$insert_query = "INSERT INTO `dogs`(`qr_id`,`email`,`password`) VALUES(:qr_id,:email,:password)";
|
||||||
|
|
||||||
$insert_stmt = $conn->prepare($insert_query);
|
$insert_stmt = $conn->prepare($insert_query);
|
||||||
|
|
||||||
// DATA BINDING
|
// DATA BINDING
|
||||||
$insert_stmt->bindValue(':vorname', htmlspecialchars(strip_tags($vorname)), PDO::PARAM_STR);
|
$insert_stmt->bindValue(':qr_id', htmlspecialchars(strip_tags($qr_id)), 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(':email', $email, PDO::PARAM_STR);
|
||||||
|
// $insert_stmt->bindValue(':password', $password, PDO::PARAM_STR);
|
||||||
$insert_stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT), PDO::PARAM_STR);
|
$insert_stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT), PDO::PARAM_STR);
|
||||||
|
|
||||||
$insert_stmt->execute();
|
$insert_stmt->execute();
|
||||||
|
|
||||||
$returnData = new CMsg(1, 201, 'You have successfully registered.');
|
$returnData = new CMsg(1, 201, 'You have successfully registered.');
|
||||||
|
|
||||||
endif;
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
$returnData = new CMsg(0, 500, $e->getMessage());
|
|
||||||
}
|
}
|
||||||
endif;
|
|
||||||
endif;
|
}
|
||||||
|
catch (PDOException $e)
|
||||||
|
{
|
||||||
|
$returnData = new CMsg(0, 500, $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
echo $returnData->jsonarray();
|
echo $returnData->jsonarray();
|
||||||
?>
|
?>
|
||||||
@ -41,7 +41,7 @@ if(!in_array($fileType, $allowTypes))
|
|||||||
}
|
}
|
||||||
|
|
||||||
$newFilename = getNewFilename($targetDir, $fileType, 20);
|
$newFilename = getNewFilename($targetDir, $fileType, 20);
|
||||||
if($newFilename.strlen() == 0)
|
if(strlen($newFilename) == 0)
|
||||||
{
|
{
|
||||||
$result = new CMsg(
|
$result = new CMsg(
|
||||||
0,
|
0,
|
||||||
|
|||||||
@ -9,7 +9,6 @@
|
|||||||
name="description"
|
name="description"
|
||||||
content="Web site created using create-react-app"
|
content="Web site created using create-react-app"
|
||||||
/>
|
/>
|
||||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
|
||||||
<!--
|
<!--
|
||||||
manifest.json provides metadata used when your web app is installed on a
|
manifest.json provides metadata used when your web app is installed on a
|
||||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||||
|
|||||||
@ -6,19 +6,9 @@
|
|||||||
"src": "favicon.ico",
|
"src": "favicon.ico",
|
||||||
"sizes": "64x64 32x32 24x24 16x16",
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
"type": "image/x-icon"
|
"type": "image/x-icon"
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "logo192.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "192x192"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "logo512.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "512x512"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"start_url": ".",
|
"start_url": "./dog",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"theme_color": "#000000",
|
"theme_color": "#000000",
|
||||||
"background_color": "#ffffff"
|
"background_color": "#ffffff"
|
||||||
|
|||||||
17
src/App.tsx
17
src/App.tsx
@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import {useContext} from 'react'
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import { BrowserRouter, Routes, Route, Navigate} from 'react-router-dom';
|
import { BrowserRouter, Routes, Route, Navigate} from 'react-router-dom';
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
@ -6,20 +7,12 @@ import Login from './components/Login';
|
|||||||
import Register from './components/Register';
|
import Register from './components/Register';
|
||||||
import Home from './components/Home';
|
import Home from './components/Home';
|
||||||
import Dog from './components/Dog';
|
import Dog from './components/Dog';
|
||||||
|
import {UserCtx, UserCtxT} from './context/UserContext';
|
||||||
|
|
||||||
type UserT =
|
|
||||||
{
|
|
||||||
email: string;
|
|
||||||
password: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function App()
|
function App()
|
||||||
{
|
{
|
||||||
const user : UserT =
|
const {user} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
{
|
|
||||||
email: 'user@user.de',
|
|
||||||
password: 'GrüneWiese'
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
@ -34,7 +27,9 @@ function App()
|
|||||||
<Route path="/reg" element={<Register/>} />
|
<Route path="/reg" element={<Register/>} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<Route path="*" element={<Navigate to={user ? '/':'/login'} />} />
|
{/* <Route path="*" element={<Navigate to={user ? '/':'/login'} />} /> */}
|
||||||
|
<Route path="/login" element={<Login/>} />
|
||||||
|
<Route path="/reg" element={<Register/>} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,10 +1,58 @@
|
|||||||
import React from 'react'
|
import {useState,useContext} from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import {UserCtx, UserCtxT} from '../context/UserContext';
|
||||||
|
const Login = () => {
|
||||||
|
const {loginUser, wait, getUser} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
|
const [redirect, setRedirect] = useState("false");
|
||||||
|
const [errMsg, setErrMsg] = useState("false");
|
||||||
|
const [formData, setFormData] = useState({
|
||||||
|
email:'',
|
||||||
|
password:''
|
||||||
|
});
|
||||||
|
|
||||||
|
const onChangeInput = (e: React.FormEvent<HTMLInputElement>) =>
|
||||||
|
{
|
||||||
|
if(e.currentTarget.type === 'email' || e.currentTarget.type === 'password')
|
||||||
|
{
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
[e.currentTarget.name]:e.currentTarget.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitForm = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if(!Object.values(formData).every(val => val.trim() !== ''))
|
||||||
|
{
|
||||||
|
setErrMsg('Please Fill in all Required Fields!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await loginUser(formData);
|
||||||
|
if(data.success){
|
||||||
|
setRedirect('Redirecting...');
|
||||||
|
await getUser();
|
||||||
|
//e.currentTarget.reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setErrMsg(data.message);
|
||||||
|
}
|
||||||
|
|
||||||
export default function Login()
|
|
||||||
{
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>Login</h1>
|
<h2>Login</h2>
|
||||||
|
<form onSubmit={submitForm}>
|
||||||
|
<label htmlFor="email">Email:</label>
|
||||||
|
<input type="email" name="email" onChange={onChangeInput} placeholder="Your email" id="email" value={formData.email} required />
|
||||||
|
<label htmlFor="password">Password:</label>
|
||||||
|
<input type="password" name="password" onChange={onChangeInput} placeholder="New password" id="password" value={formData.password} required />
|
||||||
|
{errMsg !== "false" && <div className="err-msg">{errMsg}</div>}
|
||||||
|
{redirect !== "false" ? redirect : <button type="submit" disabled={wait}>Login</button>}
|
||||||
|
<div className="bottom-link"><Link to="/reg">Register</Link></div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
export default Login;
|
||||||
@ -1,9 +1,60 @@
|
|||||||
import React from 'react'
|
import {useContext, useState} from 'react'
|
||||||
|
import {Link} from 'react-router-dom'
|
||||||
|
import {UserCtx, UserCtxT} from '../context/UserContext';
|
||||||
|
|
||||||
|
|
||||||
|
const Register = () => {
|
||||||
|
const {registerUser, wait} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
|
const [errMsg, setErrMsg] = useState("false");
|
||||||
|
const [successMsg, setSuccessMsg] = useState("false");
|
||||||
|
const [formData, setFormData] = useState({
|
||||||
|
email:'',
|
||||||
|
password:''
|
||||||
|
});
|
||||||
|
|
||||||
|
const onChangeInput = (e: React.FormEvent<HTMLInputElement> ) => {
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
[e.currentTarget.name]:e.currentTarget.value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitForm = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if(!Object.values(formData).every(val => val.trim() !== '')){
|
||||||
|
setSuccessMsg("false");
|
||||||
|
setErrMsg('Bitte alle Felder ausfüllen!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await registerUser(formData);
|
||||||
|
if(data.success){
|
||||||
|
setSuccessMsg('Erfolgreich Registriert!');
|
||||||
|
setErrMsg("false");
|
||||||
|
e.currentTarget.reset();
|
||||||
|
}
|
||||||
|
else if(!data.success && data.message){
|
||||||
|
setSuccessMsg("false");
|
||||||
|
setErrMsg(data.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export default function Register() {
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>Register</h1>
|
<h2>Sign Up</h2>
|
||||||
|
<form onSubmit={submitForm}>
|
||||||
|
<label htmlFor="email">Email:</label>
|
||||||
|
<input type="email" name="email" onChange={onChangeInput} placeholder="Deine email" id="email" value={formData.email} required />
|
||||||
|
<label htmlFor="password">Password:</label>
|
||||||
|
<input type="password" name="password" onChange={onChangeInput} placeholder="New password" id="password" value={formData.password} required />
|
||||||
|
{successMsg !== "false" && <div className="success-msg">{successMsg}</div>}
|
||||||
|
{errMsg !== "false" && <div className="err-msg">{errMsg}</div>}
|
||||||
|
<button type="submit" disabled={wait}>Register</button>
|
||||||
|
<div className="bottom-link"><Link to="/login">Login</Link></div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
export default Register;
|
||||||
170
src/context/UserContext.tsx
Normal file
170
src/context/UserContext.tsx
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import {createContext, useState, useEffect} from 'react'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
export type TUserContextProviderProps =
|
||||||
|
{
|
||||||
|
children: React.ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TUser =
|
||||||
|
{
|
||||||
|
id: number,
|
||||||
|
qr_id: string,
|
||||||
|
email: string,
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UserCtxT =
|
||||||
|
{
|
||||||
|
user: TUser | null,
|
||||||
|
|
||||||
|
registerUser: ({ email, password }: {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
}) => Promise<any>,
|
||||||
|
|
||||||
|
loginUser: (
|
||||||
|
{ email, password } :
|
||||||
|
{
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
},
|
||||||
|
) => Promise<{
|
||||||
|
success: number;
|
||||||
|
message?: undefined;
|
||||||
|
} | {
|
||||||
|
success: number;
|
||||||
|
message: any;
|
||||||
|
}>,
|
||||||
|
|
||||||
|
wait: boolean,
|
||||||
|
|
||||||
|
getUser: () => Promise<void>,
|
||||||
|
|
||||||
|
logout: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export const UserCtx = createContext<UserCtxT | null>(null);
|
||||||
|
|
||||||
|
export const Axios = axios.create({
|
||||||
|
baseURL: 'http://localhost/dog/php-dog/',
|
||||||
|
});
|
||||||
|
|
||||||
|
export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
|
||||||
|
|
||||||
|
const [user, setUser] = useState<TUser | null>(null);
|
||||||
|
const [wait, setWait] = useState(false);
|
||||||
|
|
||||||
|
const registerUser = async ({email,password}:
|
||||||
|
{email: string, password: string}) => {
|
||||||
|
setWait(true);
|
||||||
|
try{
|
||||||
|
const {data} = await Axios.post('register.php',{
|
||||||
|
email,
|
||||||
|
password
|
||||||
|
});
|
||||||
|
setWait(false);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
catch(err){
|
||||||
|
setWait(false);
|
||||||
|
return {success:0, message:'Server Error!'};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loginUser = async ({email,password}:{email: string, password: string}) =>
|
||||||
|
{
|
||||||
|
setWait(true);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var postReturn:
|
||||||
|
{
|
||||||
|
data:
|
||||||
|
{
|
||||||
|
success: number;
|
||||||
|
message: string;
|
||||||
|
user: TUser | null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
= { data : {success: 0, message: '', user: null } };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
postReturn = await Axios.post('login.php',{
|
||||||
|
email,
|
||||||
|
password
|
||||||
|
});
|
||||||
|
|
||||||
|
const {data} = postReturn;
|
||||||
|
if(data.success && data.user)
|
||||||
|
{
|
||||||
|
setUser(data.user);
|
||||||
|
setWait(false);
|
||||||
|
return {success:1};
|
||||||
|
}
|
||||||
|
setWait(false);
|
||||||
|
return {success:0, message:data.message};
|
||||||
|
}
|
||||||
|
catch(err){
|
||||||
|
setWait(false);
|
||||||
|
return {success:0, message:'Server Error!'};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUser = async () =>
|
||||||
|
{
|
||||||
|
if(user)
|
||||||
|
{
|
||||||
|
const {data} = await Axios.get('getUser.php');
|
||||||
|
if(data.success && data.user)
|
||||||
|
{
|
||||||
|
setUser(data.user);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setUser(null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const {data} = await Axios.get('session.php');
|
||||||
|
if(data.success && data.user)
|
||||||
|
{
|
||||||
|
setUser(data.user);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() =>
|
||||||
|
{
|
||||||
|
async function asyncCall()
|
||||||
|
{
|
||||||
|
await getUser();
|
||||||
|
}
|
||||||
|
asyncCall();
|
||||||
|
},[]);
|
||||||
|
|
||||||
|
const logout = async () =>
|
||||||
|
{
|
||||||
|
await Axios.get('logout.php');
|
||||||
|
setUser(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<UserCtx.Provider value={
|
||||||
|
{
|
||||||
|
registerUser,
|
||||||
|
loginUser,
|
||||||
|
wait,
|
||||||
|
user,
|
||||||
|
getUser,
|
||||||
|
logout
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</UserCtx.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
@ -2,12 +2,16 @@ import React from 'react';
|
|||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
import { UserCtxProvider } from './context/UserContext';
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(
|
const root = ReactDOM.createRoot(
|
||||||
document.getElementById('root') as HTMLElement
|
document.getElementById('root') as HTMLElement
|
||||||
);
|
);
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
<UserCtxProvider>
|
||||||
<App />
|
<App />
|
||||||
|
</UserCtxProvider>
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user