Skip to content

Commit

Permalink
Merge pull request #123 from WildCodeSchool-2023-09/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Alexis-NM authored Feb 6, 2024
2 parents 0cde49c + 0c84e4a commit dbc7b5f
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 109 deletions.
6 changes: 5 additions & 1 deletion backend/src/models/CaptureManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ class CaptureManager extends AbstractManager {
}

async readAll() {
const [rows] = await this.database.query(`SELECT * FROM ${this.table}`);
const [rows] = await this.database.query(`
SELECT c.id, c.user_id, c.artwork_id, c.capture, a.picture AS artwork_url
FROM ${this.table} c
LEFT JOIN artworks a ON c.artwork_id = a.id
`);
return rows;
}

Expand Down
8 changes: 4 additions & 4 deletions backend/src/services/validateUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const userSchema = Joi.object({
pseudo: Joi.string().max(80).required(),
email: Joi.string().email().max(255).required(),
password: Joi.string().max(255).required(),
avatar: Joi.string().max(255).required(),
bio: Joi.string().max(255).required(),
ranking: Joi.number().integer().required(),
points: Joi.number().integer().required(),
avatar: Joi.string().max(255),
bio: Joi.string().max(255),
ranking: Joi.number().integer(),
points: Joi.number().integer(),
is_administrator: Joi.boolean().required(),
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/CaptureAdmin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function CaptureAdmin() {
<img
alt="Street Art"
className="original-img-grid"
src={artwork.picture}
src={artwork.artwork_url}
/>
<p className="original-work-grid">Oeuvre Originale</p>
</div>
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ function Login() {
<h2>Connexion</h2>
</div>
</div>
<p>Tu n'as pas encore de compte ? Créer le maintenant !</p>
<p>
Tu n'as pas encore de compte ?{" "}
<Link to="/inscription ">Créer le maintenant ! </Link>
</p>
</header>
<main className="content">
<form>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Logout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Logout() {
<h2 className={userMode()}>
Etes-vous sûr de vouloir vous déconnecter ?
</h2>
<div className="footer-modal">
<div>
<button
type="button"
className={userMode()}
Expand Down
103 changes: 79 additions & 24 deletions frontend/src/components/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,121 +1,176 @@
import { useState } from "react";
import { useState, useEffect } from "react";
import { useNavigate, Link } from "react-router-dom";
import axios from "axios";
import "../styles/modals.scss";
import CrossButton from "../assets/picto/yellow/cross_yell.svg";

function Register() {
const [registerInfo, setRegisterInfo] = useState({
firstname: "",
lastname: "",
psuedo: "",
pseudo: "",
email: "",
password: "",
confirmPassword: "",
is_administrator: false,
bio: "",
});
const [errMessage, setErrMessage] = useState("");
const [acceptedRGPD, setAcceptedRGPD] = useState(false);

const navigate = useNavigate();

const handleChangeRegister = (event) => {
const { name, value } = event.target;
setRegisterInfo({ ...registerInfo, [name]: value });
const { name, value, type, checked } = event.target;
const newValue = type === "checkbox" ? checked : value;
setRegisterInfo({ ...registerInfo, [name]: newValue });
};

const handleRGPDChange = (e) => {
setAcceptedRGPD(e.target.checked);
};

useEffect(() => {
setErrMessage("");
}, [registerInfo, acceptedRGPD]);

const handleRegister = async (event) => {
event.preventDefault();
// créer les fonctions pour vérifier que tous les input sont remplis + regex
// const { firstname, password } = registerInfo;
// créer les fonctions pour vérifier regex
const { firstname, lastname, pseudo, password, email } = registerInfo;
console.info(registerInfo);
if (
firstname === "" ||
lastname === "" ||
pseudo === "" ||
password === "" ||
email === ""
) {
setErrMessage("Merci de remplir tous les champs");
return;
}

// if (firstname === "" || password === "") {
// return;
// }
if (!acceptedRGPD) {
setErrMessage("Merci d'accepter les conditions d'utilisation");
return;
}

setErrMessage("");
try {
const resregister = await axios.post(
`${import.meta.env.VITE_BACKEND_URL}/register`, // créer la route dans le back....
`${import.meta.env.VITE_BACKEND_URL}/api/users`,
registerInfo
);

if (resregister.status === 201) {
navigate("/login");
navigate("/connexion");
}
} catch (error) {
console.error(error);
}
};

return (
<container className="backdrop">
<section className="modal">
<section className="backdrop">
<section className="modal-register">
<header>
<div>
<Link to="/" className="img-modal">
{/* <Link to="/" className="img-modal">
<img src={CrossButton} alt="close-window" />
</Link>
</Link> */}
<div>
<h2>Inscription</h2>
</div>
</div>
</header>
<main className="content">
<form>
<label htmlFor="firstname">
Prénom <span className="yell">*</span>
</label>
<input
type="text"
name="firstname"
placeholder="Prénom"
value={registerInfo.firstname}
onChange={handleChangeRegister}
/>
<label htmlFor="lastname">
Nom <span className="yell">*</span>
</label>
<input
type="text"
name="lastname"
placeholder="Nom"
value={registerInfo.lastname}
onChange={handleChangeRegister}
/>
<label htmlFor="pseudo">
Pseudo <span className="yell">*</span>
</label>
<input
type="text"
name="pseudo"
placeholder="Pseudo"
value={registerInfo.pseudo}
onChange={handleChangeRegister}
/>
<label htmlFor="email">
Adresse email <span className="yell">*</span>
</label>
<input
type="text"
name="email"
placeholder="[email protected]"
value={registerInfo.email}
onChange={handleChangeRegister}
/>
<label htmlFor="password">
Mot de passe <span className="yell">*</span>
</label>
<input
id="password"
type="text"
type="password"
name="password"
placeholder="Mot de passe"
value={registerInfo.password}
onChange={handleChangeRegister}
/>
<input
id="password-repeat"

<label htmlFor="bio">Biographie</label>
<textarea
id="bio"
type="text"
name="password-repeat"
placeholder="Répète ton mot de passe"
name="bio"
placeholder="Décrivez-vous et dites-nous pourquoi vous serez un excellent chasseur"
value={registerInfo.passwordRepeat}
onChange={handleChangeRegister}
/>
</form>
</main>
<footer className="footer-modal">
<p className="err-msg">{errMessage}</p>
<p className="checkbox-RGPD">
<input type="checkbox" name="RGPD-check" value="" /> J'accepte les{" "}
<input
type="checkbox"
name="rgpdCheck"
checked={registerInfo.rgpdCheck}
id="rgpdCheck"
onChange={handleRGPDChange}
/>{" "}
J'accepte les{" "}
<Link to="/RGPD">conditions générales d'utilisation.</Link>
</p>
<button type="button" onClick={handleRegister}>
S'inscrire
</button>
<p>
J'ai déjà un compte :{" "}
<Link className="text-link" to="/connexion">
connexion
</Link>{" "}
</p>
</footer>
</section>
</container>
</section>
);
}
export default Register;
Loading

0 comments on commit dbc7b5f

Please sign in to comment.