Skip to content
Snippets Groups Projects
Commit 12e86e46 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Merge branch 'api-login' into 'dev'

Api login

See merge request !18
parents 6c178b49 c5bafc5a
No related branches found
No related tags found
2 merge requests!18Api login,!13Basic form api and implement cookie entrypoint
Pipeline #11652 failed
...@@ -138,4 +138,5 @@ npm-debug.log* ...@@ -138,4 +138,5 @@ npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
yarn.lock yarn.lock
.docz/ .docz/
\ No newline at end of file ._.DS_Store
\ No newline at end of file
...@@ -2,13 +2,14 @@ import React, { FC } from 'react'; ...@@ -2,13 +2,14 @@ import React, { FC } from 'react';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'; import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { HomePage } from './components/HomePage/HomePage'; import { HomePage } from './components/HomePage/HomePage';
import { AuthUser } from './components/AuthUser/AuthUser'; import { AuthUser } from './components/AuthUser/AuthUser';
import { LandingPage } from './components/LandingPage/LandingPage';
export const App: FC = () => ( export const App: FC = () => (
<Router> <Router>
<div data-testid="App"> <div data-testid="App">
<Switch> <Switch>
<Route path="/auth" component={AuthUser} /> <Route path="/auth" component={AuthUser} />
<Route exact path="/" component={HomePage} /> <Route exact path="/" component={LandingPage} />
</Switch> </Switch>
</div> </div>
</Router> </Router>
......
...@@ -7,7 +7,9 @@ export const AuthUser: FC = () => { ...@@ -7,7 +7,9 @@ export const AuthUser: FC = () => {
useEffect(() => { useEffect(() => {
axios axios
.get('api/web/csrf') .get('api/web/csrf')
.then((response) => console.log(response)) .then((response) =>
sessionStorage.setItem('CSRF_TOKEN', response.data.token),
)
.catch((error) => console.log(error)); .catch((error) => console.log(error));
}, []); }, []);
return ( return (
......
...@@ -6,10 +6,12 @@ type Props = { ...@@ -6,10 +6,12 @@ type Props = {
label: string; label: string;
error: boolean; error: boolean;
errorMessage: string; errorMessage: string;
value: string;
onChange: any;
}; };
export const InputField: FC<Props> = (props: Props) => { export const InputField: FC<Props> = (props: Props) => {
const { id, label, error, errorMessage } = props; const { id, label, error, errorMessage, onChange, value } = props;
return ( return (
<TextField <TextField
variant="outlined" variant="outlined"
...@@ -19,6 +21,8 @@ export const InputField: FC<Props> = (props: Props) => { ...@@ -19,6 +21,8 @@ export const InputField: FC<Props> = (props: Props) => {
id={id} id={id}
label={label} label={label}
name={id} name={id}
onChange={onChange}
value={value}
autoComplete={id} autoComplete={id}
autoFocus autoFocus
error={error} error={error}
......
import React, { FC } from 'react'; import React, { FC } from 'react';
import axios from 'axios';
import { useForm, Controller, appendErrors } from 'react-hook-form'; import { useForm, Controller, appendErrors } from 'react-hook-form';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'; import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
...@@ -40,7 +41,17 @@ export const SignInForm: FC = () => { ...@@ -40,7 +41,17 @@ export const SignInForm: FC = () => {
}); });
const onSubmit: any = (values: FormData) => { const onSubmit: any = (values: FormData) => {
alert(JSON.stringify(values)); axios
.post('/api/web/login', {
values,
token: sessionStorage.getItem('CSRF_TOKEN'),
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
}; };
const intl = useIntl(); const intl = useIntl();
const classes = useStyles(); const classes = useStyles();
...@@ -63,11 +74,13 @@ export const SignInForm: FC = () => { ...@@ -63,11 +74,13 @@ export const SignInForm: FC = () => {
message: intl.formatMessage({ id: 'email' }), message: intl.formatMessage({ id: 'email' }),
}, },
}} }}
render={() => ( render={({ onChange, value }) => (
<InputField <InputField
id="email" id="email"
value={value}
onChange={onChange}
label={intl.formatMessage({ id: 'email' })} label={intl.formatMessage({ id: 'email' })}
error={Boolean(errors.email)} error={!!errors.email}
errorMessage={intl.formatMessage({ id: 'error' })} errorMessage={intl.formatMessage({ id: 'error' })}
/> />
)} )}
...@@ -76,17 +89,18 @@ export const SignInForm: FC = () => { ...@@ -76,17 +89,18 @@ export const SignInForm: FC = () => {
<Controller <Controller
name="password" name="password"
control={control} control={control}
defaultValues
rules={{ rules={{
minLength: 8, minLength: 8,
maxLength: 60, maxLength: 60,
required: { value: true, message: 'You must enter your name' }, required: { value: true, message: 'You must enter your name' },
}} }}
render={() => ( render={({ onChange, value }) => (
<InputField <InputField
id="password" id="password"
value={value}
onChange={onChange}
label="Password" label="Password"
error={Boolean(errors.password)} error={!!errors.password}
errorMessage="Incorrect entry." errorMessage="Incorrect entry."
/> />
)} )}
......
import React, { FC, useEffect } from 'react';
export const LandingPage: FC = () => (
<>
<section>
<h2>What is MoveAid?</h2>
<p>
MoveAid is a project born in order to satisfy a specific problem. There
are many senior citizens who are not able to drive and move from a place
to another easily, because of this they sometimes need to take private
Taxis or public means of transport which could be expensive and not
simple. MoveAid wants to be the solution to this problem offering free
drives (carried out by voulunteers) for those who need them to reach
medical visit, to go to the supermarket or to satisfy any other need.
</p>
</section>
<section>
<h2>How will MoveAid work?</h2>
<p>
MoveAid will be the platform that will allow people to ask for a drive
(either by phone or online) and organizations of voulenteers to organise
and accept drives.
</p>
</section>
<p>
<br />
</p>
<footer>
<p>
Authors: Alberto Defendi, Andrea Esposito, Marco Marinello, Francesco
Mazzini
</p>
<p>&copy 2021 - All right reserved</p>
</footer>
</>
);
import React, { FC, useEffect } from 'react';
export const TeamPage: FC = () => (
<>
<section>
<h2>These are the students of the MoveAid project</h2>
<div>
<h3>Alberto Defendi</h3>
<table>
<tr>
<td> </td>
<td>
<p>
Age: 19 <br />
Role: Front End Developer
<br />
Hobbys: Sports, maths
<br />
</p>
</td>
</tr>
</table>
</div>
<div>
<h3>Andrea Esposito</h3>
<table>
<tr>
<td> </td>
<td>
<p>
Age: 19 <br />
Role: xxxxx
<br />
Hobbys: xxxxxxxxx
<br />
</p>
</td>
</tr>
</table>
</div>
<div>
<h3>Marco Marinello</h3>
<table>
<tr>
<td> </td>
<td>
<p>
Age: 19 <br />
Role: xxxxx
<br />
Hobbys: xxxxxxxxx
<br />
</p>
</td>
</tr>
</table>
</div>
<div>
<h3>Francesco Mazzini</h3>
<table>
<tr>
<td> </td>
<td>
<p>
<strong>Age:</strong> 19 <br />
<br />
<strong>Role:</strong> Front End Developer
<br />
<br />
<strong>Hobbys:</strong> I like Graphic and Programing.
<br />
I also like playing videogames, hanging out <br />
with friends, watching tv series and <br />
training in gym!
</p>
</td>
</tr>
</table>
</div>
</section>
</>
);
src/components/LandingPage/assets/alberto.png

21.7 KiB

src/components/LandingPage/assets/logo04Circle.png

60.3 KiB

src/components/LandingPage/assets/pp.jpg

28.9 KiB

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