From 817ce0ed5d19979c0ae5493ac495acf0f134a518 Mon Sep 17 00:00:00 2001 From: Hamza KHAIT Date: Wed, 20 Mar 2024 16:09:54 +0100 Subject: [PATCH] fix: fixing authentication url --- src/pages/home/HomeForm.tsx | 243 +----------------------------------- 1 file changed, 5 insertions(+), 238 deletions(-) diff --git a/src/pages/home/HomeForm.tsx b/src/pages/home/HomeForm.tsx index ed07d57..7f69c81 100644 --- a/src/pages/home/HomeForm.tsx +++ b/src/pages/home/HomeForm.tsx @@ -3,23 +3,13 @@ import { Input } from '@codegouvfr/react-dsfr/Input'; import { Button } from '@codegouvfr/react-dsfr/Button'; import { Badge } from '@codegouvfr/react-dsfr/Badge'; import styles from './Home.module.css'; +import AuthModal from './AuthModal'; import { Accordion } from '@codegouvfr/react-dsfr/Accordion'; import { Alert } from '@codegouvfr/react-dsfr/Alert'; import MuiAlert from '@mui/material/Alert'; import Snackbar, { SnackbarCloseReason } from '@mui/material/Snackbar'; import ShuffleIcon from '@mui/icons-material/Shuffle'; -import api from '../../axios/axios'; -import { redirect, useNavigate } from 'react-router-dom'; import { fr } from '@codegouvfr/react-dsfr'; -import { createModal } from '@codegouvfr/react-dsfr/Modal'; -import { Checkbox } from '@codegouvfr/react-dsfr/Checkbox'; -import CalendarModalComponent from './CalendarModal'; -import Authstyles from './AuthModal.module.css'; - -const modal = createModal({ - id: 'AgentConnect', - isOpenedByDefault: false, -}); interface AuthModalProps { roomName: string; @@ -39,17 +29,6 @@ function HomeForm(props: AuthModalProps) { const [message, setMessage] = useState(<>); const [messageType, setMessageType] = useState(''); const [open, setOpen] = useState(false); - const [msg, setMsg] = useState(''); - const [buttonMsg, setButtonMsg] = useState( - 'Recevoir le code de vérification par email' - ); - const [isCheked, setIsChecked] = useState(false); - - const copyLink = () => { - navigator.clipboard.writeText(window.location.href + props.roomName); - setOpen(true); - }; - const navigate = useNavigate(); const change = (e: string) => { verifyAndSetVAlue(e); @@ -170,110 +149,6 @@ function HomeForm(props: AuthModalProps) { setOpen(false); }; - function roomNameConstraintOk(roomName: string) { - /** - * Verify if the room name is valid - * @param {String} roomName The room name - * @return {Boolean} True if the room name is valid, false otherwise - */ - const regex = new RegExp( - '^(?=(?:[a-zA-Z0-9]*[a-zA-Z]))(?=(?:[a-zA-Z0-9]*[0-9]){3})[a-zA-Z0-9]{10,}$' - ); - return regex.test(roomName); - } - - useEffect(() => { - props.setIsWhitelisted(null); - const mail = localStorage.getItem('email'); - const checked1 = localStorage.getItem('checked'); - const checked = checked1 === 'true'; - if (checked) { - if (mail) { - props.setEmail(mail); - } - } else { - props.setEmail(''); - localStorage.setItem('email', ''); - } - setIsChecked(checked); - setMsg(null); - setButtonMsg('Recevoir le code de vérification par email'); - }, []); - - const agentConnect = (room: string) => { - fetch( - `${import.meta.env.VITE_BASE_URL}/auth/login_authorize?room=${room}`, - { - redirect: 'manual', - } - ).then(res => { - if (res.type === 'opaqueredirect') { - window.location.href = res.url; - } else { - // handle normally / pass on to next handler - window.location.href = res.url; - } - }); - }; - const onCheck = () => { - setIsChecked(!isCheked); - localStorage.setItem('checked', (!isCheked).toString()); - }; - - const mailchanger = (e: any) => { - props.setEmail(e.target.value); - localStorage.setItem('email', e.target.value); - }; - - const mailSender = (e: any) => { - props.sendEmail(e); - setButtonMsg('Email non reçu ? Cliquez ici pour recevoir un nouvel email'); - }; - - function handle(e: any) { - e.preventDefault(); - if (!props.roomName) { - const room = generateRoomName(); - props.setRoomName(room); - if (roomNameConstraintOk(room)) { - api.get('/feedback/whereami').then(res => { - if (res.data.toLowerCase() == 'internet') { - if (!props.authenticated) { - modal.open(); - } - if (props.authenticated) { - props.joinConference(room); - } - } - if (res.data.toLowerCase() !== 'internet') { - props.joinConference(room); - } - }); - } - } else if (roomNameConstraintOk(props.roomName)) { - api - .get('/roomExists/' + props.roomName) - .then(res => { - return navigate('/' + props.roomName); - }) - .catch(err => { - api.get('/feedback/whereami').then(res => { - if (res.data.toLowerCase() == 'internet') { - if (!props.authenticated) { - return modal.open(); - } - if (props.authenticated) { - return props.joinConference(props.roomName); - } - } - if (res.data.toLowerCase() !== 'internet') { - return props.joinConference(props.roomName); - } - }); - }); - } - } - const AlertMui = React.forwardRef(function Alert(props, ref) { return ( ); }); - const handleKeypress = (e: any) => { - //it triggers by pressing the enter key - if (e.code === 'Enter') { - handle(e); - } - }; const up = '+'; const down = '--'; @@ -302,7 +171,7 @@ function HomeForm(props: AuthModalProps) {

La WebConférence de l'État pour tous les agents publics

Audio, vidéo, chat, partage d'écran et de documents

-
+
change(e.target.value), - onKeyPress: e => handleKeypress(e), }} />
- {/* */} - <> - -

- - Nous avons besoin de vérifier votre identité afin de créer la - conférence {props.roomName}. - -

- -

- - - Qu'est ce que Agent Connect ? - - -

- - Ou saissez votre adresse email professionnelle: - - } - nativeInputProps={{ - 'aria-describedby': 'input3-desc-error', - 'aria-labelledby': 'input3-desc-error', - id: 'input3', - value: props.email, - onChange: e => mailchanger(e), - required: true, - }} - /> - onCheck(), - }, - }, - ]} - /> - - {msg} - {props.isWhitelisted === false ? ( -

- - votre adresse email n'est pas valide. Merci de saisir votre - adresse email professionelle. - -

- ) : null} - {props.isWhitelisted === true ? ( -

- Message envoyé. -

- ) : null} -
-
- -
- {props.buttons ? ( -
- - -
- ) : null} -
- +
- +

{message}

Actuellement, il y a 0 conférences et 0 participants. @@ -504,4 +271,4 @@ function generateRoomName() { Math.floor(Math.random() * 10) + Math.floor(Math.random() * 10) ); -} +} \ No newline at end of file