fix: createNewUser应该返回promise;添加要求inviter的注册接口
This commit is contained in:
@@ -64,6 +64,49 @@ module.exports = {
|
||||
}
|
||||
};
|
||||
}),
|
||||
signUpReqInviter: inject(function(SysConfig) {
|
||||
const { JWT_SECRET, PWD_HASH_SALT } = SysConfig;
|
||||
return async (req, res) => {
|
||||
let { phone, code, inviter, password } = req.body;
|
||||
if (!phone || !code || !password || !inviter) return res.json({
|
||||
code: 1,
|
||||
msg: 'Missing required parameters'
|
||||
});
|
||||
const isCodeValid = await Code.verifyCode({ id: phone, code, type: CODE_TYPE['signUp'] });
|
||||
password = Crypto.hash(password, { salt: PWD_HASH_SALT });
|
||||
if (isCodeValid) {
|
||||
await createNewUser({
|
||||
phone,
|
||||
inviter,
|
||||
password
|
||||
}).then(user => {
|
||||
const token = createToken({
|
||||
userId: user.id
|
||||
}, JWT_SECRET, {});
|
||||
res.json({
|
||||
code: 0,
|
||||
msg: 'success',
|
||||
data: {
|
||||
//刚注册,需要返回的应该只有token,其他的没意义
|
||||
token
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
mylog.error(err);
|
||||
res.json({
|
||||
code: 3,
|
||||
msg: JSON.stringify(err),
|
||||
});
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
code: 2,
|
||||
msg: 'Invalid code',
|
||||
});
|
||||
}
|
||||
};
|
||||
}),
|
||||
signUp: inject(function(SysConfig) {
|
||||
const { JWT_SECRET, PWD_HASH_SALT } = SysConfig;
|
||||
return async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user