Merge remote-tracking branch 'origin/noContextProvider'
This commit is contained in:
1
docs/m7MdMK
Normal file
1
docs/m7MdMK
Normal file
@ -0,0 +1 @@
|
||||
m7MdMK
|
||||
BIN
docs/testAnhaenger.odt
Normal file
BIN
docs/testAnhaenger.odt
Normal file
Binary file not shown.
BIN
docs/threema-20221219-154859460.jpg
Normal file
BIN
docs/threema-20221219-154859460.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
10
package.json
10
package.json
@ -22,8 +22,10 @@
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eject": "react-scripts eject",
|
||||
|
||||
"postbuild": "cp ./src/.htaccess ./build/ && sudo cp -r -v ./build/static/ /opt/lampp/htdocs/dog/ && sudo cp -v ./build/* /opt/lampp/htdocs/dog/"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
@ -43,6 +45,6 @@
|
||||
]
|
||||
},
|
||||
"xxxhomepage____": "http://localhost:3000/dog",
|
||||
"xxxxhomepage": "https://hope-fly.de/dog",
|
||||
"homepage": "http://localhost/dog"
|
||||
"homepage": "https://hope-fly.de/dog",
|
||||
"xxxxhomepage": "http://localhost/dog"
|
||||
}
|
||||
|
||||
26
php/php-dog/classes/ranStr.php
Normal file
26
php/php-dog/classes/ranStr.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
function random_str(
|
||||
$length,
|
||||
$keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
)
|
||||
{
|
||||
$str = '';
|
||||
$max = mb_strlen($keyspace, '8bit') - 1;
|
||||
if ($max < 1)
|
||||
{
|
||||
throw new Exception('$keyspace must be at least two characters long');
|
||||
}
|
||||
for ($i = 0; $i < $length; ++$i)
|
||||
{
|
||||
$str .= $keyspace[random_int(0, $max)];
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
echo random_str(20);
|
||||
|
||||
?>
|
||||
@ -15,20 +15,20 @@ $db_connection = new Database();
|
||||
$conn = $db_connection->dbConnection();
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"));
|
||||
// $data = json_decode('{ "qr_id": "m7MdMK" }');
|
||||
//$data = json_decode('{ "qr_id": "m7MdMK" }');
|
||||
|
||||
// var_dump( get_defined_vars() );
|
||||
// echo "xxxxxxx";
|
||||
// echo $data;
|
||||
// echo "-------";
|
||||
|
||||
$returnData = new CMsg(0);
|
||||
$fields = ['fields' => ['qr_id']];
|
||||
|
||||
// if(true)
|
||||
|
||||
// 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)
|
||||
if(!isset($data->qr_id)
|
||||
|| empty(trim($data->qr_id))
|
||||
)
|
||||
{
|
||||
@ -42,8 +42,8 @@ else
|
||||
|
||||
try
|
||||
{
|
||||
$fetch_user_by_email = "SELECT * FROM `dogs` WHERE `qr_id`=:qr_id";
|
||||
$query_stmt = $conn->prepare($fetch_user_by_email);
|
||||
$fetch_user_qr_id = "SELECT id, qr_id, email, name, phone, qr_code, picture FROM `dogs` WHERE `qr_id`=:qr_id";
|
||||
$query_stmt = $conn->prepare($fetch_user_qr_id);
|
||||
$query_stmt->bindValue(':qr_id', $qr_id,PDO::PARAM_STR);
|
||||
$query_stmt->execute();
|
||||
|
||||
@ -53,6 +53,10 @@ else
|
||||
$row = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$returnData = new CMsg(1,200,'get dog',$fields,$row);
|
||||
}
|
||||
else
|
||||
{
|
||||
$returnData = new CMsg(0,422,'no dog',$fields);
|
||||
}
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
|
||||
@ -108,7 +108,7 @@ try
|
||||
}
|
||||
else
|
||||
{
|
||||
$returnData = new CMsg(0,422,'Invalid Email Address!');
|
||||
$returnData = new CMsg(0,422,'Invalid Email Address! No Email found!');
|
||||
}
|
||||
}
|
||||
catch(PDOException $e)
|
||||
|
||||
4
src/.htaccess
Normal file
4
src/.htaccess
Normal file
@ -0,0 +1,4 @@
|
||||
Options -MultiViews
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.html [QSA,L]
|
||||
@ -19,6 +19,7 @@ function App()
|
||||
<div className="col middle">
|
||||
<BrowserRouter basename='/dog'>
|
||||
<Routes>
|
||||
<Route path="/:qr_id" element={<Dog/>} />
|
||||
<Route path="/" element={<Home/>} />
|
||||
<Route path="/d" element={<Dog/>} />
|
||||
<Route path="/login" element={<Login/>} />
|
||||
|
||||
@ -1,15 +1,47 @@
|
||||
import React from 'react'
|
||||
import { useParams, useSearchParams } from "react-router-dom";
|
||||
import { ResponseT, UserCtx, UserCtxT } from '../context/UserContext';
|
||||
import React, { useContext, useState } from 'react'
|
||||
import { useParams } from "react-router-dom";
|
||||
import Img from './Img';
|
||||
import DogNameTxt from './DogNameTxt';
|
||||
|
||||
export default function Dog()
|
||||
const Dog = () =>
|
||||
{
|
||||
const {getDog, dog} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||
|
||||
// m7MdMK
|
||||
const params = useParams();
|
||||
const searchParams = useSearchParams();
|
||||
const qr_id = Object.values(params)[0];
|
||||
var data;
|
||||
var needData = dog.success === undefined;
|
||||
if(needData)
|
||||
{
|
||||
data = getDog(qr_id); // await not allowed?! => workaraound
|
||||
}
|
||||
var email = "nicht definiert;"
|
||||
var phone = "nicht definiert;"
|
||||
var picPath = "nicht definiert;"
|
||||
var qrPath = "nicht definiert;"
|
||||
var name = "nicht definiert;"
|
||||
if(dog.success === 1)
|
||||
{
|
||||
name = dog.data.name;
|
||||
qrPath = dog.data.qr_code;
|
||||
picPath = dog.data.picture;
|
||||
email = dog.data.email;
|
||||
phone = dog.data.phone;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Dog</h1>
|
||||
<p>{Object.keys(params)[0]}: {Object.values(params)[0]}</p>
|
||||
<p>{Object.keys(params)[1]}: {Object.values(params)[1]}</p>
|
||||
<h1>Hast Du mich gefunden?</h1>
|
||||
{/* <p>name: {name}</p>
|
||||
<p>email: {email}</p>
|
||||
<p>phone: {phone}</p>
|
||||
<p>pic: {picPath}</p>
|
||||
<p>qr: {qrPath}</p> */}
|
||||
<Img pth={picPath} />
|
||||
<DogNameTxt name={name} email={email} phone={phone} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
export default Dog;
|
||||
13
src/components/DogNameTxt.tsx
Normal file
13
src/components/DogNameTxt.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import React from 'react'
|
||||
|
||||
export default function DogNameTxt(
|
||||
{name, email, phone}:
|
||||
{name: string, email: string, phone: string}) {
|
||||
return (
|
||||
<div>
|
||||
<p>Hallo ich bin die <p>{name}!</p></p>
|
||||
<p>bitte schreib eine Mail an <p>{email}</p>
|
||||
oder ruf <p>{phone} an,</p>damit ich schnell wieder Heim komme.</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
10
src/components/Img.tsx
Normal file
10
src/components/Img.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
|
||||
export default function Img({pth}: {pth: string})
|
||||
{
|
||||
return (
|
||||
<div>
|
||||
<img src={'./uploads' + pth} width="300" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
9
src/components/Pic.tsx
Normal file
9
src/components/Pic.tsx
Normal file
@ -0,0 +1,9 @@
|
||||
import React from 'react'
|
||||
|
||||
export default function Pic() {
|
||||
return (
|
||||
<div>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@ -19,7 +19,8 @@ const Register = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const submitForm = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
const submitForm = async (e: React.FormEvent<HTMLFormElement>) =>
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
if(!Object.values(formData).every(val => val.trim() !== '')){
|
||||
@ -38,7 +39,6 @@ const Register = () => {
|
||||
setSuccessMsg("false");
|
||||
setErrMsg(data.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -15,6 +15,28 @@ export type TUser =
|
||||
name: string
|
||||
}
|
||||
|
||||
export type DogT =
|
||||
{
|
||||
id: number,
|
||||
qr_id: string,
|
||||
email: string,
|
||||
name: string,
|
||||
phone: string,
|
||||
qr_code: string,
|
||||
picture: string
|
||||
};
|
||||
|
||||
export type ResponseT =
|
||||
{
|
||||
success: number,
|
||||
status: number,
|
||||
message: string,
|
||||
fields: string,
|
||||
data: DogT
|
||||
} | any;
|
||||
|
||||
|
||||
|
||||
export type UserCtxT =
|
||||
{
|
||||
user: TUser | null,
|
||||
@ -42,13 +64,17 @@ export type UserCtxT =
|
||||
|
||||
getUser: () => Promise<void>,
|
||||
|
||||
logout: () => void
|
||||
logout: () => void,
|
||||
|
||||
getDog: (str: string | undefined) => Promise<ResponseT>,
|
||||
|
||||
dog: ResponseT
|
||||
}
|
||||
|
||||
export const UserCtx = createContext<UserCtxT | null>(null);
|
||||
|
||||
export const Axios = axios.create({
|
||||
// baseURL: 'http://localhost/dog/php-dog/',
|
||||
// baseURL: 'http://localhost/dog/php-dog/',
|
||||
baseURL: 'https://hope-fly.de/dog/php-dog/',
|
||||
});
|
||||
|
||||
@ -56,6 +82,7 @@ export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
|
||||
|
||||
const [user, setUser] = useState<TUser | null>(null);
|
||||
const [wait, setWait] = useState(false);
|
||||
const [dog, setDog] = useState<ResponseT>({});
|
||||
|
||||
const registerUser = async ({email,password}:
|
||||
{email: string, password: string}) => {
|
||||
@ -154,6 +181,29 @@ export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
|
||||
setUser(null);
|
||||
}
|
||||
|
||||
const getDog = async ( str: string | undefined) =>
|
||||
{
|
||||
var ret: ResponseT = {};
|
||||
setWait(true);
|
||||
|
||||
try
|
||||
{
|
||||
ret = await Axios.post<ResponseT>('getDog.php',
|
||||
{
|
||||
qr_id: str
|
||||
});
|
||||
setDog(ret.data as ResponseT);
|
||||
setWait(false);
|
||||
return;
|
||||
}
|
||||
catch (error:any)
|
||||
{
|
||||
console.log('error message: ', error.message);
|
||||
setWait(false);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<UserCtx.Provider value={
|
||||
{
|
||||
@ -162,7 +212,9 @@ export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
|
||||
wait,
|
||||
user,
|
||||
getUser,
|
||||
logout
|
||||
logout,
|
||||
getDog,
|
||||
dog
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user