Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ant-design-pro-vue
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tianzhuanghu
ant-design-pro-vue
Commits
e60479eb
Commit
e60479eb
authored
Oct 22, 2018
by
Sendya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add 2step chatcha
parent
56947a11
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
4 deletions
+115
-4
TwoStepCaptcha.vue
src/components/tools/TwoStepCaptcha.vue
+80
-0
Login.vue
src/views/Login.vue
+35
-4
No files found.
src/components/tools/TwoStepCaptcha.vue
0 → 100644
View file @
e60479eb
<
template
>
<!-- 两步验证 -->
<a-modal
centered
v-model=
"visible"
@
cancel=
"handleCancel"
:maskClosable=
"false"
>
<div
slot=
"title"
:style=
"
{ textAlign: 'center' }">两步验证
</div>
<template
slot=
"footer"
>
<div
:style=
"
{ textAlign: 'center' }">
<a-button
key=
"back"
@
click=
"visible = false"
>
返回
</a-button>
<a-button
key=
"submit"
type=
"primary"
:loading=
"stepLoading"
@
click=
"handleStepOk"
>
继续
</a-button>
</div>
</
template
>
<a-spin
:spinning=
"stepLoading"
>
<a-form
layout=
"vertical"
:auto-form-create=
"(form)=>{this.form = form}"
>
<p
style=
"text-align: center"
v-if=
"!stepLoading"
>
请在手机中打开 Google Authenticator 或两步验证 APP
<br
/>
输入 6 位动态码
</p>
<p
style=
"text-align: center"
v-else
>
正在验证..
<br/>
请稍后
</p>
<a-form-item
:style=
"{ textAlign: 'center' }"
hasFeedback
fieldDecoratorId=
"stepCode"
:fieldDecoratorOptions=
"{rules: [{ required: true, message: '请输入 6 位动态码!', pattern: /^\d{6}$/, len: 6 }]}"
>
<a-input
:style=
"{ textAlign: 'center' }"
placeholder=
"000000"
/>
</a-form-item>
<p
style=
"text-align: center"
>
<a
@
click=
"onForgeStepCode"
>
遗失手机?
</a>
</p>
</a-form>
</a-spin>
</a-modal>
</template>
<
script
>
export
default
{
props
:
{
visible
:
{
type
:
Boolean
,
default
:
false
}
},
data
()
{
return
{
stepLoading
:
false
,
form
:
null
};
},
methods
:
{
handleStepOk
()
{
const
vm
=
this
this
.
stepLoading
=
true
this
.
form
.
validateFields
((
err
,
values
)
=>
{
if
(
!
err
)
{
console
.
log
(
'values'
,
values
)
setTimeout
(
()
=>
{
vm
.
stepLoading
=
false
vm
.
$emit
(
'success'
,
{
values
})
},
2000
)
return
;
}
this
.
stepLoading
=
false
this
.
$emit
(
'error'
,
{
err
})
})
},
handleCancel
()
{
},
onForgeStepCode
()
{
}
}
};
</
script
>
\ No newline at end of file
src/views/Login.vue
View file @
e60479eb
<
template
>
<div>
<a-form
class=
"user-layout-login"
ref=
"formLogin"
:autoFormCreate=
"(form)=>
{this.form = form}" id="formLogin">
<a-tabs
:activeKey=
"customActiveKey"
...
...
@@ -81,23 +82,31 @@
注册账户
</router-link>
</div>
</a-form>
<two-step-captcha
v-if=
"requiredTwoStepCaptcha"
:visible=
"stepCaptchaVisible"
@
success=
"stepCaptchaSuccess"
></two-step-captcha>
</div>
</
template
>
<
script
>
import
md5
from
"md5"
import
api
from
'@/api/'
import
TwoStepCaptcha
from
'@/components/tools/TwoStepCaptcha'
import
{
mapActions
}
from
"vuex"
import
{
timeFix
}
from
"@/utils/util"
export
default
{
components
:
{
TwoStepCaptcha
},
data
()
{
return
{
customActiveKey
:
"tab1"
,
loginBtn
:
false
,
// login type: 0 email, 1 username, 2 telephone
loginType
:
0
,
requiredTwoStepCaptcha
:
true
,
stepCaptchaVisible
:
false
,
form
:
null
,
state
:
{
time
:
60
,
...
...
@@ -112,6 +121,18 @@
},
}
},
created
()
{
/*
this.$http.get('/auth/2step-code')
.then(res => {
this.requiredTwoStepCaptcha = res.result
}).catch(err => {
console.log('2step-code:', err)
})
*/
this
.
requiredTwoStepCaptcha
=
true
},
methods
:
{
...
mapActions
([
"Login"
]),
// handler
...
...
@@ -171,9 +192,11 @@
}
that
.
Login
(
loginParams
).
then
(()
=>
{
that
.
loginBtn
=
false
that
.
$router
.
push
({
name
:
"dashboard"
})
that
.
$message
.
success
(
timeFix
()
+
',欢迎回来'
,
3
)
if
(
that
.
requiredTwoStepCaptcha
)
{
that
.
stepCaptchaVisible
=
true
}
else
{
that
.
loginSuccess
()
}
}).
catch
((
err
)
=>
{
that
.
requestFailed
(
err
);
})
...
...
@@ -217,6 +240,14 @@
}
);
},
stepCaptchaSuccess
()
{
this
.
loginSuccess
()
},
loginSuccess
()
{
this
.
loginBtn
=
false
this
.
$router
.
push
({
name
:
"dashboard"
})
this
.
$message
.
success
(
timeFix
()
+
',欢迎回来'
,
3
)
},
requestFailed
(
err
)
{
this
.
$notification
[
'error'
]({
message
:
'错误'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment