From 0c443a7314498cc6c6ba29bb4a175b9f42d5ad48 Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 7 Mar 2020 10:54:42 +0100 Subject: [PATCH 1/8] Finish forgot password and start test --- .gitlab-ci.yml | 21 +++++++++++++++++++++ smart-hut/src/App.js | 4 ++-- smart-hut/src/client_server.js | 20 ++++++++++++++++++-- smart-hut/src/views/Forgot-pass-reset.js | 17 +++++++++++++++-- smart-hut/src/views/Forgot-password.js | 16 +++++++++++++++- 5 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..9e4f653 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,21 @@ +image: node:latest + +stages: + - build + - test + +cache: + paths: + - node_modules/ + +install_dependencies: + stage: build + script: + - npm install + artifacts: + paths: + - node_modules/ + +testing_testing: + stage: test + script: npm test \ No newline at end of file diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index ea84497..3c445d3 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -89,8 +89,8 @@ class App extends React.Component { - - + + ); diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js index b8ed670..427d1db 100644 --- a/smart-hut/src/client_server.js +++ b/smart-hut/src/client_server.js @@ -8,7 +8,7 @@ export var call = { .then(res => { return res; }).catch(err => { - return err; + return {status : "Errore"}; }); }, register: function(data, headers) { @@ -17,7 +17,23 @@ export var call = { return res; }).catch(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"}; + }); + }, }; diff --git a/smart-hut/src/views/Forgot-pass-reset.js b/smart-hut/src/views/Forgot-pass-reset.js index 39496d5..170bf1d 100644 --- a/smart-hut/src/views/Forgot-pass-reset.js +++ b/smart-hut/src/views/Forgot-pass-reset.js @@ -1,6 +1,6 @@ import React, {Component} from '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 { @@ -31,7 +31,20 @@ export default class ChangePass extends Component { }; 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() { diff --git a/smart-hut/src/views/Forgot-password.js b/smart-hut/src/views/Forgot-password.js index b3f1e93..99a454d 100644 --- a/smart-hut/src/views/Forgot-password.js +++ b/smart-hut/src/views/Forgot-password.js @@ -1,6 +1,6 @@ import React, {Component} from '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 { @@ -22,7 +22,21 @@ export default class ForgotPass extends Component { }; 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() { From 649cec210d44d4529894612e62481d4a5f0e4072 Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 7 Mar 2020 11:59:04 +0100 Subject: [PATCH 2/8] initial test and 404 page --- smart-hut/src/App.js | 16 +++++++++++----- smart-hut/src/App.test.js | 15 +++++++++++---- smart-hut/src/index.js | 12 ++++-------- smart-hut/src/views/FourOhFour.js | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 smart-hut/src/views/FourOhFour.js diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index 3c445d3..592ecdc 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -1,9 +1,10 @@ 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 Dashboard from "./views/DashboardTest"; import Signup from "./views/Signup"; import Login from "./views/Login"; +import FourOhFour from "./views/FourOhFour"; import ForgotPass from "./views/Forgot-password"; import ChangePass from "./views/Forgot-pass-reset"; import queryString from 'query-string'; @@ -33,10 +34,12 @@ class App extends React.Component { } componentDidMount() { - const values = queryString.parse(this.props.location.search); - this.setState({ - query : values - }); + if (this.props.location) { + const values = queryString.parse(this.props.location.search); + this.setState({ + query : values + }); + } } auth(data) { @@ -77,6 +80,7 @@ class App extends React.Component { render() { return ( + @@ -92,7 +96,9 @@ class App extends React.Component { + + ); } } diff --git a/smart-hut/src/App.test.js b/smart-hut/src/App.test.js index 4db7ebc..dd1c60a 100644 --- a/smart-hut/src/App.test.js +++ b/smart-hut/src/App.test.js @@ -1,9 +1,16 @@ import React from 'react'; import { render } from '@testing-library/react'; +import { Router } from "react-router"; +import { createMemoryHistory } from "history"; import App from './App'; -test('renders learn react link', () => { - const { getByText } = render(); - const linkElement = getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); +test("redirects to homepage", () => { + const history = createMemoryHistory(); + render( + + + + ); + expect(history.location.pathname).toBe("/"); }); + diff --git a/smart-hut/src/index.js b/smart-hut/src/index.js index 1ec8388..840e490 100644 --- a/smart-hut/src/index.js +++ b/smart-hut/src/index.js @@ -3,17 +3,13 @@ import ReactDOM from 'react-dom'; import App from './App'; import * as serviceWorker from './serviceWorker'; //React Router -import { BrowserRouter, Route, Switch } from "react-router-dom"; +//import { BrowserRouter, Route, Switch } from "react-router-dom"; -const routes = ( - - - - - +const index = ( + ); ReactDOM.render( - routes + index , document.getElementById('root')); serviceWorker.unregister(); diff --git a/smart-hut/src/views/FourOhFour.js b/smart-hut/src/views/FourOhFour.js new file mode 100644 index 0000000..99cca6c --- /dev/null +++ b/smart-hut/src/views/FourOhFour.js @@ -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 ( + + 404 Page Not Found +

+ Hey what are you doing here? + Go back to our homepage +

+
+ ) + } +} \ No newline at end of file From 97fdee796e38de9c96f4eb68cd5a4a14803a9ebb Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 7 Mar 2020 12:38:53 +0100 Subject: [PATCH 3/8] update .gitlab-ci.yml --- .gitlab-ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9e4f653..f587208 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,11 +11,13 @@ cache: install_dependencies: stage: build script: + - cd smarthut - npm install artifacts: - paths: - - node_modules/ + paths: node_modules/ testing_testing: stage: test - script: npm test \ No newline at end of file + script: + - cd smarthut + - npm test \ No newline at end of file From ddf01bf15922fe5c8f7bf93f87b2c56425bfde40 Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 7 Mar 2020 12:42:57 +0100 Subject: [PATCH 4/8] update 2 gitlab-ci.yml --- .gitlab-ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f587208..8db49f2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,10 +14,11 @@ install_dependencies: - cd smarthut - npm install artifacts: - paths: node_modules/ + paths: + - node_modules/ testing_testing: stage: test script: - - cd smarthut + - cd smarthut - npm test \ No newline at end of file From 14a7b8c2641c88e5c3c450957c3bbb1b3bcec641 Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 7 Mar 2020 12:47:43 +0100 Subject: [PATCH 5/8] update 3 gitlab-ci.yml --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8db49f2..608649c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ cache: install_dependencies: stage: build script: - - cd smarthut + - cd smart-hut - npm install artifacts: paths: @@ -20,5 +20,5 @@ install_dependencies: testing_testing: stage: test script: - - cd smarthut + - cd smart-hut - npm test \ No newline at end of file From c5582882eb6930bbed3c1a99c5069ee60ce46099 Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 7 Mar 2020 13:07:32 +0100 Subject: [PATCH 6/8] update 4 gitlab-ci.yml --- .gitlab-ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 608649c..4be7128 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,13 +12,14 @@ install_dependencies: stage: build script: - cd smart-hut - - npm install + - yarn install artifacts: paths: + - cd smart-hut - node_modules/ testing_testing: stage: test script: - cd smart-hut - - npm test \ No newline at end of file + - yarn test \ No newline at end of file From ac15bbc4f22ad83220c9f8d18c04c476b3dbf137 Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 7 Mar 2020 15:10:02 +0100 Subject: [PATCH 7/8] update 5 gitlab-ci.yml --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4be7128..3ec65b4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,7 +15,6 @@ install_dependencies: - yarn install artifacts: paths: - - cd smart-hut - node_modules/ testing_testing: From f1775a837a3845529a9cb2fe2ff121d40530f772 Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 7 Mar 2020 15:12:52 +0100 Subject: [PATCH 8/8] update6 gitlab-ci.yml --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ec65b4..a033693 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,7 @@ stages: cache: paths: - - node_modules/ + - smart-hut/node_modules/ install_dependencies: stage: build @@ -15,7 +15,7 @@ install_dependencies: - yarn install artifacts: paths: - - node_modules/ + - smart-hut/node_modules/ testing_testing: stage: test