...
|
...
|
@@ -5,9 +5,10 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
const library = '../../../library';
|
|
|
const helpers = require(`${library}/helpers`);
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const service = require('../models/back-service');
|
|
|
|
|
|
const SIGN_IN = helpers.urlFormat('/passport/login');
|
...
|
...
|
@@ -16,16 +17,18 @@ const SIGN_IN = helpers.urlFormat('/passport/login'); |
|
|
* 通过邮箱找回密码页面
|
|
|
*/
|
|
|
const indexEmailPage = (req, res) => {
|
|
|
res.render('back/email', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-email',
|
|
|
title : '找回密码-通过邮箱'
|
|
|
}, {
|
|
|
backUrl : SIGN_IN,
|
|
|
headerText : '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backEmail : true
|
|
|
}));
|
|
|
res.render('back/email', Object.assign(
|
|
|
{
|
|
|
module: 'passport',
|
|
|
page: 'back-email',
|
|
|
title: '找回密码-通过邮箱'
|
|
|
}, {
|
|
|
backUrl: SIGN_IN,
|
|
|
headerText: '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backEmail: true
|
|
|
}
|
|
|
));
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -34,9 +37,9 @@ const indexEmailPage = (req, res) => { |
|
|
const sendCodeToEmailAPI = (req, res) => {
|
|
|
let email = req.body.email || '';
|
|
|
const ERR = {
|
|
|
code : 400,
|
|
|
code: 400,
|
|
|
message: '邮箱格式不正确,请重新输入',
|
|
|
data : ''
|
|
|
data: ''
|
|
|
};
|
|
|
|
|
|
if (!helpers.verifyEmail(email)) {
|
...
|
...
|
@@ -47,7 +50,7 @@ const sendCodeToEmailAPI = (req, res) => { |
|
|
service.sendCodeToEmailAsync(email)
|
|
|
.then(result => {
|
|
|
if (result.code === 200) {
|
|
|
result.data = helpers.urlFormat('/passport/back/success', {email: email});
|
|
|
result.data = helpers.urlFormat('/passport/back/success', { email: email });
|
|
|
}
|
|
|
|
|
|
res.json(result);
|
...
|
...
|
@@ -73,7 +76,7 @@ const resendCodeToEmailAPI = (req, res) => { |
|
|
})
|
|
|
.catch(err => {
|
|
|
res.json({
|
|
|
code : 400,
|
|
|
code: 400,
|
|
|
message: err
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -89,28 +92,28 @@ const backSuccessByEmailPage = (req, res) => { |
|
|
res.redirect(400);
|
|
|
}
|
|
|
|
|
|
let domain = email.split('@')[1];
|
|
|
let domain = email.split('@')[1];
|
|
|
let emailUrl = `http://${domain === 'gmail.com' ? 'mail.google.com' : 'mail.'}${domain}`;
|
|
|
|
|
|
res.render('back/email-success', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-email-success',
|
|
|
title : '找回密码-通过邮箱'
|
|
|
page: 'back-email-success',
|
|
|
title: '找回密码-通过邮箱'
|
|
|
}, {
|
|
|
backUrl : helpers.urlFormat('/passport/back/email'),
|
|
|
headerText : '找回密码',
|
|
|
isPassportPage : true,
|
|
|
backEmailSuccess: true,
|
|
|
goEmail : emailUrl,
|
|
|
resendUrl : helpers.urlFormat('/passport/back/resendemail', {email: email})
|
|
|
}));
|
|
|
backUrl: helpers.urlFormat('/passport/back/email'),
|
|
|
headerText: '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backEmailSuccess: true,
|
|
|
goEmail: emailUrl,
|
|
|
resendUrl: helpers.urlFormat('/passport/back/resendemail', { email: email })
|
|
|
}));
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 根据邮箱修改密码
|
|
|
*/
|
|
|
const setNewPasswordByEmailAPI = (req, res) => {
|
|
|
let pwd = req.body.password || '';
|
|
|
let pwd = req.body.password || '';
|
|
|
let code = req.body.code || '';
|
|
|
let data = {
|
|
|
code: 200,
|
...
|
...
|
@@ -120,7 +123,7 @@ const setNewPasswordByEmailAPI = (req, res) => { |
|
|
service.modifyPasswordByEmailAsync(pwd, code)
|
|
|
.then(result => {
|
|
|
if (result.includes('history.back')) {
|
|
|
data.code = 400;
|
|
|
data.code = 400;
|
|
|
data.message = '修改失败';
|
|
|
}
|
|
|
|
...
|
...
|
@@ -139,16 +142,16 @@ const indexMobilePage = (req, res, next) => { |
|
|
.then(result => {
|
|
|
res.render('back/mobile', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-mobile',
|
|
|
title : '找回密码-通过手机号'
|
|
|
page: 'back-mobile',
|
|
|
title: '找回密码-通过手机号'
|
|
|
}, {
|
|
|
backUrl : SIGN_IN,
|
|
|
headerText : '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backMobile : true,
|
|
|
countrys : result.data,
|
|
|
areaCode : '+86'
|
|
|
}));
|
|
|
backUrl: SIGN_IN,
|
|
|
headerText: '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backMobile: true,
|
|
|
countrys: result.data,
|
|
|
areaCode: '+86'
|
|
|
}));
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
...
|
...
|
@@ -159,8 +162,8 @@ const indexMobilePage = (req, res, next) => { |
|
|
const sendCodeToMobileAPI = (req, res, next) => {
|
|
|
let phoneNum = req.body.phoneNum || '';
|
|
|
let areaCode = req.body.areaCode || '86';
|
|
|
let ERR = {
|
|
|
code : 400,
|
|
|
let ERR = {
|
|
|
code: 400,
|
|
|
message: '输入手机号码出错'
|
|
|
};
|
|
|
|
...
|
...
|
@@ -197,17 +200,17 @@ const verifyCodeByMobilePage = (req, res) => { |
|
|
|
|
|
res.render('back/mobile-code', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-code',
|
|
|
title : '找回密码-通过手机号'
|
|
|
page: 'back-code',
|
|
|
title: '找回密码-通过手机号'
|
|
|
}, {
|
|
|
backUrl : helpers.urlFormat('/passport/back/mobile'),
|
|
|
headerText : '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backCode : true,
|
|
|
areaCode : areaCode,
|
|
|
phoneNum : phoneNum
|
|
|
|
|
|
}));
|
|
|
backUrl: helpers.urlFormat('/passport/back/mobile'),
|
|
|
headerText: '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backCode: true,
|
|
|
areaCode: areaCode,
|
|
|
phoneNum: phoneNum
|
|
|
|
|
|
}));
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -215,7 +218,7 @@ const verifyCodeByMobilePage = (req, res) => { |
|
|
*/
|
|
|
const verifyCodeByMobileAPI = (req, res, next) => {
|
|
|
let phoneNum = req.body.phoneNum || '';
|
|
|
let code = req.body.code || '';
|
|
|
let code = req.body.code || '';
|
|
|
let areaCode = req.body.areaCode || '86';
|
|
|
|
|
|
service.validateMobileCodeAsync(phoneNum, code, areaCode)
|
...
|
...
|
@@ -225,13 +228,13 @@ const verifyCodeByMobileAPI = (req, res, next) => { |
|
|
code: 200,
|
|
|
data: helpers.urlFormat('/passport/back/backcode', {
|
|
|
phoneNum: phoneNum,
|
|
|
token : result.data.token,
|
|
|
token: result.data.token,
|
|
|
areaCode: areaCode
|
|
|
})
|
|
|
})
|
|
|
} else {
|
|
|
res.json({
|
|
|
code : 400,
|
|
|
code: 400,
|
|
|
message: '验证码失败'
|
|
|
})
|
|
|
}
|
...
|
...
|
@@ -244,9 +247,9 @@ const verifyCodeByMobileAPI = (req, res, next) => { |
|
|
*/
|
|
|
const setNewPasswordByMobilePage = (req, res) => {
|
|
|
let phoneNum = req.query.phoneNum || '';
|
|
|
let token = req.query.token || '';
|
|
|
let token = req.query.token || '';
|
|
|
let areaCode = req.query.areaCode || '86';
|
|
|
let code = req.query.code || '';
|
|
|
let code = req.query.code || '';
|
|
|
|
|
|
if (!(code || (token && helpers.verifyMobile(phoneNum)))) {
|
|
|
res.redirect(400);
|
...
|
...
|
@@ -255,18 +258,18 @@ const setNewPasswordByMobilePage = (req, res) => { |
|
|
|
|
|
res.render('back/new-password', Object.assign({
|
|
|
module: 'passport',
|
|
|
page : 'back-new-password',
|
|
|
title : '找回密码-输入新密码'
|
|
|
page: 'back-new-password',
|
|
|
title: '找回密码-输入新密码'
|
|
|
}, {
|
|
|
backUrl : SIGN_IN,
|
|
|
headerText : '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backNewPwd : true,
|
|
|
phoneNum : phoneNum,
|
|
|
token : token,
|
|
|
areaCode : areaCode,
|
|
|
code : code
|
|
|
}));
|
|
|
backUrl: SIGN_IN,
|
|
|
headerText: '找回密码',
|
|
|
isPassportPage: true,
|
|
|
backNewPwd: true,
|
|
|
phoneNum: phoneNum,
|
|
|
token: token,
|
|
|
areaCode: areaCode,
|
|
|
code: code
|
|
|
}));
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -274,9 +277,9 @@ const setNewPasswordByMobilePage = (req, res) => { |
|
|
*/
|
|
|
const setNewPasswordByMobileAPI = (req, res, next) => {
|
|
|
let phoneNum = req.body.phoneNum || '';
|
|
|
let token = req.body.token || '';
|
|
|
let token = req.body.token || '';
|
|
|
let areaCode = req.body.areaCode || '86';
|
|
|
let newPwd = req.body.password || '';
|
|
|
let newPwd = req.body.password || '';
|
|
|
|
|
|
service.modifyPasswordByMobileAsync(phoneNum, token, newPwd, areaCode)
|
|
|
.then(result => {
|
...
|
...
|
@@ -288,7 +291,7 @@ const setNewPasswordByMobileAPI = (req, res, next) => { |
|
|
});
|
|
|
} else {
|
|
|
res.json({
|
|
|
code : 400,
|
|
|
code: 400,
|
|
|
message: "修改密码失败"
|
|
|
})
|
|
|
}
|
...
|
...
|
|