last master commit
This commit is contained in:
@ -28,7 +28,7 @@ class CMsg
|
|||||||
'success' => $this->success,
|
'success' => $this->success,
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'message' => $this->message,
|
'message' => $this->message,
|
||||||
'fields' => $this->message,
|
'fields' => $this->fields,
|
||||||
'data' => $this->data
|
'data' => $this->data
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,37 +1,42 @@
|
|||||||
import { UserCtx, UserCtxT } from '../context/UserContext';
|
import { ResponseT, DogT} from '../context/UserContext';
|
||||||
import { useContext, ReactNode } from 'react'
|
import { ReactNode, useState } from 'react'
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import Img from './Img';
|
import Img from './Img';
|
||||||
import DogNameTxt from './DogNameTxt';
|
import DogNameTxt from './DogNameTxt';
|
||||||
import './Dog.css';
|
import './Dog.css';
|
||||||
|
import {getDog} from '../services/PhpApi'
|
||||||
|
|
||||||
const Dog = () =>
|
const Dog = () =>
|
||||||
{
|
{
|
||||||
const {getDog, dog} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
const [success, setSuccess] = useState<number>(0);
|
||||||
|
|
||||||
// m7MdMK
|
// m7MdMK
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const qr_id = Object.values(params)[0];
|
const qr_id = Object.values(params)[0];
|
||||||
var needData = dog.success === undefined;
|
var dogRes : ResponseT = {};
|
||||||
if(needData)
|
var dog: DogT = dogRes.data;
|
||||||
|
|
||||||
|
getDog(qr_id).then((resDog) =>
|
||||||
{
|
{
|
||||||
getDog(qr_id); // await not allowed?! => workaraound
|
dogRes = Object.assign({},resDog);
|
||||||
}
|
dog = Object.assign({},resDog.data);
|
||||||
|
setSuccess(dogRes.success);
|
||||||
|
});
|
||||||
|
|
||||||
var email = "nicht definiert;"
|
var email = "nicht definiert;"
|
||||||
var phone = "nicht definiert;"
|
var phone = "nicht definiert;"
|
||||||
var picPath = "nicht definiert;"
|
var picPath = "nicht definiert;"
|
||||||
//var qrPath = "nicht definiert;"
|
//var qrPath = "nicht definiert;"
|
||||||
var name = "nicht definiert;"
|
var name = "nicht definiert;"
|
||||||
if(dog.success === 1)
|
if(success === 1)
|
||||||
{
|
{
|
||||||
name = dog.data.name;
|
name = dog.name;
|
||||||
//qrPath = dog.data.qr_code;
|
//qrPath = dog.data.qr_code;
|
||||||
picPath = dog.data.picture;
|
picPath = dog.picture;
|
||||||
email = dog.data.email;
|
email = dog.email;
|
||||||
phone = dog.data.phone;
|
phone = dog.phone;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content: ReactNode = dog.success === 1 ?
|
const content: ReactNode = success === 1 ?
|
||||||
<div className = 'Dog'>
|
<div className = 'Dog'>
|
||||||
<h1>Hast Du mich gefunden?</h1>
|
<h1>Hast Du mich gefunden?</h1>
|
||||||
{/* <p>name: {name}</p>
|
{/* <p>name: {name}</p>
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import React, { useContext } from 'react'
|
|||||||
import { UserCtx, UserCtxT } from '../context/UserContext';
|
import { UserCtx, UserCtxT } from '../context/UserContext';
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const {loginUser, wait, getUser, user} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
const {user} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>Home</h1>
|
<h1>Home</h1>
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import {useState,useContext} from 'react';
|
import {useState,useContext} from 'react';
|
||||||
import { Link, useNavigate } from 'react-router-dom';
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
import {UserCtx, UserCtxT} from '../context/UserContext';
|
import {UserCtx, UserCtxT} from '../context/UserContext';
|
||||||
import './Login.css'
|
import './Login.css';
|
||||||
|
import {loginUser} from '../services/PhpApi'
|
||||||
|
|
||||||
const Login = () =>
|
const Login = () =>
|
||||||
{
|
{
|
||||||
const {loginUser, wait, getUser, user} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
const {wait, getUser, user} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
const [redirect, setRedirect] = useState("false");
|
const [redirect, setRedirect] = useState("false");
|
||||||
const [errMsg, setErrMsg] = useState("false");
|
const [errMsg, setErrMsg] = useState("false");
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
@ -39,12 +40,12 @@ const Login = () =>
|
|||||||
if(data.success)
|
if(data.success)
|
||||||
{
|
{
|
||||||
setRedirect('Redirecting...');
|
setRedirect('Redirecting...');
|
||||||
setErrMsg(data.message);
|
setErrMsg(data.message!);
|
||||||
await getUser();
|
await getUser();
|
||||||
navigate('/profil');
|
navigate('/profil');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setErrMsg(data.message);
|
setErrMsg(data.message!);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -2,10 +2,10 @@ import {useContext, useState} from 'react'
|
|||||||
import {Link} from 'react-router-dom'
|
import {Link} from 'react-router-dom'
|
||||||
import {UserCtx, UserCtxT} from '../context/UserContext';
|
import {UserCtx, UserCtxT} from '../context/UserContext';
|
||||||
import './Register.css';
|
import './Register.css';
|
||||||
|
import {registerUser} from '../services/PhpApi';
|
||||||
|
|
||||||
const Register = () => {
|
const Register = () => {
|
||||||
const {registerUser, wait} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
const {wait} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
const [errMsg, setErrMsg] = useState("false");
|
const [errMsg, setErrMsg] = useState("false");
|
||||||
const [successMsg, setSuccessMsg] = useState("false");
|
const [successMsg, setSuccessMsg] = useState("false");
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
|
|||||||
@ -12,29 +12,27 @@ export const Axios = axios.create({
|
|||||||
export const updateDog = async ({email, name, phone}:
|
export const updateDog = async ({email, name, phone}:
|
||||||
{email: string, name: string, phone: string}) =>
|
{email: string, name: string, phone: string}) =>
|
||||||
{
|
{
|
||||||
const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
// const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
setWait(true);
|
// setWait(true);
|
||||||
try{
|
try{
|
||||||
const {data} = await Axios.post('updateDog.php',{
|
const {data} = await Axios.post('updateDog.php',{
|
||||||
email,
|
email,
|
||||||
name,
|
name,
|
||||||
phone
|
phone
|
||||||
});
|
});
|
||||||
setWait(false);
|
// setWait(false);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
catch(err){
|
catch(err){
|
||||||
setWait(false);
|
// setWait(false);
|
||||||
return {success:0, message:'Server Error!'};
|
return {success:0, message:'Server Error!'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getDog = async ( str: string | undefined) =>
|
export const getDog = async ( str: string | undefined) : Promise<ResponseT> =>
|
||||||
{
|
{
|
||||||
const { setWait, setDog } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
|
||||||
|
|
||||||
var ret: ResponseT = {};
|
var ret: ResponseT = {};
|
||||||
setWait(true);
|
// setWait(true);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -42,33 +40,43 @@ export const getDog = async ( str: string | undefined) =>
|
|||||||
{
|
{
|
||||||
qr_id: str
|
qr_id: str
|
||||||
});
|
});
|
||||||
setDog(ret.data as ResponseT);
|
// setDog(ret.data as ResponseT);
|
||||||
setWait(false);
|
// setWait(false);
|
||||||
return;
|
return ret.data as ResponseT;
|
||||||
}
|
}
|
||||||
catch (error:any)
|
catch (error:any)
|
||||||
{
|
{
|
||||||
console.log('error message: ', error.message);
|
console.log('error message: ', error.message);
|
||||||
setWait(false);
|
// setWait(false);
|
||||||
return;
|
ret =
|
||||||
|
{
|
||||||
|
success: 0,
|
||||||
|
status: 500,
|
||||||
|
message: error.message,
|
||||||
|
fields: null,
|
||||||
|
data: null
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const registerUser = async ({email,password}:
|
export const registerUser = async ({email,password}:
|
||||||
{email: string, password: string}) =>
|
{email: string, password: string}) =>
|
||||||
{
|
{
|
||||||
const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
// const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
setWait(true);
|
// setWait(true);
|
||||||
try{
|
try{
|
||||||
const {data} = await Axios.post('register.php',{
|
const {data} = await Axios.post('register.php',
|
||||||
|
{
|
||||||
email,
|
email,
|
||||||
password
|
password
|
||||||
});
|
});
|
||||||
setWait(false);
|
// setWait(false);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
catch(err){
|
catch(err)
|
||||||
setWait(false);
|
{
|
||||||
|
// setWait(false);
|
||||||
return {success:0, message:'Server Error!'};
|
return {success:0, message:'Server Error!'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,30 +84,33 @@ export const registerUser = async ({email,password}:
|
|||||||
export const updateQR = async ({qr_width_cm, qr_height_cm, qr_fontsize, qr_visible_items, qr_item_sequence}:
|
export const updateQR = async ({qr_width_cm, qr_height_cm, qr_fontsize, qr_visible_items, qr_item_sequence}:
|
||||||
{qr_width_cm: number, qr_height_cm: number, qr_fontsize: number, qr_visible_items: number, qr_item_sequence: number}) =>
|
{qr_width_cm: number, qr_height_cm: number, qr_fontsize: number, qr_visible_items: number, qr_item_sequence: number}) =>
|
||||||
{
|
{
|
||||||
const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
// const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
|
|
||||||
setWait(true);
|
// setWait(true);
|
||||||
try{
|
try
|
||||||
const {data} = await Axios.post('updateQR.php',{
|
{
|
||||||
|
const {data} = await Axios.post('updateQR.php',
|
||||||
|
{
|
||||||
qr_width_cm,
|
qr_width_cm,
|
||||||
qr_height_cm,
|
qr_height_cm,
|
||||||
qr_fontsize,
|
qr_fontsize,
|
||||||
qr_visible_items,
|
qr_visible_items,
|
||||||
qr_item_sequence
|
qr_item_sequence
|
||||||
});
|
});
|
||||||
setWait(false);
|
// setWait(false);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
catch(err){
|
catch(err)
|
||||||
setWait(false);
|
{
|
||||||
|
// setWait(false);
|
||||||
return {success:0, message:'Server Error!'};
|
return {success:0, message:'Server Error!'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loginUser = async ({email,password}:{email: string, password: string}) =>
|
export const loginUser = async ({email,password}:{email: string, password: string}) =>
|
||||||
{
|
{
|
||||||
const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
// const { setWait } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
setWait(true);
|
// setWait(true);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var postReturn:
|
var postReturn:
|
||||||
@ -113,32 +124,32 @@ export const loginUser = async ({email,password}:{email: string, password: strin
|
|||||||
}
|
}
|
||||||
= { data : {success: 0, message: '', data: null } };
|
= { data : {success: 0, message: '', data: null } };
|
||||||
|
|
||||||
postReturn = await Axios.post('login.php',{
|
postReturn = await Axios.post('login.php',
|
||||||
email,
|
{
|
||||||
password
|
email,
|
||||||
});
|
password
|
||||||
|
});
|
||||||
|
|
||||||
const {data} = postReturn;
|
const {data} = postReturn;
|
||||||
if(data.success && data.data)
|
if(data.success && data.data)
|
||||||
{
|
{
|
||||||
setUser(data.data);
|
// setUser(data.data);
|
||||||
setWait(false);
|
// setWait(false);
|
||||||
return {success:1};
|
return {success:1};
|
||||||
}
|
}
|
||||||
setWait(false);
|
// setWait(false);
|
||||||
return {success:0, message:data.message};
|
return {success:0, message:data.message};
|
||||||
}
|
}
|
||||||
catch(err){
|
catch(err)
|
||||||
setWait(false);
|
{
|
||||||
|
// setWait(false);
|
||||||
return {success:0, message:'Server Error!'};
|
return {success:0, message:'Server Error!'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const logout = async () =>
|
// export const logout = async () =>
|
||||||
{
|
// {
|
||||||
const { setUser } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
// await Axios.get('logout.php');
|
||||||
await Axios.get('logout.php');
|
// }
|
||||||
setUser(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user