fix: createNewUser应该返回promise;添加要求inviter的注册接口

This commit is contained in:
chaosBreaking
2019-09-01 22:42:39 +08:00
parent 6c2cd15689
commit 05c97a07c5
2 changed files with 45 additions and 4 deletions

View File

@@ -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) => {