Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuywap-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Plain Diff
Browse Files
Authored by
陈峰
8 years ago
Commit
79abee51063c107c290de55c85209743631b680a
2 parents
af0738c3
8ca5c762
Merge branch 'feature/weiBinding' into 'gray'
Feature/wei binding See merge request
!234
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
33 deletions
apps/passport/controllers/bind.js
apps/passport/router.js
apps/passport/views/action/bind/index.hbs
package.json
public/js/passport/bind/bind.js
public/js/passport/code.js
apps/passport/controllers/bind.js
View file @
79abee5
...
...
@@ -12,6 +12,8 @@ const RegService = require('../models/reg-service');
const
BindService
=
require
(
'../models/bind-service'
);
const
AuthHelper
=
require
(
'../models/auth-helper'
);
const
_
=
require
(
'lodash'
);
const
config
=
global
.
yoho
.
config
;
const
moment
=
require
(
'moment'
);
const
Sources
=
{
qq
:
'QQ'
,
...
...
@@ -87,32 +89,57 @@ const bind = {
let
openId
=
req
.
body
.
openId
;
let
areaCode
=
req
.
body
.
areaCode
||
'86'
;
let
sourceType
=
req
.
body
.
sourceType
;
let
verify
=
req
.
body
.
verify
||
''
;
let
testCode
=
req
.
body
.
yohobuy
;
if
(
_
.
isNumber
(
parseInt
(
phoneNum
,
0
))
&&
openId
&&
areaCode
&&
sourceType
)
{
BindService
.
bindCheck
(
phoneNum
,
openId
,
sourceType
,
areaCode
).
then
(
result
=>
{
let
data
=
{
code
:
result
.
code
,
message
:
result
.
message
,
data
:
{}
};
if
(
result
.
code
===
200
)
{
let
nextUrl
=
helpers
.
urlFormat
(
'/passport/bind/code'
,
{
isReg
:
result
.
data
.
is_register
,
// esline-disable-line
openId
:
openId
,
sourceType
:
sourceType
,
areaCode
:
areaCode
,
phoneNum
:
phoneNum
});
data
.
data
.
isReg
=
result
.
data
.
is_register
;
data
.
data
.
next
=
nextUrl
;
if
(
verify
)
{
let
captcha
=
_
.
get
(
req
,
'session.captcha'
);
if
((
captcha
&&
verify
.
toString
()
===
captcha
)
||
(
testCode
===
config
.
testCode
))
{
BindService
.
bindCheck
(
phoneNum
,
openId
,
sourceType
,
areaCode
).
then
(
result
=>
{
let
data
=
{
code
:
result
.
code
,
message
:
result
.
message
,
data
:
{}
};
if
(
result
.
code
===
200
)
{
let
nextUrl
=
helpers
.
urlFormat
(
'/passport/bind/code'
,
{
isReg
:
result
.
data
.
is_register
,
// esline-disable-line
openId
:
openId
,
sourceType
:
sourceType
,
areaCode
:
areaCode
,
phoneNum
:
phoneNum
});
data
.
data
.
isReg
=
result
.
data
.
is_register
;
data
.
data
.
next
=
nextUrl
;
_
.
set
(
req
.
session
,
'bind.area'
,
areaCode
);
_
.
set
(
req
.
session
,
'bind.phoneNum'
,
phoneNum
);
}
else
{
data
.
data
=
result
.
data
;
}
res
.
json
(
data
);
}).
catch
(
next
);
}
else
{
data
.
data
=
result
.
data
;
let
jsonData
=
{
code
:
400
,
message
:
'请将图片旋转到正确位置'
};
if
(
req
.
session
.
captchaValidCount
===
0
)
{
req
.
session
.
captcha
=
null
;
// 验证码 用过就扔
jsonData
.
changeCaptcha
=
true
;
}
return
res
.
json
(
jsonData
);
}
res
.
json
(
data
);
}).
catch
(
next
);
_
.
set
(
req
.
session
,
'captcha'
,
null
);
}
}
else
{
res
.
json
({
code
:
400
,
...
...
@@ -122,13 +149,62 @@ const bind = {
}
},
// 防刷
sendBefore
:
(
req
,
res
,
next
)
=>
{
let
count
=
_
.
get
(
req
.
session
,
'bind.count'
);
let
interval
=
_
.
get
(
req
.
session
,
'bind.interval'
);
let
now
=
Date
.
now
();
// // 重发次数用完了, 会冻结5min
// // 1. 过了冻结期, count 重设为 5次
// // 2. 没过冻结期, end
// // 没有用完, 判断是否请求太频繁
let
during
=
moment
.
duration
(
interval
-
now
,
'ms'
).
minutes
();
let
message
=
`请
$
{
during
}
分钟后再试`
;
if
(
!
count
)
{
if
(
interval
>
now
)
{
return
res
.
json
({
code
:
400
,
message
:
message
,
during
:
Math
.
ceil
((
interval
-
now
)
/
1000
)
});
}
else
{
_
.
set
(
req
.
session
,
'bind.count'
,
5
);
}
}
else
if
(
interval
>
now
)
{
return
res
.
json
({
code
:
429
,
message
:
message
});
}
next
();
},
sendBindMsg
:
(
req
,
res
,
next
)
=>
{
let
phoneNum
=
req
.
body
.
phoneNum
;
let
areaCode
=
req
.
body
.
areaCode
;
let
phoneNum
=
_
.
get
(
req
.
session
,
'bind.phoneNum'
);
let
areaCode
=
_
.
get
(
req
.
session
,
'bind.area'
);
if
(
req
.
xhr
&&
_
.
isNumber
(
parseInt
(
phoneNum
,
0
))
&&
areaCode
)
{
BindService
.
sendBindMsg
(
areaCode
,
phoneNum
).
then
(
result
=>
{
if
(
result
&&
result
.
code
)
{
if
(
result
.
code
===
200
)
{
_
.
set
(
req
.
session
,
'bind.area'
,
areaCode
);
_
.
set
(
req
.
session
,
'bind.phoneNum'
,
phoneNum
);
--
req
.
session
.
bind
.
count
;
if
(
!
req
.
session
.
bind
.
count
)
{
_
.
set
(
req
.
session
,
'bind.interval'
,
Date
.
now
()
+
5
*
60
*
1000
);
}
else
{
_
.
set
(
req
.
session
,
'bind.interval'
,
Date
.
now
()
+
60
*
1000
);
}
}
res
.
json
(
result
);
}
else
{
res
.
json
({
code
:
400
,
message
:
''
,
data
:
''
});
...
...
apps/passport/router.js
View file @
79abee5
...
...
@@ -77,7 +77,9 @@ router.get('/login/alipay/callback', login.alipay.callback);
router
.
get
(
'/passport/bind/index'
,
bind
.
indexPage
);
router
.
post
(
'/passport/bind/bindCheck'
,
bind
.
bindCheck
);
router
.
get
(
'/passport/bind/code'
,
bind
.
codePage
);
router
.
post
(
'/passport/bind/sendBindMsg'
,
bind
.
sendBindMsg
);
router
.
post
(
'/passport/bind/sendBindMsg'
,
bind
.
sendBefore
,
bind
.
sendBindMsg
);
router
.
post
(
'/passport/bind/bindMobile'
,
bind
.
bindMobile
);
router
.
post
(
'/passport/bind/relateMobile'
,
bind
.
relateMobile
);
...
...
apps/passport/views/action/bind/index.hbs
View file @
79abee5
...
...
@@ -14,6 +14,13 @@
<span
id=
"area-code"
class=
"area-code"
>
{{
areaCode
}}
</span>
<input
id=
"phone-num"
class=
"input phone-num"
type=
"text"
placeholder=
"手机号"
>
</div>
{{!--图片验证 start--}}
<div
id=
"js-img-check"
>
<input
type=
"hidden"
name=
"captsrc"
value=
"
{{
captsrc
}}
"
>
</div>
{{!--图片验证 end--}}
<span
id=
"btn-next"
class=
"btn btn-next disable row"
>
发送验证码
</span>
{{#if
isWechatLogin
}}
...
...
package.json
View file @
79abee5
{
"name"
:
"m-yohobuy-node"
,
"version"
:
"93.4.1
0
"
,
"version"
:
"93.4.1
1
"
,
"private"
:
true
,
"description"
:
"A New Yohobuy Project With Express"
,
"repository"
:
{
...
...
public/js/passport/bind/bind.js
View file @
79abee5
...
...
@@ -24,6 +24,17 @@ var requested = false;
require
(
'../../common'
);
var
ImgCheck
=
require
(
'plugin/img-check'
);
var
imgCheck
=
new
ImgCheck
(
'#js-img-check'
,
{
useREM
:
{
rootFontSize
:
40
,
picWidth
:
150
}
});
imgCheck
.
init
();
function
nextStep
(
url
,
mobileNo
,
areaCode
)
{
if
(
requested
)
{
return
false
;
...
...
@@ -31,7 +42,6 @@ function nextStep(url, mobileNo, areaCode) {
requested
=
true
;
$btnNext
.
addClass
(
'disable'
).
html
(
'绑定中...'
);
$
.
ajax
({
type
:
'POST'
,
url
:
'/passport/bind/sendBindMsg'
,
...
...
@@ -85,7 +95,8 @@ $btnNext.on('touchstart', function() {
openId
=
trim
(
$openId
.
val
()),
nickname
=
trim
(
$nickname
.
val
()),
sourceType
=
trim
(
$sourceType
.
val
()),
areaCode
=
$countrySelect
.
val
();
areaCode
=
$countrySelect
.
val
(),
verify
=
trim
(
imgCheck
.
getResults
());
if
(
$btnNext
.
hasClass
(
'disable'
))
{
return
;
...
...
@@ -100,12 +111,11 @@ $btnNext.on('touchstart', function() {
phoneNum
:
pn
,
openId
:
openId
,
sourceType
:
sourceType
,
nickname
:
nickname
nickname
:
nickname
,
verify
:
verify
},
success
:
function
(
res
)
{
// console.log(res);
// res : {
// code: 'xxx',
// data: {
...
...
public/js/passport/code.js
View file @
79abee5
...
...
@@ -5,6 +5,8 @@
*/
var
$
=
require
(
'yoho-jquery'
);
require
(
'js/common'
);
module
.
exports
=
function
(
useInRegister
,
useForBind
,
useForRelate
)
{
var
$captcha
=
$
(
'#captcha'
),
$btnNext
=
$
(
'#btn-next'
),
...
...
@@ -79,8 +81,8 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
});
}
function
countDown
()
{
var
count
=
59
,
function
countDown
(
during
)
{
var
count
=
during
||
59
,
itime
;
itime
=
setInterval
(
function
()
{
...
...
@@ -89,6 +91,11 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
clearInterval
(
itime
);
}
else
{
$captchaTip
.
text
(
'重新发送 ('
+
count
--
+
'秒)'
);
window
.
setCookie
(
'count'
,
count
);
if
(
during
&&
parseInt
(
during
)
!==
0
)
{
$captchaTip
.
addClass
(
'disable'
);
}
}
},
1000
);
}
...
...
@@ -121,6 +128,7 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
$captchaTip
.
text
(
'重发验证码 (60秒)'
).
addClass
(
'disable'
);
countDown
();
}
else
{
data
.
during
&&
countDown
(
data
.
during
);
// 验证码不正确,显示提示
showErrTip
(
data
.
message
);
...
...
@@ -148,5 +156,10 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
}
});
countDown
();
if
(
window
.
cookie
(
'count'
)
&&
parseInt
(
window
.
cookie
(
'count'
))
>
0
)
{
countDown
(
window
.
cookie
(
'count'
));
}
else
{
countDown
();
}
};
...
...
Please
register
or
login
to post a comment