feat: 资金密码
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
const User = require('./user.model');
|
const User = require('./user.model');
|
||||||
const MsgCode = require('../msgCode/msgCode.controller');
|
const MsgCode = require('../msgCode/msgCode.controller');
|
||||||
const changePwd = require('../sign/sign.controller').changePasswd;
|
const changePwd = require('../sign/sign.controller').changePasswd;
|
||||||
|
const Crypto = require('../../utils/crypto');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
changePwd,
|
changePwd,
|
||||||
@@ -85,5 +86,32 @@ module.exports = {
|
|||||||
code: 500,
|
code: 500,
|
||||||
error: JSON.stringify(err)
|
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: '修改成功'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
@@ -12,6 +12,9 @@ const UserSchema = new mongoose.Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
fundPwd: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
nickname: {
|
nickname: {
|
||||||
type: String,
|
type: String,
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ const services = [
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
controller: controller.getGroup
|
controller: controller.getGroup
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
url: '/checkFundPwd',
|
||||||
|
method: 'GET',
|
||||||
|
controller: controller.checkFundPwd
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: '/chFundPwd',
|
||||||
|
method: 'GET',
|
||||||
|
controller: controller.changeFundPwd
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = services.map(service => {
|
module.exports = services.map(service => {
|
||||||
|
|||||||
Reference in New Issue
Block a user