Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-blk
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
1
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
shijian
8 years ago
Commit
b589853adf0117252c962eea38aa5d565e00f3f6
1 parent
e9ffba82
bug修改
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
31 deletions
apps/passport/controllers/reg.js
apps/passport/models/login-auth-service.js
apps/passport/controllers/reg.js
View file @
b589853
...
...
@@ -157,8 +157,8 @@ let sendBindMsg = (req, res, next) => {
// let checkNum = yield cache.get(`regCheckMobileNum_${mobile}`);
// 检查上次的发送短信号码
if
(
req
.
session
.
sendMobile
&&
req
.
session
.
sendMobile
!==
mobile
)
{
req
.
session
.
sendMobile
=
''
;
if
(
req
.
session
.
sendMobile_reg
&&
req
.
session
.
sendMobile_reg
!==
mobile
)
{
req
.
session
.
sendMobile_reg
=
''
;
req
.
session
.
captcha
=
''
;
data
.
message
=
'验证码失效'
;
return
res
.
json
(
data
);
...
...
@@ -180,7 +180,7 @@ let sendBindMsg = (req, res, next) => {
return
cache
.
set
(
sendCodeKey
,
sendCodeTimes
+
1
,
3600
).
then
(()
=>
{
if
(
result
.
code
)
{
// 记录发送短信的号码
req
.
session
.
sendMobile
=
mobile
;
req
.
session
.
sendMobile
_reg
=
mobile
;
return
res
.
json
(
result
);
}
else
{
data
.
message
=
'发送失败'
;
...
...
apps/passport/models/login-auth-service.js
View file @
b589853
...
...
@@ -21,10 +21,17 @@ const config = global.yoho.config;
const
helpers
=
global
.
yoho
.
helpers
;
const
cookie
=
global
.
yoho
.
cookie
;
const
logger
=
global
.
yoho
.
logger
;
const
cache
=
global
.
yoho
.
cache
;
let
siteUrl
=
config
.
siteUrl
.
indexOf
(
'//'
)
===
0
?
'http:'
+
config
.
siteUrl
:
config
.
siteUrl
;
function
getLoginStat
(
ip
)
{
let
errorLoginKey
=
'loginErrorIp:'
+
ip
;
return
cache
.
get
(
errorLoginKey
);
}
// 本地登录
passport
.
use
(
'local'
,
new
LocalStrategy
({
usernameField
:
'account'
,
...
...
@@ -33,47 +40,67 @@ passport.use('local', new LocalStrategy({
},
(
req
,
username
,
password
,
done
)
=>
{
let
area
=
req
.
body
.
areaCode
||
'86'
;
let
type
=
req
.
body
.
loginType
;
let
clientIp
=
req
.
yoho
.
clientIp
;
let
errorLoginKey
=
'loginErrorIp:'
+
clientIp
;
if
(
isNaN
(
_
.
parseInt
(
area
))
||
_
.
isEmpty
(
username
)
||
_
.
isEmpty
(
password
))
{
logger
.
info
(
`【
Passport
Login
】
bad
params
,
area
:
$
{
area
}
account
:
$
{
username
}
password
:
$
{
password
}
`
);
return
done
({
message
:
'登录参数错误'
},
null
);
}
return
getLoginStat
(
clientIp
).
then
((
times
)
=>
{
let
errLoginTimes
=
_
.
parseInt
(
times
)
||
0
;
let
verifyCode
=
req
.
body
.
captcha
;
let
verifyEmail
=
helpers
.
verifyEmail
(
username
);
let
verifyMobile
=
area
===
'86'
?
helpers
.
verifyAreaMobile
(
area
+
'-'
+
username
)
:
true
;
if
(
errLoginTimes
>
0
&&
type
!==
'SMSLogin'
)
{
if
(
!
verifyCode
||
verifyCode
!==
req
.
session
.
captcha
)
{
return
done
({
message
:
'验证码不正确或验证码过期'
,
needCaptcha
:
true
},
null
);
}
}
if
(
!
verifyEmail
&&
!
verifyMobile
)
{
logger
.
info
(
`【
Passport
Login
】
bad
account
,
email
:
$
{
verifyEmail
}
mobile
:
$
{
verifyMobile
}
`
);
return
done
({
message
:
'登录账号格式错误'
},
null
);
}
let
expire
=
req
.
cookies
[
'LE'
+
md5
(
'_LOGIN_EXPIRE'
)]
||
''
;
if
(
isNaN
(
_
.
parseInt
(
area
))
||
_
.
isEmpty
(
username
)
||
_
.
isEmpty
(
password
))
{
logger
.
info
(
`【
Passport
Login
】
bad
params
,
area
:
$
{
area
}
account
:
$
{
username
}
password
:
$
{
password
}
`
);
return
done
({
message
:
'登录参数错误'
},
null
);
}
if
(
expire
&&
expire
<
(
new
Date
()).
getTime
()
/
1000
)
{
return
done
({
message
:
'页面停留时间过长,请刷新页面'
},
null
);
}
let
verifyEmail
=
helpers
.
verifyEmail
(
username
);
let
verifyMobile
=
area
===
'86'
?
helpers
.
verifyAreaMobile
(
area
+
'-'
+
username
)
:
true
;
let
verifyCode
=
req
.
body
.
captcha
;
if
(
!
verifyEmail
&&
!
verifyMobile
)
{
logger
.
info
(
`【
Passport
Login
】
bad
account
,
email
:
$
{
verifyEmail
}
mobile
:
$
{
verifyMobile
}
`
);
return
done
({
message
:
'登录账号格式错误'
},
null
);
}
if
(
type
!==
'SMSLogin'
&&
verifyCode
&&
verifyCode
!==
req
.
session
.
captcha
)
{
return
done
({
message
:
'验证码不正确或验证码过期'
,
needCaptcha
:
true
},
null
);
}
let
expire
=
req
.
cookies
[
'LE'
+
md5
(
'_LOGIN_EXPIRE'
)]
||
''
;
if
(
expire
&&
expire
<
(
new
Date
()).
getTime
()
/
1000
)
{
return
done
({
message
:
'页面停留时间过长,请刷新页面'
},
null
);
}
let
shoppingKey
=
cookie
.
getShoppingKey
(
req
);
return
LoginService
.
signin
(
type
,
area
,
username
,
password
,
shoppingKey
,
req
).
then
((
result
)
=>
{
if
(
result
.
code
&&
result
.
code
===
200
&&
result
.
data
.
uid
)
{
done
(
null
,
result
.
data
);
}
else
{
done
({
message
:
'请输入正确的账号或密码'
,
needCaptcha
:
true
});
if
(
type
!==
'SMSLogin'
&&
verifyCode
&&
verifyCode
!==
req
.
session
.
captcha
)
{
return
done
({
message
:
'验证码不正确或验证码过期'
,
needCaptcha
:
true
},
null
);
}
let
shoppingKey
=
cookie
.
getShoppingKey
(
req
);
return
LoginService
.
signin
(
type
,
area
,
username
,
password
,
shoppingKey
,
req
).
then
((
result
)
=>
{
if
(
result
.
code
&&
result
.
code
===
200
&&
result
.
data
.
uid
)
{
cache
.
del
(
errorLoginKey
).
catch
(()
=>
{});
done
(
null
,
result
.
data
);
}
else
{
cache
.
set
(
errorLoginKey
,
errLoginTimes
+
1
,
3600
).
catch
(()
=>
{});
done
({
message
:
'请输入正确的账号或密码'
,
needCaptcha
:
true
});
}
}).
catch
(
e
=>
{
logger
.
error
(
'call the signin service fail,'
,
e
);
done
(
'登录失败,请稍后重试'
,
null
);
});
}).
catch
(
e
=>
{
logger
.
error
(
'call the signin service fail,'
,
e
);
done
(
'登录失败,请稍后重试'
,
null
);
return
done
(
'登录失败,请稍后重试'
,
null
);
});
}));
/**
...
...
Please
register
or
login
to post a comment