Merge branch '24-finish-forgot-password-and-start-test-on-frontend' into 'dev'

Resolve "Finish forgot password and start test on frontend"

Closes #24

See merge request sa4-2020/the-sanmarinoes/frontend!16
This commit is contained in:
Matteo Omenetti 2020-03-07 18:14:08 +01:00
commit 3e8090142f
8 changed files with 119 additions and 24 deletions

24
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,24 @@
image: node:latest
stages:
- build
- test
cache:
paths:
- smart-hut/node_modules/
install_dependencies:
stage: build
script:
- cd smart-hut
- yarn install
artifacts:
paths:
- smart-hut/node_modules/
testing_testing:
stage: test
script:
- cd smart-hut
- yarn test

View file

@ -1,9 +1,10 @@
import React from "react"; import React from "react";
import { Switch, Route, Redirect } from "react-router-dom"; import {BrowserRouter, Switch, Route, Redirect } from "react-router-dom";
import Home from "./views/Home"; import Home from "./views/Home";
import Dashboard from "./views/DashboardTest"; import Dashboard from "./views/DashboardTest";
import Signup from "./views/Signup"; import Signup from "./views/Signup";
import Login from "./views/Login"; import Login from "./views/Login";
import FourOhFour from "./views/FourOhFour";
import ForgotPass from "./views/Forgot-password"; import ForgotPass from "./views/Forgot-password";
import ChangePass from "./views/Forgot-pass-reset"; import ChangePass from "./views/Forgot-pass-reset";
import queryString from 'query-string'; import queryString from 'query-string';
@ -33,11 +34,13 @@ class App extends React.Component {
} }
componentDidMount() { componentDidMount() {
if (this.props.location) {
const values = queryString.parse(this.props.location.search); const values = queryString.parse(this.props.location.search);
this.setState({ this.setState({
query : values query : values
}); });
} }
}
auth(data) { auth(data) {
return call.login(data.params) return call.login(data.params)
@ -77,6 +80,7 @@ class App extends React.Component {
render() { render() {
return ( return (
<BrowserRouter>
<Switch> <Switch>
<Route path="/" exact component={Home} /> <Route path="/" exact component={Home} />
<Route path="/login" > <Route path="/login" >
@ -89,10 +93,12 @@ class App extends React.Component {
<Route path="/forgot-password" > <Route path="/forgot-password" >
<ForgotPass /> <ForgotPass />
</Route> </Route>
<Route path="/forgot-pass-change" > <Route path="/forgot-pass-reset" >
<ChangePass /> <ChangePass query={this.state.query}/>
</Route> </Route>
<Route component={FourOhFour} />
</Switch> </Switch>
</BrowserRouter>
); );
} }
} }

View file

@ -1,9 +1,16 @@
import React from 'react'; import React from 'react';
import { render } from '@testing-library/react'; import { render } from '@testing-library/react';
import { Router } from "react-router";
import { createMemoryHistory } from "history";
import App from './App'; import App from './App';
test('renders learn react link', () => { test("redirects to homepage", () => {
const { getByText } = render(<App />); const history = createMemoryHistory();
const linkElement = getByText(/learn react/i); render(
expect(linkElement).toBeInTheDocument(); <Router history={history}>
<App />
</Router>
);
expect(history.location.pathname).toBe("/");
}); });

View file

@ -8,7 +8,7 @@ export var call = {
.then(res => { .then(res => {
return res; return res;
}).catch(err => { }).catch(err => {
return err; return {status : "Errore"};
}); });
}, },
register: function(data, headers) { register: function(data, headers) {
@ -17,7 +17,23 @@ export var call = {
return res; return res;
}).catch(err => { }).catch(err => {
//console.error(err); //console.error(err);
return err; return {status : "Errore"};
});
},
initResetPassword: function(data, headers) {
return axios.post(config + 'register/init-reset-password', data)
.then(res => {
return res;
}).catch(err => {
return {status : "Errore"};
});
},
resetPassword: function(data, headers) {
return axios.put(config + 'register/reset-password', data)
.then(res => {
return res;
}).catch(err => {
return {status : "Errore"};
}); });
}, },
}; };

View file

@ -3,17 +3,13 @@ import ReactDOM from 'react-dom';
import App from './App'; import App from './App';
import * as serviceWorker from './serviceWorker'; import * as serviceWorker from './serviceWorker';
//React Router //React Router
import { BrowserRouter, Route, Switch } from "react-router-dom"; //import { BrowserRouter, Route, Switch } from "react-router-dom";
const routes = ( const index = (
<BrowserRouter> <App />
<Switch>
<Route path="/" component={App} />
</Switch>
</BrowserRouter>
); );
ReactDOM.render( ReactDOM.render(
routes index
, document.getElementById('root')); , document.getElementById('root'));
serviceWorker.unregister(); serviceWorker.unregister();

View file

@ -1,6 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react'; import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react';
//import { call } from '../client_server'; import { call } from '../client_server';
export default class ChangePass extends Component { export default class ChangePass extends Component {
@ -31,7 +31,20 @@ export default class ChangePass extends Component {
}; };
handleChangePassword = (e) => { handleChangePassword = (e) => {
const params = {
"confirmationToken" : this.props.query.confirmationToken ,
"password" : this.state.password
}
call.resetPassword(params)
.then(res => {
if (res.status === "Errore") {
this.setState({ error: { state: true,
message: "Errore"}});
}
// else set a message that an email has been sent
}).catch(err => {
console.log(err);
});
}; };
render() { render() {

View file

@ -1,6 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react'; import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react';
//import { call } from '../client_server'; import { call } from '../client_server';
export default class ForgotPass extends Component { export default class ForgotPass extends Component {
@ -22,7 +22,21 @@ export default class ForgotPass extends Component {
}; };
handleSendEmail = (e) => { handleSendEmail = (e) => {
e.preventDefault();
const params = {
"email" : this.state.user,
}
call.initResetPassword(params)
.then(res => {
if (res.status === "Errore") {
this.setState({ error: { state: true,
message: "Errore"}});
}
//set a message that an email has been sent
}).catch(err => {
console.log(err);
});
}; };
render() { render() {

View file

@ -0,0 +1,19 @@
import React, {Component} from 'react';
import { Message} from 'semantic-ui-react';
import {Link } from "react-router-dom";
export default class FourOhFour extends Component {
render() {
return (
<Message>
<Message.Header>404 Page Not Found</Message.Header>
<p>
Hey what are you doing here?
Go back to our homepage <Link to="/"/>
</p>
</Message>
)
}
}