-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hashage du password, register et début login
- Loading branch information
Showing
21 changed files
with
362 additions
and
51 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const argon2 = require("argon2"); | ||
|
||
const hashingOptions = { | ||
type: argon2.argon2id, | ||
memoryCost: 19 * 2 ** 10, | ||
timeCost: 2, | ||
parallelism: 1, | ||
}; | ||
|
||
const hashPassword = async (req, res, next) => { | ||
try { | ||
const { password } = req.body; | ||
const hashedPassword = await argon2.hash(password, hashingOptions); | ||
req.body.hashedPassword = hashedPassword; | ||
// pour supprimer le password en clair une fois celui-ci hashé | ||
delete req.body.password; | ||
console.info("HASHED PASSWORD", req.body); | ||
next(); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
module.exports = { hashPassword }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import axios from "axios"; | ||
import PropTypes from "prop-types"; | ||
|
||
export default function Book({ book, refreshPage }) { | ||
const deleteBook = () => { | ||
axios | ||
.delete(`${import.meta.env.VITE_BACKEND_URL}/api/books/${book.id}`) | ||
.then(() => refreshPage()) | ||
.catch((error) => console.error(error)); | ||
}; | ||
|
||
return ( | ||
<article> | ||
<h3>{book.title}</h3> | ||
<p>{book.summary}</p> | ||
<button type="button" onClick={deleteBook}> | ||
Supprimer le livre de la liste | ||
</button> | ||
</article> | ||
); | ||
} | ||
|
||
Book.propTypes = { | ||
book: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
title: PropTypes.string.isRequired, | ||
summary: PropTypes.string.isRequired, | ||
}).isRequired, | ||
refreshPage: PropTypes.func.isRequired, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// import { useContext } from "react"; | ||
import { Link } from "react-router-dom"; | ||
// import UserContext from "../services/UserContext"; | ||
|
||
export default function Navbar() { | ||
// const { user } = useContext(UserContext); | ||
|
||
// const isConnected = user.id && user.id !== "null"; | ||
|
||
// console.info("isConnected", isConnected); | ||
|
||
return ( | ||
<nav> | ||
<Link to="/">Accueil</Link> | ||
<Link to="/books">Livres</Link> | ||
<Link to="/create">Créer une fiche </Link> | ||
<Link to="/register">Créer un compte</Link> | ||
{/* <Link to="/login">Se connecter</Link> */} | ||
</nav> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useLoaderData, useNavigate } from "react-router-dom"; | ||
import Book from "../components/Books"; | ||
|
||
export default function Books() { | ||
const books = useLoaderData(); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const refreshPage = () => { | ||
navigate("/books", { replace: true }); | ||
}; | ||
|
||
return ( | ||
<> | ||
<h1>Liste des livres lus :</h1> | ||
{books.map((book) => ( | ||
<Book key={book.id} book={book} refreshPage={refreshPage} /> | ||
))} | ||
</> | ||
); | ||
} |
Oops, something went wrong.