feat: 资金密码

This commit is contained in:
chaosBreaking
2019-09-05 16:16:50 +08:00
parent 005368f0d5
commit 689adb3c5b
3 changed files with 42 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
const User = require('./user.model');
const MsgCode = require('../msgCode/msgCode.controller');
const changePwd = require('../sign/sign.controller').changePasswd;
const Crypto = require('../../utils/crypto');
module.exports = {
changePwd,
@@ -86,4 +87,31 @@ module.exports = {
error: JSON.stringify(err)
}));
},
async checkFundPwd (req, res) {
const { userId } = res.locals.user;
return User.findById(userId).then(user => {
return res.json({
code: 0,
data: user.fundPwd ? 1 : 0
});
});
},
async changeFundPwd (req, res) {
const { userId } = res.locals.user;
const { password, newPassword } = req.body;
return User.findById(userId).then(async user => {
const hashPasswd = Crypto.hash(password);
if (user.fundPwd !== hashPasswd) return res.json({
code: 1,
msg: '原资金密码不正确'
});
const newHashFundPwd = Crypto.hash(newPassword);
user.updateOne({ fundPwd: newHashFundPwd }).then(() => {
return res.json({
code: 0,
msg: '修改成功'
});
});
});
},
};

View File

@@ -12,6 +12,9 @@ const UserSchema = new mongoose.Schema({
type: String,
required: true
},
fundPwd: {
type: String,
},
nickname: {
type: String,
required: false

View File

@@ -26,6 +26,16 @@ const services = [
method: 'GET',
controller: controller.getGroup
},
{
url: '/checkFundPwd',
method: 'GET',
controller: controller.checkFundPwd
},
{
url: '/chFundPwd',
method: 'GET',
controller: controller.changeFundPwd
},
];
module.exports = services.map(service => {