diff --git a/README.md b/README.md index 5b89ad8..72a1067 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [![Quality Gate Status](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=jtt_crm&metric=alert_status&token=4e704a73064f9dd9388eb33b182fcfe6f8aed2a4)](https://codefirst.iut.uca.fr/sonar/dashboard?id=jtt_crm) [![Code Smells](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=jtt_crm&metric=code_smells&token=4e704a73064f9dd9388eb33b182fcfe6f8aed2a4)](https://codefirst.iut.uca.fr/sonar/dashboard?id=jtt_crm) [![Lines of Code](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=jtt_crm&metric=ncloc&token=4e704a73064f9dd9388eb33b182fcfe6f8aed2a4)](https://codefirst.iut.uca.fr/sonar/dashboard?id=jtt_crm) -[![Quality Gate Status](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=jtt_crm&metric=alert_status&token=4e704a73064f9dd9388eb33b182fcfe6f8aed2a4)](https://codefirst.iut.uca.fr/sonar/dashboard?id=jtt_crm) [![Bugs](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=jtt_crm&metric=bugs&token=4e704a73064f9dd9388eb33b182fcfe6f8aed2a4)](https://codefirst.iut.uca.fr/sonar/dashboard?id=jtt_crm) diff --git a/package-lock.json b/package-lock.json index a85a884..6583b16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "react-big-calendar": "^1.5.0", "react-datepicker": "^4.8.0", "react-dom": "^18.2.0", + "react-loading": "^2.0.3", "react-router-dom": "^6.4.2", "react-scripts": "^5.0.1", "sass": "^1.55.0", @@ -14941,6 +14942,15 @@ "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz", "integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==" }, + "node_modules/react-loading": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/react-loading/-/react-loading-2.0.3.tgz", + "integrity": "sha512-Vdqy79zq+bpeWJqC+xjltUjuGApyoItPgL0vgVfcJHhqwU7bAMKzysfGW/ADu6i0z0JiOCRJjo+IkFNkRNbA3A==", + "peerDependencies": { + "prop-types": "^15.6.0", + "react": ">=0.14.0" + } + }, "node_modules/react-onclickoutside": { "version": "6.12.2", "resolved": "https://registry.npmjs.org/react-onclickoutside/-/react-onclickoutside-6.12.2.tgz", @@ -28394,6 +28404,12 @@ "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz", "integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==" }, + "react-loading": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/react-loading/-/react-loading-2.0.3.tgz", + "integrity": "sha512-Vdqy79zq+bpeWJqC+xjltUjuGApyoItPgL0vgVfcJHhqwU7bAMKzysfGW/ADu6i0z0JiOCRJjo+IkFNkRNbA3A==", + "requires": {} + }, "react-onclickoutside": { "version": "6.12.2", "resolved": "https://registry.npmjs.org/react-onclickoutside/-/react-onclickoutside-6.12.2.tgz", diff --git a/package.json b/package.json index 468a707..10f2b72 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "react-big-calendar": "^1.5.0", "react-datepicker": "^4.8.0", "react-dom": "^18.2.0", + "react-loading": "^2.0.3", "react-router-dom": "^6.4.2", "react-scripts": "^5.0.1", "sass": "^1.55.0", diff --git a/server-api/api.js b/server-api/api.js index a936c54..c95ec21 100644 --- a/server-api/api.js +++ b/server-api/api.js @@ -86,6 +86,20 @@ app.get('/User/Auth/:login/:pwd', (req, res) => { }); }); +app.get('/User/Auth/Password/:id/:pwd', (req, res) => { + + const id = req.params.id; + const pwd = req.params.pwd; + let sql = 'SELECT login FROM users WHERE iduser = ? AND password = ?'; + + db.query(sql, [id, pwd], (err, result) => { + if (err) throw err; + + console.log(result); + res.send(result); + }); +}); + app.get('/User/Role/:login', (req, res) => { const login = req.params.login; @@ -155,11 +169,38 @@ app.put('/User/Update/:id', (req, res) => { const id = req.params.id; let form = req.body; - const sql = `UPDATE users SET lastname = ?, firstname = ?, idrole = ?, login = ?, password = ?, phone = ?, mail = ? WHERE (iduser = ?)`; - db.query(sql, [form.lastname, form.firstname, form.idrole, form.login, form.password, form.phone, form.mail, id], (err, result) => { + const sql = `UPDATE users SET lastname = ?, firstname = ?, idrole = ?, login = ?, phone = ?, mail = ? WHERE (iduser = ?)`; + db.query(sql, [form.lastname, form.firstname, form.idrole, form.login, form.phone, form.mail, id], (err, result) => { + if (err) throw err; + console.log(result); + res.send('Post update...'); + }); +}); + +app.put('/User/Update/Password/:id', (req, res) => { + + const id = req.params.id; + let form = req.body; + + console.log(form.newPassword); + + const sql = `UPDATE users SET password = ? WHERE (iduser = ?)`; + db.query(sql, [form.newPassword, id], (err, result) => { + if (err) throw err; + console.log(result); + res.send('Post password update...'); + }); +}); + +app.delete('/User/Delete/:id', (req, res) => { + + const id = req.params.id; + + const sql = `DELETE FROM users WHERE (iduser = ?)`; + db.query(sql, [id], (err, result) => { if (err) throw err; console.log(result); - res.send('Post added...'); + res.send('Post delete...'); }); }); diff --git a/src/App.js b/src/App.js index fe047fb..f2910b2 100644 --- a/src/App.js +++ b/src/App.js @@ -12,29 +12,35 @@ import Admin_create from './pages/Admin_create'; import Calendrier from './pages/Calendrier'; import Repertoire from './pages/Repertoire'; import Parametres from './pages/Parametres'; +import Chargement from './pages/Chargement'; +import { Component } from 'fullcalendar'; +import RestartPassword from './pages/RestartPassword'; + const App = () => { - return ( - - - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - ); + + + return ( + + + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + + ); } diff --git a/src/components/NavigationAdmin.js b/src/components/NavigationAdmin.js index 301cc1b..19db335 100644 --- a/src/components/NavigationAdmin.js +++ b/src/components/NavigationAdmin.js @@ -16,7 +16,7 @@ const NavigationAdmin = (props) => { - + diff --git a/src/pages/Admin_create.js b/src/pages/Admin_create.js index da1c961..b9d2528 100644 --- a/src/pages/Admin_create.js +++ b/src/pages/Admin_create.js @@ -36,7 +36,6 @@ function Admin_create() { const formData = new FormData(event.currentTarget); const values = Object.fromEntries(formData.entries()); - {/* Verif value login exist déja */} console.log(values.firstname); api.get('/User/Exist/'+ values.login).then((response) => { const login = response.data; diff --git a/src/pages/Admin_list.js b/src/pages/Admin_list.js index 63c2acc..67ff739 100644 --- a/src/pages/Admin_list.js +++ b/src/pages/Admin_list.js @@ -33,7 +33,6 @@ function Admin_list() { return ( - {/* Create a page to delete an user in the admin page*/}

Admin

@@ -45,28 +44,6 @@ function Admin_list() {
- {/* -
- - -
-

- Dupont Jacques -

-

- Carreau Alexis -

-
- - -
- - -
- -
-
- */} diff --git a/src/pages/Admin_modif.js b/src/pages/Admin_modif.js index 5ef1fa3..d04aeb7 100644 --- a/src/pages/Admin_modif.js +++ b/src/pages/Admin_modif.js @@ -2,10 +2,11 @@ import axios from 'axios' import React, { useState, useEffect } from 'react'; import NavigationAdmin from '../components/NavigationAdmin.js'; import Admin from './Admin_create.js'; -import { useLocation } from "react-router-dom" +import { useLocation } from "react-router-dom"; import Select, { SelectChangeEvent } from '@mui/material/Select'; import MenuItem from '@mui/material/MenuItem'; import { NavLink } from 'react-router-dom'; +import { useNavigate } from "react-router-dom"; const api = axios.create({ baseURL: 'http://localhost:8080' @@ -24,6 +25,8 @@ function Admin_modif() { const [mail, setMail] = useState(); const [login, setLogin] = useState(); + const navigate = useNavigate(); + useEffect(() =>{ api.get('/Role/All/').then((response) => { setRoles(response.data); @@ -38,9 +41,9 @@ function Admin_modif() { setLastName(response.data[0].lastname); setFirstName(response.data[0].firstname); + setLogin(response.data[0].login); setPhone(response.data[0].phone); setMail(response.data[0].mail); - setLogin(response.data[0].login); }); }, []); @@ -81,12 +84,13 @@ function Admin_modif() { api.put(apiString, values).then((response) => { console.log(response.data); }); + + navigate("/Admin_list"); } return (
- {/* Create a admin page */}

Admin

Modification d'utilisateur

@@ -97,15 +101,16 @@ function Admin_modif() {

Nom :

Prénom :

+

Login :

Rôle :

-

Identifiant :

-

Identifiant :

-

Mot de passe :

+

Téléphone :

+

Mail :

+ -
- -
+ Réinitialiser le mot de passe
diff --git a/src/pages/Admin_supp.js b/src/pages/Admin_supp.js index c652765..6a1db1d 100644 --- a/src/pages/Admin_supp.js +++ b/src/pages/Admin_supp.js @@ -1,44 +1,52 @@ import React, { useState, useEffect } from 'react'; import axios from 'axios' import NavigationAdmin from '../components/NavigationAdmin.js'; +import { NavLink, useLocation } from "react-router-dom"; import { TableContainer,Table,TableHead,TableBody,TableRow,TableCell } from '@mui/material'; import { Paper } from '@mui/material'; +import { useNavigate } from "react-router-dom"; const api = axios.create({ baseURL: 'http://localhost:8080' }) -const Admin_supp = () => { +function Admin_supp(){ - const [users, setUsers] = useState([]); - const [selectedIdUser, setSelectedIdUser] = useState(); + const location = useLocation(); + const { iduser } = location.state; + + const [selectedUser, setSelectedUsers] = useState([]); + + const navigate = useNavigate(); useEffect(() =>{ - api.get('/User/All/').then((response) => { - setUsers(response.data); - setSelectedIdUser(response.data[0].iduser); + const apiString = '/User/Id/' + iduser; + api.get(apiString).then((response) => { + console.log(response.data[0]); + setSelectedUsers(response.data[0]); }); }, []); - const handleClick = (event, iduser) => { - setSelectedIdUser(iduser); - }; + function checkDelete(event){ + + event.preventDefault(); + + const apiString = '/User/Delete/' + iduser; + api.delete(apiString).then((response) => { + console.log(response.data); + }); + + navigate("/Admin_list"); + } return (
- {/* Create a page to delete an user in the admin page*/}

Admin

Supression d'utilisateur

-
- - - - -
@@ -48,29 +56,24 @@ const Admin_supp = () => { Identifiant Téléphone Email - Rôle - {users.map((user) => ( - handleClick(event, user.iduser)} - selected={user.iduser === selectedIdUser} - > - {user.lastname} - {user.firstname} - {user.login} - {user.phone} - {user.mail} - {user.name} - - ))} + + {selectedUser.lastname} + {selectedUser.firstname} + {selectedUser.login} + {selectedUser.phone} + {selectedUser.mail} +
+
+ + Retour +
); diff --git a/src/pages/Chargement.js b/src/pages/Chargement.js new file mode 100644 index 0000000..b8556dc --- /dev/null +++ b/src/pages/Chargement.js @@ -0,0 +1,16 @@ +import React from 'react'; +import ReactLoading from 'react-loading'; + + + +const Chargement = () => { + + return( +
+ + +
+ ); +} + +export default Chargement; \ No newline at end of file diff --git a/src/pages/Compte.js b/src/pages/Compte.js index d69edc4..c9ac993 100644 --- a/src/pages/Compte.js +++ b/src/pages/Compte.js @@ -1,13 +1,18 @@ import { Component } from '@fullcalendar/core'; -import React, { useState } from 'react'; +import userEvent from '@testing-library/user-event'; +import React, { useEffect, useState } from 'react'; import NavigationDashboard from '../components/NavigationDashboard'; import img1 from '../img/logo_personEntouré.svg'; +import axios from 'axios' - +const api = axios.create({ + baseURL: 'http://localhost:8080' + }) function Compte() { - const [theme, setTheme] = useState("light"); + const [theme, setTheme] = useState("light"); + const [modification, setModification] = useState(false); if (localStorage.getItem('theme') && localStorage.getItem("theme") !== '' && localStorage.getItem("theme") !== theme) { setTheme(localStorage.getItem("theme")) } @@ -18,6 +23,11 @@ function Compte() { setFile(URL.createObjectURL(e.target.files[0])); } + const modificationHandler = () => { + setModification((modification) => !modification) + console.log(modification) + } + return ( @@ -58,10 +68,11 @@ function Compte() {

Nom Complet :

+

{}

Mateo Centeno

- +
diff --git a/src/pages/Connexion.js b/src/pages/Connexion.js index 343fdcd..8ce50c5 100644 --- a/src/pages/Connexion.js +++ b/src/pages/Connexion.js @@ -1,9 +1,10 @@ import axios from 'axios' -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import CryptoJS from 'crypto-js'; import Admin from './Admin_create.js' import Dashboard from './Dashboard.js' import Admin_list from './Admin_list.js'; +import Chargement from './Chargement.js'; const api = axios.create({ baseURL: 'http://localhost:8080' @@ -58,6 +59,15 @@ function Connexion() { }); } + const [loader, setLoader] = useState(true); + + useEffect(() => { + setTimeout(() => { + setLoader(false); + }, 3000) + }, []) + + if (auth === "Succeed") { const apiString = '/User/role/' + login; api.get(apiString).then((response) => { @@ -77,7 +87,9 @@ function Connexion() { return (); } else { - return ( + return loader ?( + + ) : (
diff --git a/src/pages/RestartPassword.js b/src/pages/RestartPassword.js new file mode 100644 index 0000000..0fac4bf --- /dev/null +++ b/src/pages/RestartPassword.js @@ -0,0 +1,105 @@ +import axios from 'axios' +import React, { useState, useEffect } from 'react'; +import NavigationAdmin from '../components/NavigationAdmin.js'; +import Admin from './Admin_create.js'; +import { useLocation } from "react-router-dom"; +import Select, { SelectChangeEvent } from '@mui/material/Select'; +import MenuItem from '@mui/material/MenuItem'; +import { NavLink } from 'react-router-dom'; +import CryptoJS from 'crypto-js'; +import { useNavigate } from "react-router-dom"; + + +const api = axios.create({ + baseURL: 'http://localhost:8080' + }) + +function RestartPassword() { + const location = useLocation(); + const { iduser } = location.state; + console.log(iduser); + + const [password, setPassword] = useState(""); + const [confPassword, setConfPassword] = useState(""); + const [newPassword, setNewPassword] = useState(""); + + const navigate = useNavigate(); + + function handleChangePassword(event){ + setPassword(event.target.value); + }; + + function handleChangeConfPassword(event){ + setConfPassword(event.target.value); + }; + + function handleChangeNewPassword(event){ + setNewPassword(event.target.value); + }; + + function checkRestartPassword(event){ + + const formData = new FormData(event.currentTarget); + const values = Object.fromEntries(formData.entries()); + + event.preventDefault(); + + if(password === confPassword) + { + const apiString = '/User/Auth/Password/' + iduser + "/" + CryptoJS.SHA256(confPassword).toString(CryptoJS.enc.Hex); + api.get(apiString).then((response) => { + const login = response.data; + if (login.length > 0){ + console.log(values.newPassword); + + values.newPassword = CryptoJS.SHA256(newPassword).toString(CryptoJS.enc.Hex); + + const apiStringUpdate = '/User/Update/Password/' + iduser; + api.put(apiStringUpdate, values).then((response) => { + console.log(response.data); + }); + + navigate("/Admin_list"); + } + else{ + console.log("trt"); + } + }); + } + } + + return ( +
+ + {/* Create a admin page */} +
+

Admin

+

Modification d'utilisateur

+
+ + + +
+

Mot de passe :

+

Confirmation mot de passe :

+

Nouveau mot de passe :

+
+ + + + + + +
+
+ + Retour +
+ +
+
+
+ ); +}; + +export default RestartPassword; \ No newline at end of file diff --git a/src/styles/components/_chargement.scss b/src/styles/components/_chargement.scss new file mode 100644 index 0000000..64dc2f2 --- /dev/null +++ b/src/styles/components/_chargement.scss @@ -0,0 +1,12 @@ +.chargement { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; +} + +.logo{ + height: 200px; + width:200px; +} \ No newline at end of file diff --git a/src/styles/index.scss b/src/styles/index.scss index 625c18a..ac6a812 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -6,4 +6,5 @@ @import "./components/analyse"; @import "./components/calendrier"; @import "./components/parametre"; -@import "./components/repertoire" \ No newline at end of file +@import "./components/repertoire"; +@import "./components/chargement" \ No newline at end of file