Skip to content

Commit 3bbd8de

Browse files
committed
Login works
1 parent 7a82589 commit 3bbd8de

File tree

10 files changed

+131
-20
lines changed

10 files changed

+131
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.swp
22
node_modules/**
3-
dist/**
3+
public/dist/**
4+
public/css/**

app/App.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import { Router, Route } from 'react-router'
4+
5+
import iClientComponent from './components/iClient/iClientComponent';
6+
7+
ReactDOM.render(
8+
<Router>
9+
<Route path="/" component={iClientComponent} />
10+
</Router>,
11+
document.getElementById('app')
12+
);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
3+
class ClientComponent extends React.Component{
4+
constructor(props) {
5+
super(props);
6+
}
7+
8+
render() {
9+
return (
10+
<div className="container hello">
11+
<h1>{{ msg }}</h1>
12+
<table className="table">
13+
<thead>
14+
<tr>
15+
<th>Name</th>
16+
<th>Address</th>
17+
<th>City</th>
18+
<th></th>
19+
<th></th>
20+
</tr>
21+
</thead>
22+
<tbody>
23+
<tr v-for="client in clients">
24+
<td>{{ client.name }}</td>
25+
<td>{{ client.address }}</td>
26+
<td>{{ client.city }}</td>
27+
<td className="is-icon"> <a href="#"> <i className="fa fa-calendar"></i> </a>
28+
</td>
29+
<td className="is-icon"> <a href="#"> <i className="fa fa-search"></i> </a>
30+
</td>
31+
</tr>
32+
</tbody>
33+
</table>
34+
</div>
35+
);
36+
}
37+
}
38+
39+
export default ClientComponent;
40+

src/components/Home/HomeComponent.js renamed to app/components/Login/LoginComponent.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
import React from 'react';
22

3-
class HomeComponent extends React.Component{
4-
constructor(props) {
5-
super(props);
3+
import iClientUser from './../../services/iClientUser';
4+
5+
class LoginComponent extends React.Component{
6+
constructor(props, context) {
7+
super(props, context);
8+
this.handleSubmit = this.handleSubmit.bind(this);
9+
}
10+
11+
handleSubmit(e) {
12+
e.preventDefault();
13+
14+
iClientUser.login(
15+
this.refs.username.value,
16+
this.refs.password.value
17+
).then((response) => {
18+
localStorage.token = response.data.token;
19+
window.location.href = "/";
20+
});
21+
console.log(this.refs.username.value);
22+
console.log(this.refs.password.value);
623
}
724

825
render() {
@@ -17,18 +34,27 @@ class HomeComponent extends React.Component{
1734
</h1>
1835
<form onSubmit={this.handleSubmit}>
1936
<div className="box">
20-
<label className="label">Email</label>
37+
<label className="label">Username</label>
2138
<p className="control">
22-
<input className="input" type="text" placeholder="[email protected]" />
39+
<input
40+
ref='username'
41+
className="input"
42+
type="text"
43+
placeholder="Ex: jsmith"
44+
/>
2345
</p>
2446
<label className="label">Password</label>
2547
<p className="control">
26-
<input className="input" type="password" placeholder="●●●●●●●" />
48+
<input
49+
ref='password'
50+
className="input"
51+
type="password"
52+
placeholder="●●●●●●●"
53+
/>
2754
</p>
2855
<hr />
2956
<p className="control">
3057
<button className="button is-primary">Login</button>
31-
<button className="button is-default">Cancel</button>
3258
</p>
3359
<p className="has-text-centered">
3460
<a href="register.html">Register an Account</a>
@@ -46,4 +72,4 @@ class HomeComponent extends React.Component{
4672
}
4773
}
4874

49-
export default HomeComponent;
75+
export default LoginComponent;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
3+
import LoginComponent from './../Login/LoginComponent';
4+
5+
class iClientComponent extends React.Component{
6+
constructor(props) {
7+
super(props);
8+
}
9+
10+
render() {
11+
let view = <h1>Teste</h1>;
12+
13+
if (!localStorage.token) {
14+
view = <LoginComponent />;
15+
}
16+
return (
17+
view
18+
);
19+
}
20+
}
21+
22+
export default iClientComponent;
23+

app/services/iClientUser.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import axios from 'axios';
2+
3+
const host = 'http://localhost:3000';
4+
const iClientUser = {
5+
login(username, password) {
6+
let auth = {
7+
username: username,
8+
password: password
9+
};
10+
return axios.post(`${host}/authenticate`, auth);
11+
}
12+
};
13+
14+
export default iClientUser;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"bulma": "^0.2.1",
99
"font-awesome": "^4.6.3",
1010
"react": "^15.3.2",
11-
"react-dom": "^15.3.2"
11+
"react-dom": "^15.3.2",
12+
"react-router": "^2.8.1"
1213
},
1314
"devDependencies": {
1415
"babel-core": "^6.17.0",

index.html renamed to public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<head>
44
<meta charset="utf-8">
55
<title>React Client</title>
6-
<link rel="stylesheet" href="node_modules/bulma/css/bulma.css">
7-
<link rel="stylesheet" href="node_modules/font-awesome/css/font-awesome.min.css">
6+
<link rel="stylesheet" href="css/bulma.css">
7+
<link rel="stylesheet" href="css/font-awesome.min.css">
88
</head>
99
<body>
1010
<div id="app"></div>

src/main.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
entry: "./src/main.js",
2+
entry: "./app/App.js",
33
output: {
4-
filename: "dist/bundle.js"
4+
filename: "public/dist/bundle.js"
55
},
66
module: {
77
loaders: [

0 commit comments

Comments
 (0)