Skip to content

Commit c7ed021

Browse files
committed
login function
1 parent f1db34b commit c7ed021

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

backend/TestModel/views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def login (request) :
145145
if hash_code (password) != user[0].password :
146146
return JsonResponse ({'result': 200, 'msg': 'wrong password'})
147147
else :
148-
return JsonResponse ({'result': 200, 'msg': 'success'})
148+
username = user[0].username
149+
return JsonResponse ({'result': 200, 'msg': 'success', 'username': username})
149150

150151

frontend/src/store/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export default new Vuex.Store({
99
username: ''
1010
},
1111
mutations: {
12-
increment (state) {
13-
state.count++
12+
setUserStatus (state, user) {
13+
state.isLogin = true;
14+
state.username = user;
1415
}
1516
},
1617
actions: {

frontend/src/views/Login.vue

+5-25
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,6 @@ export default {
5858
}
5959
},
6060
methods: {
61-
log_in (formName) {
62-
if (formName.name == '' || formName.pwd == '') {
63-
this.$message ({
64-
message: "email and password can not be empty",
65-
type: "error"
66-
})
67-
}
68-
else {
69-
if (formName.name == '358746595@qq.com' && formName.pwd == 'hedyfattoo') {
70-
this.$router.push ('/upload')
71-
}
72-
else {
73-
this.$message ({
74-
message: "wrong email or password",
75-
type: "error"
76-
})
77-
}
78-
}
79-
},
8061
to_home () {
8162
this.$router.push ('/')
8263
},
@@ -88,15 +69,14 @@ export default {
8869
let url = "https://fangzx.pythonanywhere.com/api/login";
8970
let json_data = {
9071
email: this.ruleForm.name,
91-
password: this.ruleForm.password
72+
password: this.ruleForm.pwd
9273
}
9374
axios.post (url, json_data, config).then (response => {
9475
if (response.data.msg == "success") {
95-
this.$msgbox ({
96-
title: 'success',
97-
message: "sign up successfully"
98-
})
99-
this.$router.push ('/login')
76+
sessionStorage.setItem ("username", response.data.username);
77+
this.$store.commit ("setUserStatus", response.data.username);
78+
console.log (this.$store.state.username);
79+
this.$router.push ('/');
10080
}
10181
else {
10282
this.$msgbox ({

0 commit comments

Comments
 (0)