Skip to content

Commit 12ae165

Browse files
committed
add captcha
1 parent 381479c commit 12ae165

File tree

7 files changed

+88
-8
lines changed

7 files changed

+88
-8
lines changed

src/components/lib/AjaxTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default {
4444
this.loading = false;
4545
})
4646
.catch(err => {
47-
this.$SegmentMessage.error(this, '[Ajax Table] Request Failed.');
47+
this.$SegmentMessage.error(this, '[Ajax Table] Request Failed');
4848
console.log(err);
4949
});
5050
}

src/components/lib/captcha.vue

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<template>
2+
<div class="captcha">
3+
<el-input v-model="captcha_answer" placeholder="Solve Captcha"></el-input>
4+
<img class="captcha-img" v-if="loaded" @click="refresh_captcha();" :src="img_url" />
5+
</div>
6+
</template>
7+
8+
<script>
9+
import apiurl from './../../apiurl';
10+
11+
export default {
12+
name: 'captcha',
13+
data() {
14+
return {
15+
img_url: null,
16+
captcha_answer: '',
17+
loaded: false
18+
};
19+
},
20+
watch: {
21+
captcha_answer(val) {
22+
this.$store.commit('setAnswer', {
23+
val: val
24+
});
25+
}
26+
},
27+
methods: {
28+
refresh_captcha() {
29+
this.img_url = apiurl('/captcha/' + this.$store.state.captcha.captchaKey + '?sfid=' + String(Math.random()));
30+
}
31+
},
32+
mounted() {
33+
this.$store.commit('newCaptcha');
34+
this.img_url = apiurl('/captcha/' + this.$store.state.captcha.captchaKey + '?sfid=' + String(Math.random()));
35+
this.loaded = true;
36+
}
37+
};
38+
</script>
39+
40+
<style scoped>
41+
.captcha {
42+
display: flex;
43+
}
44+
45+
.captcha-img {
46+
margin-left: 10px;
47+
}
48+
</style>

src/components/problem/list.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default {
6767
this.data_count = data.res;
6868
})
6969
.catch(err => {
70-
this.$SegmentMessage.error(this, '[Problem List] Get List Length Failed.');
70+
this.$SegmentMessage.error(this, '[Problem List] Get List Length Failed');
7171
console.log(err);
7272
});
7373
}

src/components/user/register.vue

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<el-form-item prop="email">
1919
<el-input type="email" v-model="ldata.email"></el-input>
2020
</el-form-item>
21+
<div class="icon-lable form-required"><i class="el-icon-check" /> Captcha</div>
22+
<captcha class="margin-bottom" />
2123
<el-form-item>
2224
<el-button type="primary" v-on:click="onSubmit();" :loading="buttonLoading">Register</el-button>
2325
<el-button v-on:click="$store.state.user.showregister = false;">Cancel</el-button>
@@ -30,6 +32,7 @@
3032

3133
<script>
3234
import apiurl from './../../apiurl';
35+
import captcha from './../lib/captcha.vue';
3336
3437
export default {
3538
name: 'UserRegister',
@@ -99,7 +102,9 @@ export default {
99102
.post(apiurl('/account'), {
100103
username: this.ldata.username,
101104
password: this.ldata.password,
102-
email: this.ldata.email
105+
email: this.ldata.email,
106+
captcha_key: this.$store.state.captcha.captchaKey,
107+
captcha_answer: this.$store.state.captcha.captchaAnswer
103108
})
104109
.then(() => {
105110
this.$store.state.user.showregister = false;
@@ -137,13 +142,19 @@ export default {
137142
reset() {
138143
this.$refs['register'].resetFields();
139144
}
145+
},
146+
components: {
147+
captcha
140148
}
141149
};
142150
</script>
143151

144152
<style scoped>
145-
.form-required::before {
146-
content: "*";
147-
color: #f56c6c;
153+
.form-required {
154+
margin-bottom: 5px;
155+
}
156+
157+
.margin-bottom {
158+
margin-bottom: 20px;
148159
}
149160
</style>

src/sfconfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export default {
99
pedantic: false,
1010
smartLists: true,
1111
smartypants: false,
12-
}
12+
},
13+
captchaKeyMax: 2000000000
1314
};

src/store/captcha.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sfconfig from './../sfconfig';
2+
3+
const captchastore = {
4+
state: {
5+
captchaKey: null,
6+
captchaAnswer: null
7+
},
8+
mutations: {
9+
newCaptcha(state) {
10+
state.captchaKey = Math.floor(Math.random() * sfconfig.captchaKeyMax) + 1;
11+
},
12+
setAnswer(state, data) {
13+
state.captchaAnswer = data.val;
14+
}
15+
}
16+
};
17+
18+
export default captchastore;

src/store/store.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import Vuex from 'vuex';
44
Vue.use(Vuex);
55

66
import userstore from './user';
7+
import captchastore from './captcha';
78

89
export default new Vuex.Store({
910
modules: {
10-
user: userstore
11+
user: userstore,
12+
captcha: captchastore
1113
}
1214
});

0 commit comments

Comments
 (0)