Authored by 郝肖肖

弱密码接口

... ... @@ -67,10 +67,10 @@ passport.use('local', new LocalStrategy({
done({message: '您的账号已被暂时锁定,请稍后再试'}, null);
} else {
return LoginApi.signin(type, area, username, password, shoppingKey, clientIp).then((result) => {
if (result.code && result.code === 200 && result.data.uid) {
if (result.code && (result.code === 200 || result.code === 510) && result.data.uid) {
cache.del(errorLoginKey).catch(() => {});
done(null, result.data);
done(null, Object.assign(result.data, {code: result.code}));
} else {
errLoginTimes = errLoginTimes + 1;
accountTimes = accountTimes + 1;
... ...
... ... @@ -453,6 +453,19 @@ const weakPwdSuccessPage = (req, res, next) => {
.catch(next);
};
const modPwdByCodeAPI = (req, res, next) => {
let body = req.body;
service.modPwdByCodeAsync({
uid: req.use.uid,
oldPwd: body.oldPwd,
newPwd: body.newPwd,
token: req.cookies.CSToken,
}).then(d => {
res.json(d);
}).catch(next);
};
module.exports = {
index, // 首页
fakeGetUserInfoAPI, // 通过邮箱或手机号获得用户信息
... ... @@ -486,6 +499,7 @@ module.exports = {
validatePwdPage, // 验证密码是否合法
weakPasswordPage, // 弱密码页面
weakPwdSuccessPage // 弱密码重置成功页面
weakPwdSuccessPage, // 弱密码重置成功页面
modPwdByCodeAPI // 弱密码重置接口
};
... ...
... ... @@ -212,7 +212,7 @@ const bind = {
sourceType: sourceType + '_bind'
});
return loginService.syncUserSession(result.data.uid, req, res, result.data.session_key).then(() => {
return loginService.syncUserSession(result.data, req, res).then(() => {
return {code: 200, message: result.message, data: {refer: refer}};
});
} else {
... ... @@ -247,10 +247,9 @@ const bind = {
});
return loginService.syncUserSession(
result.data.uid,
result.data,
req,
res,
result.data.session_key
res
).then(() => {
return {code: 200, message: result.message, data: {refer: refer}};
});
... ...
... ... @@ -67,7 +67,7 @@ function doPassportCallback(req, res, user) {
});
} else if (result.data['is_bind'] === 'Y' && result.data.uid) {//eslint-disable-line
return loginService.syncUserSession(result.data.uid, req, res, result.data.session_key).then(() => {
return loginService.syncUserSession(result.data, req, res).then(() => {
return refer;
});
}
... ... @@ -166,6 +166,7 @@ const local = {
},
login: (req, res, next) => {
passport.authenticate('local', (err, user) => {
console.log(err, user, ' === ');
if (err) {
return res.json({
code: 400,
... ... @@ -198,9 +199,11 @@ const local = {
}
}());
loginService.syncUserSession(user.uid, req, res, user.session_key).then((noCertTip) => {
if (noCertTip === true) {
loginService.syncUserSession(user, req, res).then((noCertTip) => {
// 弱密码
if (user.code === 510) {
refer = `${config.siteUrl}/passport/back/weak?token=${user.token}&refer=${refer}`;
} else if (noCertTip === true) {
refer = `${config.siteUrl}/passport/cert/tip?refer=${refer}`;
}
... ...
... ... @@ -282,7 +282,7 @@ let mobileRegister = (req, res, next) => {
// 清除 session type
req.session.type = '';
return loginService.syncUserSession(regResult.data.uid, req, res, regResult.data.session_key).then(() => {
return loginService.syncUserSession(regResult.data, req, res).then(() => {
return res.json({
code: 200,
message: '注册成功',
... ...
... ... @@ -161,6 +161,10 @@ const modifyPasswordByEmailCodeAsyncAes = (code, password) => {
});
};
const modPwdByCodeAsync = (params) => {
return api.get('', Object.assign({method: 'app.password.modPwdByCode'}, params));
};
module.exports = {
getAreaDataAsync,
sendCodeToEmailAsync,
... ... @@ -171,5 +175,6 @@ module.exports = {
modifyPasswordByMobileAsyncAes,
checkEmailCodeAsync,
modifyPasswordByEmailCodeAsync,
modifyPasswordByEmailCodeAsyncAes
modifyPasswordByEmailCodeAsyncAes,
modPwdByCodeAsync
};
... ...
... ... @@ -211,6 +211,9 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
*/
const checkEmailCodeAsync = api.checkEmailCodeAsync;
// 弱密码重置
const modPwdByCodeAsync = api.modPwdByCodeAsync;
module.exports = {
validateEmailOrMobileAsync,
findUserAsync,
... ... @@ -220,5 +223,6 @@ module.exports = {
verifyCodyByMobileAsync,
authRequest,
updatePwdAsync,
checkEmailCodeAsync
checkEmailCodeAsync,
modPwdByCodeAsync
};
... ...
... ... @@ -30,7 +30,10 @@ const signin = (type, area, profile, password, shoppingKey, clientIp) => {
return loginBy[type](area, profile, password, shoppingKey, clientIp);
};
const syncUserSession = (uid, req, res, sessionKey) => {
const syncUserSession = (user, req, res) => {
let uid = user.uid;
let sessionKey = user.session_key;
if (sessionKey) {
cache.set(`java_session_key:${uid}`, sessionKey).catch(() => {
logger.error('write session key fail');
... ... @@ -97,6 +100,14 @@ const syncUserSession = (uid, req, res, sessionKey) => {
httpOnly: true
});
if (user.canSkip && user.token) {
res.cookie('canSkip', user.canSkip, {
domain: config.cookieDomain
});
res.cookie('CSToken', user.token, {
domain: config.cookieDomain
});
}
if (isTipCert && isTipCert.code === 200 && isTipCert.data) {
return isTipCert.data.isNeedPopupRelated === 'Y';
}
... ...
... ... @@ -163,7 +163,7 @@ router.post('/passport/back/backMobile', back.verifyCodeByMobileAPI);
* 重置密码
*/
// 重置密码页面
// 重置密码页面
router.get('/passport/back/backcode',
back.validateExistCodePage,
back.validateCodeByMobilePage,
... ... @@ -185,7 +185,9 @@ router.get('/passport/back/resetSuccess',
router.get('/passport/images.png', captcha.generate);
router.post('/passport/captcha/img', captcha.checkAPI);
router.get('/passport/back/weak', back.weakPasswordPage);
// 弱密码
router.get('/passport/back/weak', auth, back.weakPasswordPage);
router.post('/passport/back/modPwdByCodeAPI', auth, back.modPwdByCodeAPI);
// 重置密码成功页面
router.get('/passport/back/weakSuccess',
... ...
... ... @@ -11,7 +11,7 @@ const isTest = process.env.NODE_ENV === 'test';
module.exports = {
app: 'web',
appVersion: '5.5.1', // 调用api的版本
appVersion: '5.6.1', // 调用api的版本
port: 6002,
siteUrl: 'http://www.yohobuy.com',
cookieDomain: '.yohobuy.com',
... ...