Skip to content

Commit 83d6582

Browse files
committed
add login captcha
1 parent 853c7c2 commit 83d6582

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

web/src/assets/styles/login.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
}
4545
.login-main {
4646
width: 380px;
47-
height: 300px;
4847
background-color: $body-background;
4948
margin-right: 9.5%;
5049
padding: 20px;
@@ -76,9 +75,15 @@
7675
}
7776
}
7877
.remember-user-name {
79-
margin: 5px 0 0 10px;
78+
margin: 0px 0 10px 10px;
8079
}
8180
.ivu-form-item {
8281
margin-bottom: 20px;
8382
}
83+
.captcha-wp {
84+
display: flex;
85+
img{
86+
height: 44px;
87+
}
88+
}
8489
}

web/src/commonData/i18n/common/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@
800800
"password": "Please enter password!",
801801
"loginSuccess": "Login Success",
802802
"haveLogin": "You have already logged in, please do not login repeatedly",
803-
"vaildFaild": "Authentication failed!"
803+
"vaildFaild": "Authentication failed!",
804+
"captcha": "Please enter captcha"
804805
},
805806
"userMenu": {
806807
"title": "Warning",

web/src/commonData/i18n/common/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@
800800
"password": "请输入密码!",
801801
"loginSuccess": "登录成功",
802802
"haveLogin": "您已经登录,请不要重复登录",
803-
"vaildFaild": "验证未通过!"
803+
"vaildFaild": "验证未通过!",
804+
"captcha": "请输入验证码"
804805
},
805806
"userMenu": {
806807
"title": "警告",

web/src/js/view/login/index.vue

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,23 @@
2323
<Input
2424
v-model="loginForm.password"
2525
type="password"
26-
placeholder="请输入密码"
26+
:placeholder="this.$t('message.login.password')"
2727
size="large" />
28-
<Checkbox
29-
v-model="rememberUserNameAndPass"
30-
class="remember-user-name"
31-
style="">{{$t('message.login.remenber')}}</Checkbox>
3228
</FormItem>
29+
<FormItem prop="captcha" v-if="captImg">
30+
<div class="captcha-wp">
31+
<Input
32+
v-model="loginForm.captcha"
33+
type="text"
34+
:placeholder="$t('message.login.captcha')"
35+
size="large"/>
36+
<div><img :src="captImg" @click="getCapt"></div>
37+
</div>
38+
</FormItem>
39+
<Checkbox
40+
v-model="rememberUserNameAndPass"
41+
class="remember-user-name"
42+
style="">{{$t('message.login.remenber')}}</Checkbox>
3343
<FormItem>
3444
<Button
3545
:loading="loading"
@@ -47,13 +57,17 @@
4757
import api from '@/js/service/api';
4858
import storage from '@/js/helper/storage';
4959
import socket from '@js/module/webSocket';
60+
import axios from 'axios';
5061
export default {
5162
data() {
5263
return {
5364
loading: false,
65+
captImg: null,
66+
5467
loginForm: {
5568
user: '',
5669
password: '',
70+
captcha: ''
5771
},
5872
ruleInline: {
5973
user: [
@@ -64,6 +78,10 @@ export default {
6478
{ required: true, message: this.$t('message.login.password'), trigger: 'blur' },
6579
// {type: 'string', pattern: /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,18}$/, message: '请输入6至12位的密码', trigger: 'change'},
6680
],
81+
captcha: [
82+
{ required: true, message: this.$t('message.login.captcha'), trigger: 'blur' }
83+
]
84+
6785
},
6886
rememberUserNameAndPass: false,
6987
};
@@ -75,6 +93,7 @@ export default {
7593
this.loginForm.user = userNameAndPass.split('&')[0];
7694
this.loginForm.password = userNameAndPass.split('&')[1];
7795
}
96+
this.getCapt();
7897
},
7998
mounted() {
8099
// 如果有登录状态,且用户手动跳转到login页,则判断登录态是否过期
@@ -85,6 +104,18 @@ export default {
85104
socket.methods.close();
86105
},
87106
methods: {
107+
getCapt(){
108+
axios.get('/api/rest_j/v1/user/captcha').then(data=>{
109+
api.fetch('/user/captcha', 'get').then((data)=>{
110+
this.captImg = data.image
111+
}).catch(()=>{
112+
this.captImg = null;
113+
})
114+
}).catch(err=>{
115+
this.captImg = null;
116+
console.warn('err', err);
117+
})
118+
},
88119
getIfLogin() {
89120
api.fetch('/dss/getBaseInfo', 'get').then(() => {
90121
this.$router.push('/');
@@ -103,6 +134,7 @@ export default {
103134
const params = {
104135
userName: this.loginForm.user,
105136
password: this.loginForm.password,
137+
captcha: this.loginForm.captcha,
106138
};
107139
api
108140
.fetch(`/user/login`, params)
@@ -133,6 +165,7 @@ export default {
133165
this.$Message.error(this.$t('message.login.vaildFaild'));
134166
}
135167
});
168+
this.getCapt();
136169
},
137170
clearSession() {
138171
storage.clear();

0 commit comments

Comments
 (0)