Skip to content

Commit 7f07c99

Browse files
committed
Login and Signup forms completed. Axios not added
1 parent 1d068d8 commit 7f07c99

File tree

8 files changed

+504
-13
lines changed

8 files changed

+504
-13
lines changed
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import React, { Component} from "react";
2+
import { Switch, Route, Link } from "react-router-dom";
3+
import Login from "./login";
4+
import Signup from "./signup";
25

3-
class App extends Component{
4-
render(){
5-
return(
6-
<div className="site">
7-
<h1>Ahhh after 10,000 years I'm free. Time to conquer the Earth!</h1>
8-
</div>
9-
);
10-
}
6+
class App extends Component {
7+
render() {
8+
return (
9+
<div className="site">
10+
<nav>
11+
<Link className={"nav-link"} to={"/"}>Home</Link>
12+
<Link className={"nav-link"} to={"/login/"}>Login</Link>
13+
<Link className={"nav-link"} to={"/signup/"}>Signup</Link>
14+
</nav>
15+
<main>
16+
<h1>Ahhh after 10,000 years I'm free. Time to conquer the Earth!</h1>
17+
18+
<Switch>
19+
<Route exact path={"/login/"} component={Login}/>
20+
<Route exact path={"/signup/"} component={Signup}/>
21+
<Route path={"/"} render={() => <div>Home again</div>}/>
22+
</Switch>
23+
</main>
24+
</div>
25+
);
26+
}
1127
}
1228

1329
export default App;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { Component } from "react";
2+
3+
class Login extends Component {
4+
constructor(props) {
5+
super(props);
6+
this.state = {username: "", password: ""};
7+
8+
this.handleChange = this.handleChange.bind(this);
9+
this.handleSubmit = this.handleSubmit.bind(this);
10+
}
11+
12+
handleChange(event) {
13+
this.setState({[event.target.name]: event.target.value});
14+
}
15+
16+
handleSubmit(event) {
17+
alert('A username and password was submitted: ' + this.state.username + " " + this.state.password);
18+
event.preventDefault();
19+
}
20+
21+
render() {
22+
return (
23+
<div>
24+
Login
25+
<form onSubmit={this.handleSubmit}>
26+
<label>
27+
Username:
28+
<input name="username" type="text" value={this.state.username} onChange={this.handleChange}/>
29+
</label>
30+
<label>
31+
Password:
32+
<input name="password" type="password" value={this.state.password} onChange={this.handleChange}/>
33+
</label>
34+
<input type="submit" value="Submit"/>
35+
</form>
36+
</div>
37+
)
38+
}
39+
}
40+
export default Login;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { Component } from "react";
2+
3+
class Signup extends Component{
4+
constructor(props){
5+
super(props);
6+
this.state = {
7+
username: "",
8+
password: "",
9+
email:""
10+
};
11+
12+
this.handleChange = this.handleChange.bind(this);
13+
this.handleSubmit = this.handleSubmit.bind(this);
14+
}
15+
16+
handleChange(event) {
17+
this.setState({[event.target.name]: event.target.value});
18+
}
19+
20+
handleSubmit(event) {
21+
alert('A username and password was submitted: ' + this.state.username + " " + this.state.password + " " + this.state.email);
22+
event.preventDefault();
23+
}
24+
25+
render() {
26+
return (
27+
<div>
28+
Signup
29+
<form onSubmit={this.handleSubmit}>
30+
<label>
31+
Username:
32+
<input name="username" type="text" value={this.state.username} onChange={this.handleChange}/>
33+
</label>
34+
<label>
35+
Email:
36+
<input name="email" type="email" value={this.state.email} onChange={this.handleChange}/>
37+
</label>
38+
<label>
39+
Password:
40+
<input name="password" type="password" value={this.state.password} onChange={this.handleChange}/>
41+
</label>
42+
<input type="submit" value="Submit"/>
43+
</form>
44+
</div>
45+
)
46+
}
47+
}
48+
export default Signup;

djsr/frontend/src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import React from 'react'
22
import {render} from 'react-dom'
3+
import {BrowserRouter} from 'react-router-dom'
34
import App from './components/App';
45

5-
render(<App />, document.getElementById('root'));
6+
render((
7+
<BrowserRouter>
8+
<App />
9+
</BrowserRouter>
10+
), document.getElementById('root'));

djsr/frontend/static/frontend/public/main.js

Lines changed: 262 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#root{
22
background-color:rebeccapurple;
33
color:white;
4-
}
4+
}
5+
6+
.nav-link{
7+
color:white;
8+
border: 1px solid white;
9+
padding: 1em;
10+
}

package-lock.json

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"dependencies": {
2121
"react": "^16.8.6",
22-
"react-dom": "^16.8.6"
22+
"react-dom": "^16.8.6",
23+
"react-router-dom": "^5.0.1"
2324
}
2425
}

0 commit comments

Comments
 (0)