Authored by 郝肖肖

弱密码接口

@@ -67,10 +67,10 @@ passport.use('local', new LocalStrategy({ @@ -67,10 +67,10 @@ passport.use('local', new LocalStrategy({
67 done({message: '您的账号已被暂时锁定,请稍后再试'}, null); 67 done({message: '您的账号已被暂时锁定,请稍后再试'}, null);
68 } else { 68 } else {
69 return LoginApi.signin(type, area, username, password, shoppingKey, clientIp).then((result) => { 69 return LoginApi.signin(type, area, username, password, shoppingKey, clientIp).then((result) => {
70 - if (result.code && result.code === 200 && result.data.uid) { 70 + if (result.code && (result.code === 200 || result.code === 510) && result.data.uid) {
71 cache.del(errorLoginKey).catch(() => {}); 71 cache.del(errorLoginKey).catch(() => {});
72 72
73 - done(null, result.data); 73 + done(null, Object.assign(result.data, {code: result.code}));
74 } else { 74 } else {
75 errLoginTimes = errLoginTimes + 1; 75 errLoginTimes = errLoginTimes + 1;
76 accountTimes = accountTimes + 1; 76 accountTimes = accountTimes + 1;
@@ -453,6 +453,19 @@ const weakPwdSuccessPage = (req, res, next) => { @@ -453,6 +453,19 @@ const weakPwdSuccessPage = (req, res, next) => {
453 .catch(next); 453 .catch(next);
454 }; 454 };
455 455
  456 +const modPwdByCodeAPI = (req, res, next) => {
  457 + let body = req.body;
  458 +
  459 + service.modPwdByCodeAsync({
  460 + uid: req.use.uid,
  461 + oldPwd: body.oldPwd,
  462 + newPwd: body.newPwd,
  463 + token: req.cookies.CSToken,
  464 + }).then(d => {
  465 + res.json(d);
  466 + }).catch(next);
  467 +};
  468 +
456 module.exports = { 469 module.exports = {
457 index, // 首页 470 index, // 首页
458 fakeGetUserInfoAPI, // 通过邮箱或手机号获得用户信息 471 fakeGetUserInfoAPI, // 通过邮箱或手机号获得用户信息
@@ -486,6 +499,7 @@ module.exports = { @@ -486,6 +499,7 @@ module.exports = {
486 validatePwdPage, // 验证密码是否合法 499 validatePwdPage, // 验证密码是否合法
487 500
488 weakPasswordPage, // 弱密码页面 501 weakPasswordPage, // 弱密码页面
489 - weakPwdSuccessPage // 弱密码重置成功页面 502 + weakPwdSuccessPage, // 弱密码重置成功页面
  503 + modPwdByCodeAPI // 弱密码重置接口
490 }; 504 };
491 505
@@ -212,7 +212,7 @@ const bind = { @@ -212,7 +212,7 @@ const bind = {
212 sourceType: sourceType + '_bind' 212 sourceType: sourceType + '_bind'
213 }); 213 });
214 214
215 - return loginService.syncUserSession(result.data.uid, req, res, result.data.session_key).then(() => { 215 + return loginService.syncUserSession(result.data, req, res).then(() => {
216 return {code: 200, message: result.message, data: {refer: refer}}; 216 return {code: 200, message: result.message, data: {refer: refer}};
217 }); 217 });
218 } else { 218 } else {
@@ -247,10 +247,9 @@ const bind = { @@ -247,10 +247,9 @@ const bind = {
247 }); 247 });
248 248
249 return loginService.syncUserSession( 249 return loginService.syncUserSession(
250 - result.data.uid, 250 + result.data,
251 req, 251 req,
252 - res,  
253 - result.data.session_key 252 + res
254 ).then(() => { 253 ).then(() => {
255 return {code: 200, message: result.message, data: {refer: refer}}; 254 return {code: 200, message: result.message, data: {refer: refer}};
256 }); 255 });
@@ -67,7 +67,7 @@ function doPassportCallback(req, res, user) { @@ -67,7 +67,7 @@ function doPassportCallback(req, res, user) {
67 }); 67 });
68 } else if (result.data['is_bind'] === 'Y' && result.data.uid) {//eslint-disable-line 68 } else if (result.data['is_bind'] === 'Y' && result.data.uid) {//eslint-disable-line
69 69
70 - return loginService.syncUserSession(result.data.uid, req, res, result.data.session_key).then(() => { 70 + return loginService.syncUserSession(result.data, req, res).then(() => {
71 return refer; 71 return refer;
72 }); 72 });
73 } 73 }
@@ -166,6 +166,7 @@ const local = { @@ -166,6 +166,7 @@ const local = {
166 }, 166 },
167 login: (req, res, next) => { 167 login: (req, res, next) => {
168 passport.authenticate('local', (err, user) => { 168 passport.authenticate('local', (err, user) => {
  169 + console.log(err, user, ' === ');
169 if (err) { 170 if (err) {
170 return res.json({ 171 return res.json({
171 code: 400, 172 code: 400,
@@ -198,9 +199,11 @@ const local = { @@ -198,9 +199,11 @@ const local = {
198 } 199 }
199 }()); 200 }());
200 201
201 - loginService.syncUserSession(user.uid, req, res, user.session_key).then((noCertTip) => {  
202 -  
203 - if (noCertTip === true) { 202 + loginService.syncUserSession(user, req, res).then((noCertTip) => {
  203 + // 弱密码
  204 + if (user.code === 510) {
  205 + refer = `${config.siteUrl}/passport/back/weak?token=${user.token}&refer=${refer}`;
  206 + } else if (noCertTip === true) {
204 refer = `${config.siteUrl}/passport/cert/tip?refer=${refer}`; 207 refer = `${config.siteUrl}/passport/cert/tip?refer=${refer}`;
205 } 208 }
206 209
@@ -282,7 +282,7 @@ let mobileRegister = (req, res, next) => { @@ -282,7 +282,7 @@ let mobileRegister = (req, res, next) => {
282 // 清除 session type 282 // 清除 session type
283 req.session.type = ''; 283 req.session.type = '';
284 284
285 - return loginService.syncUserSession(regResult.data.uid, req, res, regResult.data.session_key).then(() => { 285 + return loginService.syncUserSession(regResult.data, req, res).then(() => {
286 return res.json({ 286 return res.json({
287 code: 200, 287 code: 200,
288 message: '注册成功', 288 message: '注册成功',
@@ -161,6 +161,10 @@ const modifyPasswordByEmailCodeAsyncAes = (code, password) => { @@ -161,6 +161,10 @@ const modifyPasswordByEmailCodeAsyncAes = (code, password) => {
161 }); 161 });
162 }; 162 };
163 163
  164 +const modPwdByCodeAsync = (params) => {
  165 + return api.get('', Object.assign({method: 'app.password.modPwdByCode'}, params));
  166 +};
  167 +
164 module.exports = { 168 module.exports = {
165 getAreaDataAsync, 169 getAreaDataAsync,
166 sendCodeToEmailAsync, 170 sendCodeToEmailAsync,
@@ -171,5 +175,6 @@ module.exports = { @@ -171,5 +175,6 @@ module.exports = {
171 modifyPasswordByMobileAsyncAes, 175 modifyPasswordByMobileAsyncAes,
172 checkEmailCodeAsync, 176 checkEmailCodeAsync,
173 modifyPasswordByEmailCodeAsync, 177 modifyPasswordByEmailCodeAsync,
174 - modifyPasswordByEmailCodeAsyncAes 178 + modifyPasswordByEmailCodeAsyncAes,
  179 + modPwdByCodeAsync
175 }; 180 };
@@ -211,6 +211,9 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => { @@ -211,6 +211,9 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
211 */ 211 */
212 const checkEmailCodeAsync = api.checkEmailCodeAsync; 212 const checkEmailCodeAsync = api.checkEmailCodeAsync;
213 213
  214 +// 弱密码重置
  215 +const modPwdByCodeAsync = api.modPwdByCodeAsync;
  216 +
214 module.exports = { 217 module.exports = {
215 validateEmailOrMobileAsync, 218 validateEmailOrMobileAsync,
216 findUserAsync, 219 findUserAsync,
@@ -220,5 +223,6 @@ module.exports = { @@ -220,5 +223,6 @@ module.exports = {
220 verifyCodyByMobileAsync, 223 verifyCodyByMobileAsync,
221 authRequest, 224 authRequest,
222 updatePwdAsync, 225 updatePwdAsync,
223 - checkEmailCodeAsync 226 + checkEmailCodeAsync,
  227 + modPwdByCodeAsync
224 }; 228 };
@@ -30,7 +30,10 @@ const signin = (type, area, profile, password, shoppingKey, clientIp) => { @@ -30,7 +30,10 @@ const signin = (type, area, profile, password, shoppingKey, clientIp) => {
30 return loginBy[type](area, profile, password, shoppingKey, clientIp); 30 return loginBy[type](area, profile, password, shoppingKey, clientIp);
31 }; 31 };
32 32
33 -const syncUserSession = (uid, req, res, sessionKey) => { 33 +const syncUserSession = (user, req, res) => {
  34 + let uid = user.uid;
  35 + let sessionKey = user.session_key;
  36 +
34 if (sessionKey) { 37 if (sessionKey) {
35 cache.set(`java_session_key:${uid}`, sessionKey).catch(() => { 38 cache.set(`java_session_key:${uid}`, sessionKey).catch(() => {
36 logger.error('write session key fail'); 39 logger.error('write session key fail');
@@ -97,6 +100,14 @@ const syncUserSession = (uid, req, res, sessionKey) => { @@ -97,6 +100,14 @@ const syncUserSession = (uid, req, res, sessionKey) => {
97 httpOnly: true 100 httpOnly: true
98 }); 101 });
99 102
  103 + if (user.canSkip && user.token) {
  104 + res.cookie('canSkip', user.canSkip, {
  105 + domain: config.cookieDomain
  106 + });
  107 + res.cookie('CSToken', user.token, {
  108 + domain: config.cookieDomain
  109 + });
  110 + }
100 if (isTipCert && isTipCert.code === 200 && isTipCert.data) { 111 if (isTipCert && isTipCert.code === 200 && isTipCert.data) {
101 return isTipCert.data.isNeedPopupRelated === 'Y'; 112 return isTipCert.data.isNeedPopupRelated === 'Y';
102 } 113 }
@@ -163,7 +163,7 @@ router.post('/passport/back/backMobile', back.verifyCodeByMobileAPI); @@ -163,7 +163,7 @@ router.post('/passport/back/backMobile', back.verifyCodeByMobileAPI);
163 * 重置密码 163 * 重置密码
164 */ 164 */
165 165
166 - // 重置密码页面 166 +// 重置密码页面
167 router.get('/passport/back/backcode', 167 router.get('/passport/back/backcode',
168 back.validateExistCodePage, 168 back.validateExistCodePage,
169 back.validateCodeByMobilePage, 169 back.validateCodeByMobilePage,
@@ -185,7 +185,9 @@ router.get('/passport/back/resetSuccess', @@ -185,7 +185,9 @@ router.get('/passport/back/resetSuccess',
185 router.get('/passport/images.png', captcha.generate); 185 router.get('/passport/images.png', captcha.generate);
186 router.post('/passport/captcha/img', captcha.checkAPI); 186 router.post('/passport/captcha/img', captcha.checkAPI);
187 187
188 -router.get('/passport/back/weak', back.weakPasswordPage); 188 +// 弱密码
  189 +router.get('/passport/back/weak', auth, back.weakPasswordPage);
  190 +router.post('/passport/back/modPwdByCodeAPI', auth, back.modPwdByCodeAPI);
189 191
190 // 重置密码成功页面 192 // 重置密码成功页面
191 router.get('/passport/back/weakSuccess', 193 router.get('/passport/back/weakSuccess',
@@ -11,7 +11,7 @@ const isTest = process.env.NODE_ENV === 'test'; @@ -11,7 +11,7 @@ const isTest = process.env.NODE_ENV === 'test';
11 11
12 module.exports = { 12 module.exports = {
13 app: 'web', 13 app: 'web',
14 - appVersion: '5.5.1', // 调用api的版本 14 + appVersion: '5.6.1', // 调用api的版本
15 port: 6002, 15 port: 6002,
16 siteUrl: 'http://www.yohobuy.com', 16 siteUrl: 'http://www.yohobuy.com',
17 cookieDomain: '.yohobuy.com', 17 cookieDomain: '.yohobuy.com',