feat: 资金密码
This commit is contained in:
@@ -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,
|
||||
@@ -85,5 +86,32 @@ module.exports = {
|
||||
code: 500,
|
||||
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,
|
||||
required: true
|
||||
},
|
||||
fundPwd: {
|
||||
type: String,
|
||||
},
|
||||
nickname: {
|
||||
type: String,
|
||||
required: false
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user