Skip to content
Snippets Groups Projects
Commit 8e662d51 authored by AdrianBeilharz's avatar AdrianBeilharz
Browse files

change password field, error message on wrong credentials

parent bbce5c30
No related branches found
No related tags found
No related merge requests found
import React, { useState } from 'react'; import React, { useState } from 'react';
import {Row, Col, Button, Form,} from 'react-bootstrap'; import {Col, Button, Form,} from 'react-bootstrap';
import { useForm } from "react-hook-form"; import ApothekeRegisterModal from '../../modals/ApothekeRegisterModal';
import ApothekeRegisterModal from '../../modals/ApothekeRegisterModal'; import { useSnackbar } from 'notistack';
import './Startseite.scss' import './Startseite.scss'
function Login(props) { function Login(props) {
const [neuesApoRegisterModal, setNeuesApoRegisterModal] = useState(false); const [neuesApoRegisterModal, setNeuesApoRegisterModal] = useState(false);
const {handleSubmit} = useForm(); const { enqueueSnackbar } = useSnackbar();
const [user, setUser] = useState({username:'', password:''});
const login = async event => {
const login = async event => { event.preventDefault();
const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/login`, { let {username, password} = event.target;
method: 'POST', let body = {username: username.value, password: password.value};
headers: { const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/login`, {
'Content-Type': 'application/json' method: 'POST',
}, headers: {
body: JSON.stringify({ 'Content-Type': 'application/json'
username: user.username, },
password: user.password body: JSON.stringify(body)
}) }).catch((err) => {
}).catch((err) => { //SHOW ERROR
//SHOW ERROR console.log(err);
console.log(err); });
});
if(response && response.status === 200){
if(response && response.status === 200){ const data = await response.json();
const data = await response.json(); window.sessionStorage.setItem("edbapo-jwt", data.jwt)
window.sessionStorage.setItem("edbapo-jwt", data.jwt) props.history.push(`/apotheke/${data.apothekeId}`);
props.history.push(`/apotheke/${data.apothekeId}`); } else {
} enqueueSnackbar("Nutzername oder Passwort ist Falsch", {variant: "error", autoHideDuration: 3000, anchorOrigin: {vertical: 'bottom', horizontal: 'left'}});
} }
}
return (
<div className="login"> return (
<b style={{fontSize:'20pt'}}>Login:</b> <div className="login">
<Form onSubmit={handleSubmit(login)} > <b style={{fontSize:'20pt'}}>Login:</b>
<Form.Row> <Form onSubmit={login} >
<Col> <Form.Row>
<Form.Control onChange={e => setUser({...user, username: e.target.value})} placeholder="Benutzername" /> <Col>
<Form.Control onChange={e => setUser({...user, password: e.target.value})} placeholder="Passwort" /> <Form.Control name="username" placeholder="Benutzername" required />
<Button variant="primary" type="submit">Login</Button> <Form.Control name="password" placeholder="Passwort" type="password" required />
<Button variant="primary" show={neuesApoRegisterModal} onClick={() => setNeuesApoRegisterModal(true)}>Neue Apotheke registrieren</Button> <Button variant="primary" type="submit">Login</Button>
<ApothekeRegisterModal <Button variant="primary" show={neuesApoRegisterModal} onClick={() => setNeuesApoRegisterModal(true)}>Neue Apotheke registrieren</Button>
show={neuesApoRegisterModal} <ApothekeRegisterModal
{...props} show={neuesApoRegisterModal}
onHide={() => setNeuesApoRegisterModal(false)} ></ApothekeRegisterModal> {...props}
</Col> onHide={() => setNeuesApoRegisterModal(false)} ></ApothekeRegisterModal>
</Form.Row> </Col>
</Form> </Form.Row>
</div> </Form>
) </div>
} )
export default Login; }
\ No newline at end of file export default Login;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment