|
|
@ -125,20 +125,22 @@ app.get('/user/:id', async (req, res) => { |
|
|
|
app.get('/user/:id/edit', async (req, res) => { |
|
|
|
app.get('/user/:id/edit', async (req, res) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
let id = parseInt(req.params.id); |
|
|
|
let id = parseInt(req.params.id); |
|
|
|
let user = await User.findById(id); |
|
|
|
let userQuery = await User.createQueryBuilder(); |
|
|
|
if (!user) throw new ErrorMessage('无此用户。'); |
|
|
|
const userInfo = await userQuery.where("id = :id", { id }).getOne(); |
|
|
|
|
|
|
|
if (!userInfo) throw new ErrorMessage('无此用户。'); |
|
|
|
|
|
|
|
|
|
|
|
let allowedEdit = await user.isAllowedEditBy(res.locals.user); |
|
|
|
let allowedEdit = await userInfo.isAllowedEditBy(res.locals.user); |
|
|
|
if (!allowedEdit) { |
|
|
|
if (!allowedEdit) { |
|
|
|
throw new ErrorMessage('您没有权限进行此操作。'); |
|
|
|
throw new ErrorMessage('您没有权限进行此操作。'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
user.privileges = await user.getPrivileges(); |
|
|
|
userInfo.privileges = await userInfo.getPrivileges(); |
|
|
|
|
|
|
|
console.log(userInfo); |
|
|
|
|
|
|
|
|
|
|
|
res.locals.user.allowedManage = await res.locals.user.hasPrivilege('manage_user'); |
|
|
|
res.locals.user.allowedManage = await res.locals.user.hasPrivilege('manage_user'); |
|
|
|
|
|
|
|
|
|
|
|
res.render('user_edit', { |
|
|
|
res.render('user_edit', { |
|
|
|
edited_user: user, |
|
|
|
edited_user: userInfo, |
|
|
|
error_info: null |
|
|
|
error_info: null |
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -190,6 +192,7 @@ app.post('/user/:id/edit', async (req, res) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
user.information = req.body.information; |
|
|
|
user.information = req.body.information; |
|
|
|
|
|
|
|
user.anonymous_name = req.body.anonymous_name || ''; |
|
|
|
user.sex = req.body.sex; |
|
|
|
user.sex = req.body.sex; |
|
|
|
user.public_email = (req.body.public_email === 'on'); |
|
|
|
user.public_email = (req.body.public_email === 'on'); |
|
|
|
user.prefer_formatted_code = (req.body.prefer_formatted_code === 'on'); |
|
|
|
user.prefer_formatted_code = (req.body.prefer_formatted_code === 'on'); |
|
|
|