```js
// 提交注册
router.post('/register', async function (req, res) {
var body = req.body;
try {
if (await User.findOne({ email: body.email })) {
return res.status(200).json({
err_code: 1,
message: 'Email already exists'
})
}
if (await User.findOne({ nickname: body.nickname })) {
return res.status(200).json({
err_code: 2,
message: 'nickname already exists'
})
}
// 对密码进行 md5 重复加密
body.password = md5(md5(body.password));
// 创建用户,执行注册
await new User(body).save()
res.status(200).json({
err_code: 0,
message: 'OK'
})
} catch (err) {
res.status(500).json({
err_code: 500,
message: err.message
})
}
})
```
