diff --git a/docs/m7MdMK b/docs/m7MdMK new file mode 100644 index 0000000..46aec41 --- /dev/null +++ b/docs/m7MdMK @@ -0,0 +1 @@ +m7MdMK \ No newline at end of file diff --git a/docs/testAnhaenger.odt b/docs/testAnhaenger.odt new file mode 100644 index 0000000..7d8c400 Binary files /dev/null and b/docs/testAnhaenger.odt differ diff --git a/docs/threema-20221219-154859460.jpg b/docs/threema-20221219-154859460.jpg new file mode 100644 index 0000000..defe168 Binary files /dev/null and b/docs/threema-20221219-154859460.jpg differ diff --git a/package.json b/package.json index a945972..029e337 100644 --- a/package.json +++ b/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" } diff --git a/php/php-dog/classes/ranStr.php b/php/php-dog/classes/ranStr.php new file mode 100644 index 0000000..4f02dae --- /dev/null +++ b/php/php-dog/classes/ranStr.php @@ -0,0 +1,26 @@ + diff --git a/php/php-dog/getDog.php b/php/php-dog/getDog.php index f3e132c..752c28b 100644 --- a/php/php-dog/getDog.php +++ b/php/php-dog/getDog.php @@ -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) { diff --git a/php/php-dog/login.php b/php/php-dog/login.php index d92e729..b9779e5 100644 --- a/php/php-dog/login.php +++ b/php/php-dog/login.php @@ -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) diff --git a/src/.htaccess b/src/.htaccess new file mode 100644 index 0000000..1cccaa1 --- /dev/null +++ b/src/.htaccess @@ -0,0 +1,4 @@ +Options -MultiViews + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.html [QSA,L] \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index ab71f31..61a8d69 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -19,6 +19,7 @@ function App()
+ } /> } /> } /> } /> diff --git a/src/components/Dog.tsx b/src/components/Dog.tsx index c5d18de..4585cdd 100644 --- a/src/components/Dog.tsx +++ b/src/components/Dog.tsx @@ -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(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 (
-

Dog

-

{Object.keys(params)[0]}: {Object.values(params)[0]}

-

{Object.keys(params)[1]}: {Object.values(params)[1]}

+

Hast Du mich gefunden?

+ {/*

name: {name}

+

email: {email}

+

phone: {phone}

+

pic: {picPath}

+

qr: {qrPath}

*/} + +
) -} \ No newline at end of file +} +export default Dog; \ No newline at end of file diff --git a/src/components/DogNameTxt.tsx b/src/components/DogNameTxt.tsx new file mode 100644 index 0000000..b50fdd2 --- /dev/null +++ b/src/components/DogNameTxt.tsx @@ -0,0 +1,13 @@ +import React from 'react' + +export default function DogNameTxt( + {name, email, phone}: + {name: string, email: string, phone: string}) { + return ( +
+

Hallo ich bin die

{name}!

+

bitte schreib eine Mail an

{email}

+ oder ruf

{phone} an,

damit ich schnell wieder Heim komme.

+
+ ) +} diff --git a/src/components/Img.tsx b/src/components/Img.tsx new file mode 100644 index 0000000..8b2b2c0 --- /dev/null +++ b/src/components/Img.tsx @@ -0,0 +1,10 @@ +import React from 'react' + +export default function Img({pth}: {pth: string}) +{ + return ( +
+ +
+ ) +} diff --git a/src/components/Pic.tsx b/src/components/Pic.tsx new file mode 100644 index 0000000..5e384c5 --- /dev/null +++ b/src/components/Pic.tsx @@ -0,0 +1,9 @@ +import React from 'react' + +export default function Pic() { + return ( +
+ +
+ ) +} diff --git a/src/components/Register.tsx b/src/components/Register.tsx index b1fd162..cdfc8be 100644 --- a/src/components/Register.tsx +++ b/src/components/Register.tsx @@ -19,7 +19,8 @@ const Register = () => { }) } - const submitForm = async (e: React.FormEvent) => { + const submitForm = async (e: React.FormEvent) => + { e.preventDefault(); if(!Object.values(formData).every(val => val.trim() !== '')){ @@ -38,7 +39,6 @@ const Register = () => { setSuccessMsg("false"); setErrMsg(data.message); } - } return ( diff --git a/src/context/UserContext.tsx b/src/context/UserContext.tsx index 29b59c0..0790b5a 100644 --- a/src/context/UserContext.tsx +++ b/src/context/UserContext.tsx @@ -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, - logout: () => void + logout: () => void, + + getDog: (str: string | undefined) => Promise, + + dog: ResponseT } export const UserCtx = createContext(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(null); const [wait, setWait] = useState(false); + const [dog, setDog] = useState({}); 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('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 ( { wait, user, getUser, - logout + logout, + getDog, + dog }} > {children}