diff --git a/php/php-dog/classes/CNetcupMailer.php b/php/php-dog/classes/CNetcupMailer.php new file mode 100644 index 0000000..3170d93 --- /dev/null +++ b/php/php-dog/classes/CNetcupMailer.php @@ -0,0 +1,22 @@ +SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output + $this->SMTPDebug = SMTP::DEBUG_OFF; //no output + $this->isSMTP(); //Send using SMTP + $this->Host = 'mxe8bd.netcup.net'; //Set the SMTP server to send through + $this->SMTPAuth = true; //Enable SMTP authentication + $this->Username = 'dog@hope-fly.de'; //SMTP username + $this->Password = 'DgQduKV6uBWXQcCqmAjL'; //SMTP password + $this->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption + $this->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` + } +} +?> diff --git a/php/php-dog/classes/lib.php b/php/php-dog/classes/lib.php index e49e725..eca8b48 100644 --- a/php/php-dog/classes/lib.php +++ b/php/php-dog/classes/lib.php @@ -1,20 +1,4 @@ SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output - $this->isSMTP(); //Send using SMTP - $this->Host = 'mxe8bd.netcup.net'; //Set the SMTP server to send through - $this->SMTPAuth = true; //Enable SMTP authentication - $this->Username = 'dog@hope-fly.de'; //SMTP username - $this->Password = 'DgQduKV6uBWXQcCqmAjL'; //SMTP password - $this->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption - $this->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` - } -} class CMsg { var $success; diff --git a/php/php-dog/foundEmail.php b/php/php-dog/foundEmail.php index 5de593d..5092399 100644 --- a/php/php-dog/foundEmail.php +++ b/php/php-dog/foundEmail.php @@ -1,4 +1,8 @@ setFrom($fromEmail); + $mail->addAddress($toEmail); //Add a recipient + $mail->addReplyTo($fromEmail); + $mail->addCC($fromEmail); + $mail->addBCC('dog@hope-fly.de'); + + //Attachments + + //Content + $mail->Subject = $subject; + $mail->Body = $msg; + + if ($mail->send()) { $result = new CMsg(1, 200, "Email send successfully."); $storeResult = storeEmail(); } else { - $result = new CMsg(1, 500, "Sorry, there was an error sending your email your file."); + $result = new CMsg(1, 500, "Sorry, there was an error sending your email."); } echo $result->jsonarray(); } catch (Exception $e) { - $result = new CMsg(0, 500, $e->getMessage() ); + $err = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; + $err .= "\r\n" . $e->getMessage(); + $result = new CMsg(0, 500, $err); echo $result->jsonarray(); } - function storeEmail() { global $qr_id, $conn, $msg, $fromEmail; diff --git a/php/php-dog/getUser.php b/php/php-dog/getUser.php index 856e5c6..d4ba9e5 100644 --- a/php/php-dog/getUser.php +++ b/php/php-dog/getUser.php @@ -16,4 +16,5 @@ $conn = $db_connection->dbConnection(); $auth = new Auth($conn, $allHeaders); echo $auth->isValid(); +//echo (__DIR__); ?> \ No newline at end of file diff --git a/php/php-dog/tstEmail.php b/php/php-dog/tstEmail.php index 835fa14..737795f 100644 --- a/php/php-dog/tstEmail.php +++ b/php/php-dog/tstEmail.php @@ -4,13 +4,13 @@ use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; //Load Composer's autoloader -require __DIR__.'../../vendor/autoload.php'; +require '../../vendor/autoload.php'; -//Load Composer's autoloader -require __DIR__.'./classes/lib.php'; +require './classes/lib.php'; //Create an instance; passing `true` enables exceptions $mail = new CNetcupMailer(true); +//$mail = new PHPMailer(true); try { @@ -26,9 +26,11 @@ try { //Attachments //Content - $mail->Subject = 'jo subject jo XXXXX'; - $mail->Body = 'XXXX This is the txt message bodyThis is the txt message body This is the txt message bodyThis is the txt message body'; + $mail->Subject = 'aaaa jo subject jo XXXXX'; + $mail->Body = 'aaaaaa XXXX This is the txt message bodyThis is the txt message body This is the txt message bodyThis is the txt message body'; +// $mail->send(); +// echo 'Message has been NOT sent'; $mail->send(); echo 'Message has been sent'; } diff --git a/src/App.tsx b/src/App.tsx index 98af1d5..f289d16 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,7 +3,6 @@ import './App.css'; import { BrowserRouter, Routes, Route } from 'react-router-dom'; import Login from './components/Login'; import Register from './components/Register'; -import Home from './components/Home'; import Dog from './components/Dog'; import Qr from './components/Qr'; import Header from './components/Header'; @@ -16,6 +15,8 @@ import useSWR from 'swr'; import {getUser} from './services/PhpApi' import toast, { Toaster } from 'react-hot-toast'; import { TUser } from './context/UserContext'; +import PasswordReset from './components/PasswordReset'; +import WantNewPw from './components/WantNewPw'; const App: React.FC = () => { @@ -60,6 +61,8 @@ const App: React.FC = () => } /> } /> } /> + } /> + } /> {user && } />} {user && } />} diff --git a/src/components/Login.css b/src/components/InputForm.css similarity index 90% rename from src/components/Login.css rename to src/components/InputForm.css index c7ce66b..b552d12 100644 --- a/src/components/Login.css +++ b/src/components/InputForm.css @@ -1,4 +1,4 @@ -.Login +.InputForm form { width: 65%; diff --git a/src/components/Login.tsx b/src/components/Login.tsx index b18e0f8..028f1ad 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -1,6 +1,6 @@ import {useState} from 'react'; import { Link/*, useNavigate*/ } from 'react-router-dom'; -import './Login.css'; +import './InputForm.css'; import {getUser, loginUser} from '../services/PhpApi' import { toast, Toaster } from 'react-hot-toast'; import useSWR from 'swr'; @@ -67,7 +67,7 @@ const Login = () => } return ( -
+

Login

@@ -82,6 +82,7 @@ const Login = () =>
Register
+
Passwort vergessen
) diff --git a/src/components/PasswordReset.tsx b/src/components/PasswordReset.tsx new file mode 100644 index 0000000..447c84d --- /dev/null +++ b/src/components/PasswordReset.tsx @@ -0,0 +1,82 @@ +import React, { useState } from 'react' +import toast, { Toaster } from 'react-hot-toast'; +import { Link, useParams } from 'react-router-dom'; +import { passwordReset } from '../services/PhpApi'; +import './InputForm.css'; + +export default function PasswordReset() +{ + const params = useParams(); + const passwordToken = Object.values(params)[0]; + + const [formData, setFormData] = useState({ + password1:'', + password2:'' + }); + + const onChangeInput = (e: React.FormEvent ) => { + setFormData({ + ...formData, + [e.currentTarget.name]:e.currentTarget.value + }) + } + + const submitForm = async (e: React.FormEvent) => + { + e.preventDefault(); + + if(!Object.values(formData).every(val => val.trim() !== '')) + { + toast.error('Bitte alle Felder ausfüllen!'); + return; + } + + if(formData.password1 !== formData.password2) + { + toast.error('Bitte 2mal das gleiche Passwort eingeben!'); + return; + } + + const sendData = new FormData(); + const values = Object.values(formData); + const keys = Object.keys(formData); + + for (const key of keys) + { + const index = keys.indexOf(key); + sendData.append(key, values[index]); + } + + sendData.append('passwordToken', passwordToken!); + + const data = await passwordReset(sendData); + if(data.success) + { + toast.success('Erfolgreich Passwort geändert!'); + e.currentTarget.reset(); + } + else if(!data.success && data.message) + { + toast.error(data.message); + } + } + + return ( +
+ +

Passwort zurücksetzten!

+
+
+ + +
+
+ + +
+ +
Login
+
+
+ ) +} diff --git a/src/components/Profil.css b/src/components/Profil.css index facf80b..e09097c 100644 --- a/src/components/Profil.css +++ b/src/components/Profil.css @@ -1,12 +1,3 @@ -.Profil -form -{ - width: 65%; - display: flex; - flex-direction: column; - align-items: flex-end; -} - button.QRakt { max-width: 80%; diff --git a/src/components/Profil.tsx b/src/components/Profil.tsx index df6992c..5bd18f5 100644 --- a/src/components/Profil.tsx +++ b/src/components/Profil.tsx @@ -6,6 +6,7 @@ import {TUser} from '../context/UserContext'; import {getProfilData, updateDog} from '../services/PhpApi'; import CreateQr from '../services/CreateQr'; import Img from './Img'; +import './InputForm.css'; import './Profil.css'; function Profil() @@ -141,7 +142,7 @@ function Profil() console.log(formData_loc); return ( -
+

Profil

diff --git a/src/components/Register.css b/src/components/Register.css deleted file mode 100644 index c3f62e5..0000000 --- a/src/components/Register.css +++ /dev/null @@ -1,8 +0,0 @@ -.Register -form -{ - width: 65%; - display: flex; - flex-direction: column; - align-items: flex-end; -} diff --git a/src/components/Register.tsx b/src/components/Register.tsx index 41f60fd..68c6c14 100644 --- a/src/components/Register.tsx +++ b/src/components/Register.tsx @@ -1,7 +1,7 @@ import {useState} from 'react' import {Link} from 'react-router-dom' import toast, { Toaster } from 'react-hot-toast'; -import './Register.css'; +import './InputForm.css'; import {registerUser} from '../services/PhpApi'; const Register = () => @@ -48,7 +48,7 @@ const Register = () => } return ( -
+

Register

diff --git a/src/components/WantNewPw.tsx b/src/components/WantNewPw.tsx new file mode 100644 index 0000000..fd0ea10 --- /dev/null +++ b/src/components/WantNewPw.tsx @@ -0,0 +1,52 @@ +import React, { useState } from 'react' +import toast, { Toaster } from 'react-hot-toast'; +import './ImportForm.css'; + +function WantNewPw() +{ + const [email, setEmail] = useState(''); + + const onChangeInput = (e: React.FormEvent ) => { + setEmail(e.currentTarget.value); + } + + const submitForm = async (e: React.FormEvent) => + { + e.preventDefault(); + + if(e.currentTarget.value.trim() !== '') + { + toast.error('Bitte Feld ausfüllen!'); + return; + } + + const data = await wantNewPw(email); + if(data.success) + { + toast.success('Erfolgreich Passwort geändert!'); + e.currentTarget.reset(); + } + else if(!data.success && data.message) + { + toast.error(data.message); + } + } + + return ( +
+ +

Neues Passwort setzen!

+ +
+ + +
+ + +
+ ) +} + +export default WantNewPw \ No newline at end of file diff --git a/src/services/PhpApi.ts b/src/services/PhpApi.ts index 7cc1b7f..58f49cc 100644 --- a/src/services/PhpApi.ts +++ b/src/services/PhpApi.ts @@ -22,7 +22,7 @@ export const updateDog = async ({email, name, phone}: return data; } catch(err){ - return {success:0, message:'Server Error!'}; + return {success:0, message:'Update Dog Server Error!'}; } } @@ -81,7 +81,7 @@ export const registerUser = async ({email,password}: } catch(err) { - return {success:0, message:'Server Error!'}; + return {success:0, message:'Register User Server Error!'}; } } @@ -106,7 +106,7 @@ export const foundMsg = async (form_data: } catch(err) { - return {success:0, message:'Server Error!'}; + return {success:0, message:'Found Msg Server Error!'}; } } @@ -137,7 +137,7 @@ export const updateQR = async ({qr_width_cm, qr_height_cm, qr_fontsize, qr_visib } catch(err) { - return {success:0, message:'Server Error!'}; + return {success:0, message:'Update QR Server Error!'}; } } @@ -240,6 +240,38 @@ export const logOut = () => .catch((err) => console.error(err)); } +export const passwordReset = async (form_data: + FormData) => +{ + try + { + const {data} = await Axios.post('passwordReset.php', form_data); + console.log('Api passwordReset'); + console.log(data); + return data; + } + catch(err) + { + return {success:0, message:'Password Reset Server Error!'}; + } +} + +export const wantNewPw = async ({email}:{email: string}) => +{ + try + { + const {data} = await Axios.post('wantNewPw.php', {email}); + console.log('Api wantNewPw'); + console.log(data); + return data; + } + catch(err) + { + return {success:0, message:'Password Reset Server Error!'}; + } +} + + // export const sleep = (ms: number) => // { // return new Promise((resolve) => setTimeout(resolve, ms));