diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index 869bed8..56c3095 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -1,5 +1,5 @@ -import React, { Component } from "react"; -import { Switch, Route, Link, Redirect } from "react-router-dom"; +import React from "react"; +import { Switch, Route, Redirect } from "react-router-dom"; import Home from "./views/Home"; import Dashboard from "./views/DashboardTest"; import Signup from "./views/Signup"; @@ -8,7 +8,7 @@ import Login from "./views/Login"; import { call } from './client_server'; -const ProtectedRoute = ({ component: Comp, loggedIn, logOut, path, ...rest }) => { +/*const ProtectedRoute = ({ component: Comp, loggedIn, logOut, path, ...rest }) => { return ( }} /> ); -}; +};*/ class App extends React.Component { constructor(props) { @@ -55,10 +55,10 @@ class App extends React.Component { } auth(data) { - call.login(data.params) + return call.login(data.params) .then(res => { console.log(res); - if (res.data && res.status == 200) { + if (res.data && res.status === 200) { this.setState( { user: data.params.user, @@ -97,7 +97,7 @@ class App extends React.Component { - {this.state.loggedIn ? : } + {this.state.loggedIn ? : } diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js index 74880b4..1d61886 100644 --- a/smart-hut/src/client_server.js +++ b/smart-hut/src/client_server.js @@ -11,4 +11,12 @@ export var call = { console.error(err); }); }, + register: function(data, headers) { + return axios.post(config + 'register', data) + .then(res => { + return res; + }).catch(err => { + console.error(err); + }); + }, }; diff --git a/smart-hut/src/views/DashboardTest.js b/smart-hut/src/views/DashboardTest.js index bc54d5d..cf35c09 100644 --- a/smart-hut/src/views/DashboardTest.js +++ b/smart-hut/src/views/DashboardTest.js @@ -1,12 +1,8 @@ import React, {Component} from 'react'; import {Button } from 'semantic-ui-react'; -import { Link } from "react-router-dom"; export default class Dashboard extends Component { - constructor(props) { - super(props); - } handleLogOut = (e) => { console.log(this.props); diff --git a/smart-hut/src/views/Home.js b/smart-hut/src/views/Home.js index c73c137..3746ed0 100644 --- a/smart-hut/src/views/Home.js +++ b/smart-hut/src/views/Home.js @@ -3,7 +3,6 @@ import React, { Component } from 'react'; import { Button, Container, - Divider, Grid, Header, Icon, diff --git a/smart-hut/src/views/Login.js b/smart-hut/src/views/Login.js index 425b605..4650666 100644 --- a/smart-hut/src/views/Login.js +++ b/smart-hut/src/views/Login.js @@ -1,5 +1,5 @@ import React, {Component} from 'react'; -import {Button, Form, Grid, Header, Image, Message, Segment, Icon, Checkbox, Input} from 'semantic-ui-react'; +import {Button, Form, Grid, Header, Image, Message, Icon, Checkbox, Input} from 'semantic-ui-react'; export default class Login extends Component { constructor(props) { @@ -15,13 +15,21 @@ export default class Login extends Component { e.preventDefault(); const params = { - username: this.state.user, - password: this.state.password, + "usernameOrEmail": this.state.user, + "password": this.state.password, }; this.props.auth({ user: this.state.user, params : params, + }).then(res => { + if (res === '400') { + console.log('error'); + } else { + console.log("SUCCESS"); + } + }).catch(err => { + console.log(err); }); }; diff --git a/smart-hut/src/views/Signup.js b/smart-hut/src/views/Signup.js index be66ddf..06b96d7 100644 --- a/smart-hut/src/views/Signup.js +++ b/smart-hut/src/views/Signup.js @@ -1,5 +1,6 @@ import React, {Component} from 'react'; -import {Button, Form, Grid, Header, Image, Message, Segment, Icon, Checkbox, Input} from 'semantic-ui-react'; +import {Button, Form, Grid, Header, Image, Icon, Input} from 'semantic-ui-react'; +import { call } from '../client_server'; @@ -7,17 +8,31 @@ export default class Signup extends Component{ constructor(props) { super(props); this.state = { - logged : false, - completeName: '', - username: '', + completeName: "", + username: "", email: "", - password : "" + password : "", }; } - handleLogin = (e) => { - // TODO Login should be handled here - console.log(this.state); + handleRegistration = (e) => { + e.preventDefault(); + const params = { + "email": this.state.email, + "name": this.state.completeName, + "password": this.state.password, + "username": this.state.username, + }; + + call.register(params) + .then(res => { + if (res.data && res.status === 200) { + console.log(res.data); + } + }).catch(err => { + + }); + console.log(this.state); }; onChangeHandler = (event) => { @@ -86,7 +101,7 @@ export default class Signup extends Component{ minLength={6} required /> -