Skip to content

Commit d6d2472

Browse files
committed
Part 2-3 finished
1 parent 8ac8d13 commit d6d2472

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

djsr/authentication/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ObtainTokenPairWithColorView(TokenObtainPairView):
1212

1313
class CustomUserCreate(APIView):
1414
permission_classes = (permissions.AllowAny,)
15+
authentication_classes = ()
1516

1617
def post(self, request, format='json'):
1718
serializer = CustomUserSerializer(data=request.data)

djsr/frontend/src/axiosApi.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ axiosInstance.interceptors.response.use(
3636
console.log(err)
3737
});
3838
}
39-
return Promise.reject(error);
39+
// specific error handling done elsewhere
40+
return Promise.reject({...error});
4041
}
4142
);
4243

djsr/frontend/src/components/signup.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, { Component } from "react";
2+
import axiosInstance from "../axiosApi";
23

34
class Signup extends Component{
45
constructor(props){
56
super(props);
67
this.state = {
78
username: "",
89
password: "",
9-
email:""
10+
email:"",
11+
errors:{}
1012
};
1113

1214
this.handleChange = this.handleChange.bind(this);
@@ -17,9 +19,21 @@ class Signup extends Component{
1719
this.setState({[event.target.name]: event.target.value});
1820
}
1921

20-
handleSubmit(event) {
21-
alert('A username and password was submitted: ' + this.state.username + " " + this.state.password + " " + this.state.email);
22+
async handleSubmit(event) {
2223
event.preventDefault();
24+
try {
25+
const response = await axiosInstance.post('/user/create/', {
26+
username: this.state.username,
27+
email: this.state.email,
28+
password: this.state.password
29+
});
30+
return response;
31+
} catch (error) {
32+
console.log(error.stack);
33+
this.setState({
34+
errors:error.response.data
35+
});
36+
}
2337
}
2438

2539
render() {
@@ -30,19 +44,23 @@ class Signup extends Component{
3044
<label>
3145
Username:
3246
<input name="username" type="text" value={this.state.username} onChange={this.handleChange}/>
47+
{ this.state.errors.username ? this.state.errors.username : null}
3348
</label>
3449
<label>
3550
Email:
3651
<input name="email" type="email" value={this.state.email} onChange={this.handleChange}/>
52+
{ this.state.errors.email ? this.state.errors.email : null}
3753
</label>
3854
<label>
3955
Password:
4056
<input name="password" type="password" value={this.state.password} onChange={this.handleChange}/>
57+
{ this.state.errors.password ? this.state.errors.password : null}
4158
</label>
4259
<input type="submit" value="Submit"/>
4360
</form>
4461
</div>
4562
)
4663
}
4764
}
65+
4866
export default Signup;

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

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

0 commit comments

Comments
 (0)