diff --git a/api/assets/utils/deleteFilesNameStartWith.js b/api/assets/utils/deleteFilesNameStartWith.js index b2940d6..fef91e0 100644 --- a/api/assets/utils/deleteFilesNameStartWith.js +++ b/api/assets/utils/deleteFilesNameStartWith.js @@ -9,7 +9,7 @@ function deleteFilesNameStartWith(pattern, dirPath = __dirname) { // Iterate through the found file names for (const name of fileNames) { // If file name matches the pattern - if (name.startsWith(pattern)) { + if (name.startsWith(pattern) && name !== 'default.png') { console.log(name) fs.unlinkSync(path.join(dirPath, name)); } diff --git a/api/controllers/users.js b/api/controllers/users.js index 04bba56..de0fd7f 100644 --- a/api/controllers/users.js +++ b/api/controllers/users.js @@ -19,14 +19,27 @@ const deleteFilesNameStartWith = require('../assets/utils/deleteFilesNameS async function handleEditUser(res, { name, email, biography, isPublicEmail }, userId, logoName) { const user = await Users.findOne({ where: { id: userId } }); user.name = name; - user.email = email; - user.biography = biography; + if (user.email !== email) { + const tempToken = uuid.v4(); + user.email = email; + user.isConfirmed = false; + user.tempToken = tempToken; + await transporter.sendMail({ + from: `"FunctionProject" <${EMAIL_INFO.auth.user}>`, + to: email, + subject: "FunctionProject - Confirmer l'email", + html: emailTemplate("Veuillez confirmer l'email", "Oui, je confirme.", `${HOST}/users/confirm-email/${tempToken}`, "Si vous avez reçu ce message par erreur, il suffit de le supprimer. Votre email ne serez pas confirmé si vous ne cliquez pas sur le lien de confirmation ci-dessus.") + }); + } + if (biography != undefined) { + user.biography = biography; + } user.isPublicEmail = isPublicEmail; if (logoName != undefined) { user.logo = `/images/users/${logoName}`; } await user.save(); - return res.status(200).json({ message: "Le profil a bien été modifié!" }); + return res.status(200).json({ id: user.id, name: user.name, email: user.email, biography: user.biography, logo: user.logo, isPublicEmail: user.isPublicEmail, isAdmin: user.isAdmin, createdAt: user.createdAt }); } exports.putUser = (req, res, next) => { @@ -115,7 +128,7 @@ exports.login = async (req, res, next) => { } const token = jwt.sign({ email: user.email, userId: user.id - }, JWT_SECRET, { expiresIn: '3h' }); + }, JWT_SECRET, { expiresIn: '6h' }); return res.status(200).json({ token, id: user.id, name: user.name, email: user.email, biography: user.biography, logo: user.logo, isPublicEmail: user.isPublicEmail, isAdmin: user.isAdmin, createdAt: user.createdAt }); } catch (error) { console.log(error); @@ -198,7 +211,7 @@ exports.getUserInfo = async (req, res, next) => { const { name } = req.params; try { const user = await Users.findOne({ - where: { name }, + where: { name, isConfirmed: true }, attributes: { exclude: ["updatedAt", "isAdmin", "isConfirmed", "password", "tempToken", "tempExpirationToken"] }, @@ -232,6 +245,7 @@ exports.getUserInfo = async (req, res, next) => { const userObject = { // Si Public Email ... (user.isPublicEmail) && { email: user.email }, + isPublicEmail: user.isPublicEmail, name: user.name, biography: user.biography, logo: user.logo, diff --git a/website/components/Modal.js b/website/components/Modal.js new file mode 100644 index 0000000..af29ab5 --- /dev/null +++ b/website/components/Modal.js @@ -0,0 +1,9 @@ +const Modal = (props) => ( +
Succès: Connexion réussi!
'); setLoginLoading(false); @@ -46,8 +45,14 @@ function UserContextProvider(props) { setIsAuth(false); } + const changeUserValue = (user) => { + cookies.remove('user'); + cookies.set('user', user); + setUser(user); + } + return ( -Succès: Votre compte a bien été confirmé, vous pouvez maintenant vous connectez!
} + {(router.query.isConfirmed !== undefined && messageLogin === "") &&Succès: Votre compte a bien été confirmé, vous pouvez maintenant vous connectez!
} + {(router.query.isSuccessEdit !== undefined && messageLogin === "") &&Succès: Votre profil a bien été modifié, vous pouvez maintenant vous connectez!
} { (loginLoading) ?Erreur: ${error.response.data.message}
`); + setIsLoading(false); + }); + } + } + return ((Vous devrez vous reconnecter après la sauvegarde)
Si vous changez votre adresse email, vous devrez la confirmer (vérifier vos emails).
{props.biography}
} {(props.email != undefined) &&Email : {props.email}
}Date de création : {publicationDate}
Posté sur la fonction - + {comment.function.title} le {date.format(new Date(comment.createdAt), 'DD/MM/YYYY à HH:mm', true)} diff --git a/website/pages/register.js b/website/pages/register.js index 70de711..e52127f 100644 --- a/website/pages/register.js +++ b/website/pages/register.js @@ -11,7 +11,7 @@ const Register = () => { const [message, setMessage] = useState(""); const [isLoading, setIsLoading] = useState(false); - const handleChange = () => { + const handleChange = (event) => { const inputStateNew = { ...inputState }; inputStateNew[event.target.name] = event.target.value; setInputState(inputStateNew); diff --git a/website/public/css/pages/profile.css b/website/public/css/pages/profile.css index 78ecd3a..9d205aa 100644 --- a/website/public/css/pages/profile.css +++ b/website/public/css/pages/profile.css @@ -22,4 +22,70 @@ } .Profile__comment { margin: 0 0 50px 0; +} +.Profile__Modal-top-container { + margin: 20px 0; +} +.custom-control { + display: flex; + justify-content: center; +} +.custom-control-input { + position: absolute; + z-index: -1; + opacity: 0; +} +.custom-control-label { + position: relative; + margin-bottom: 0; + vertical-align: top; +} +.custom-control-input:checked~.custom-control-label::before { + color: #fff; + border-color: #007bff; + background-color: #007bff; +} +.custom-switch .custom-control-label::before { + left: -2.25rem; + width: 1.75rem; + pointer-events: all; + border-radius: .5rem; +} +.custom-control-label::before { + position: absolute; + top: .25rem; + left: -1.5rem; + display: block; + width: 1rem; + height: 1rem; + pointer-events: none; + content: ""; + background-color: #fff; + border: #adb5bd solid 1px; +} +.custom-switch .custom-control-input:checked~.custom-control-label::after { + background-color: #fff; + -webkit-transform: translateX(.75rem); + transform: translateX(.75rem); +} +.custom-switch .custom-control-label::after { + top: calc(.25rem + 2px); + left: calc(-2.25rem + 2px); + width: calc(1rem - 4px); + height: calc(1rem - 4px); + background-color: #adb5bd; + border-radius: .5rem; + transition: background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out,-webkit-transform .15s ease-in-out; + transition: transform .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out; + transition: transform .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out,-webkit-transform .15s ease-in-out; +} +.custom-control-label::after { + position: absolute; + top: .25rem; + left: -1.5rem; + display: block; + width: 1rem; + height: 1rem; + content: ""; + background: no-repeat 50%/50% 50%; } \ No newline at end of file diff --git a/website/utils/redirect.js b/website/utils/redirect.js index e7bea71..456a8c4 100644 --- a/website/utils/redirect.js +++ b/website/utils/redirect.js @@ -1,9 +1,9 @@ function redirect(ctx, path) { - if (ctx.res) { + if (ctx.res != undefined) { ctx.res.writeHead(302, { Location: path }); ctx.res.end(); } else { - document.location.pathname = path; + document.location.href = path; } }