localhost geht hop-fly nicht

This commit is contained in:
2022-12-19 22:07:54 +01:00
parent bac04885b0
commit 3657ddf4ae
16 changed files with 301 additions and 28 deletions

1
docs/m7MdMK Normal file
View File

@ -0,0 +1 @@
m7MdMK

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View File

@ -22,7 +22,9 @@
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "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": { "eslintConfig": {
"extends": [ "extends": [
@ -43,6 +45,6 @@
] ]
}, },
"xxxhomepage____": "http://localhost:3000/dog", "xxxhomepage____": "http://localhost:3000/dog",
"xxxxhomepage": "https://hope-fly.de/dog", "homepage": "https://hope-fly.de/dog",
"homepage": "http://localhost/dog" "xxxxhomepage": "http://localhost/dog"
} }

View 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);
?>

View File

@ -16,19 +16,20 @@ $conn = $db_connection->dbConnection();
$data = json_decode(file_get_contents("php://input")); $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() );
var_dump( get_defined_vars() );
echo "xxxxxxx";
echo $data;
echo "-------";
$returnData = new CMsg(0); $returnData = new CMsg(0);
$fields = ['fields' => ['qr_id']]; $fields = ['fields' => ['qr_id']];
// if(true) // 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 // CHECKING EMPTY FIELDS
elseif(!isset($data->qr_id) if(!isset($data->qr_id)
|| empty(trim($data->qr_id)) || empty(trim($data->qr_id))
) )
{ {
@ -42,8 +43,8 @@ else
try try
{ {
$fetch_user_by_email = "SELECT * FROM `dogs` WHERE `qr_id`=:qr_id"; $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_by_email); $query_stmt = $conn->prepare($fetch_user_qr_id);
$query_stmt->bindValue(':qr_id', $qr_id,PDO::PARAM_STR); $query_stmt->bindValue(':qr_id', $qr_id,PDO::PARAM_STR);
$query_stmt->execute(); $query_stmt->execute();
@ -53,6 +54,10 @@ else
$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);
} }
else
{
$returnData = new CMsg(0,422,'no dog',$fields);
}
} }
catch(PDOException $e) catch(PDOException $e)
{ {

View File

@ -108,7 +108,7 @@ try
} }
else else
{ {
$returnData = new CMsg(0,422,'Invalid Email Address!'); $returnData = new CMsg(0,422,'Invalid Email Address! No Email found!');
} }
} }
catch(PDOException $e) catch(PDOException $e)

4
src/.htaccess Normal file
View File

@ -0,0 +1,4 @@
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

View File

@ -19,6 +19,7 @@ function App()
<div className="col middle"> <div className="col middle">
<BrowserRouter basename='/dog'> <BrowserRouter basename='/dog'>
<Routes> <Routes>
<Route path="/:qr_id" element={<Dog/>} />
<Route path="/" element={<Home/>} /> <Route path="/" element={<Home/>} />
<Route path="/d" element={<Dog/>} /> <Route path="/d" element={<Dog/>} />
<Route path="/login" element={<Login/>} /> <Route path="/login" element={<Login/>} />

View File

@ -1,15 +1,47 @@
import React from 'react' import { ResponseT, UserCtx, UserCtxT } from '../context/UserContext';
import { useParams, useSearchParams } from "react-router-dom"; 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 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 ( return (
<div> <div>
<h1>Dog</h1> <h1>Hast Du mich gefunden?</h1>
<p>{Object.keys(params)[0]}: {Object.values(params)[0]}</p> {/* <p>name: {name}</p>
<p>{Object.keys(params)[1]}: {Object.values(params)[1]}</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> </div>
) )
} }
export default Dog;

View 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
View 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
View File

@ -0,0 +1,9 @@
import React from 'react'
export default function Pic() {
return (
<div>
</div>
)
}

View File

@ -19,7 +19,8 @@ const Register = () => {
}) })
} }
const submitForm = async (e: React.FormEvent<HTMLFormElement>) => { const submitForm = async (e: React.FormEvent<HTMLFormElement>) =>
{
e.preventDefault(); e.preventDefault();
if(!Object.values(formData).every(val => val.trim() !== '')){ if(!Object.values(formData).every(val => val.trim() !== '')){
@ -38,7 +39,6 @@ const Register = () => {
setSuccessMsg("false"); setSuccessMsg("false");
setErrMsg(data.message); setErrMsg(data.message);
} }
} }
return ( return (

View File

@ -15,6 +15,28 @@ export type TUser =
name: string 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 = export type UserCtxT =
{ {
user: TUser | null, user: TUser | null,
@ -42,20 +64,25 @@ export type UserCtxT =
getUser: () => Promise<void>, getUser: () => Promise<void>,
logout: () => void logout: () => void,
getDog: (str: string | undefined) => Promise<ResponseT>,
dog: ResponseT
} }
export const UserCtx = createContext<UserCtxT | null>(null); export const UserCtx = createContext<UserCtxT | null>(null);
export const Axios = axios.create({ 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/', // baseURL: 'https://hope-fly.de/dog/php-dog/',
}); });
export const UserCtxProvider = ({children}:TUserContextProviderProps) => { export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
const [user, setUser] = useState<TUser | null>(null); const [user, setUser] = useState<TUser | null>(null);
const [wait, setWait] = useState(false); const [wait, setWait] = useState(false);
const [dog, setDog] = useState<ResponseT>({});
const registerUser = async ({email,password}: const registerUser = async ({email,password}:
{email: string, password: string}) => { {email: string, password: string}) => {
@ -154,6 +181,29 @@ export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
setUser(null); 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 ( return (
<UserCtx.Provider value={ <UserCtx.Provider value={
{ {
@ -162,7 +212,9 @@ export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
wait, wait,
user, user,
getUser, getUser,
logout logout,
getDog,
dog
}} }}
> >
{children} {children}

1
src/context/aa.html Normal file

File diff suppressed because one or more lines are too long

117
src/context/aaa.json Normal file
View File

@ -0,0 +1,117 @@
{
data: {
success: 0,
status: 422,
message: "Invalid Email Address!",
fields: "Invalid Email Address!",
data: null,
},
status: 200,
statusText: "OK",
headers: {
"cache-control": "no-store, no-cache, must-revalidate",
"content-length": "107",
"content-type": "application/json; charset=UTF-8",
expires: "Thu, 19 Nov 1981 08:52:00 GMT",
pragma: "no-cache",
},
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false,
},
adapter: [
"xhr",
"http",
],
transformRequest: [
function transformRequest(data, headers) {
const contentType = headers.getContentType() || '';
const hasJSONContentType = contentType.indexOf('application/json') > -1;
const isObjectPayload = _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isObject(data);
if (isObjectPayload && _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isHTMLForm(data)) {
data = new FormData(data);
}
const isFormData = _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isFormData(data);
if (isFormData) {
if (!hasJSONContentType) {
return data;
}
return hasJSONContentType ? JSON.stringify((0,_helpers_formDataToJSON_js__WEBPACK_IMPORTED_MODULE_2__["default"])(data)) : data;
}
if (_utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isArrayBuffer(data) || _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isBuffer(data) || _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isStream(data) || _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isFile(data) || _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isBlob(data)) {
return data;
}
if (_utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isArrayBufferView(data)) {
return data.buffer;
}
if (_utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isURLSearchParams(data)) {
headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
return data.toString();
}
let isFileList;
if (isObjectPayload) {
if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
return (0,_helpers_toURLEncodedForm_js__WEBPACK_IMPORTED_MODULE_3__["default"])(data, this.formSerializer).toString();
}
if ((isFileList = _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
const _FormData = this.env && this.env.FormData;
return (0,_helpers_toFormData_js__WEBPACK_IMPORTED_MODULE_4__["default"])(isFileList ? {
'files[]': data
} : data, _FormData && new _FormData(), this.formSerializer);
}
}
if (isObjectPayload || hasJSONContentType) {
headers.setContentType('application/json', false);
return stringifySafely(data);
}
return data;
},
],
transformResponse: [
function transformResponse(data) {
const transitional = this.transitional || defaults.transitional;
const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
const JSONRequested = this.responseType === 'json';
if (data && _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
const silentJSONParsing = transitional && transitional.silentJSONParsing;
const strictJSONParsing = !silentJSONParsing && JSONRequested;
try {
return JSON.parse(data);
} catch (e) {
if (strictJSONParsing) {
if (e.name === 'SyntaxError') {
throw _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_5__["default"].from(e, _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_5__["default"].ERR_BAD_RESPONSE, this, null, this.response);
}
throw e;
}
}
}
return data;
},
],
timeout: 0,
xsrfCookieName: "XSRF-TOKEN",
xsrfHeaderName: "X-XSRF-TOKEN",
maxContentLength: -1,
maxBodyLength: -1,
env: {
FormData: function FormData() { [native code] },
Blob: function Blob() { [native code] },
},
validateStatus: function validateStatus(status) {
return status >= 200 && status < 300;
},
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
baseURL: "http://localhost/dog/php-dog/",
method: "post",
url: "login.php",
data: "{\"email\":\"conny.rankl@web.de\",\"password\":\"mellyHund\"}",
},
request: {
},
}