+ const authUser = res.locals.oauth.token.User
+ if (authUser.role !== UserRole.ADMINISTRATOR && req.body.role !== UserRole.USER) {
+ return res
+ .status(HttpStatusCode.FORBIDDEN_403)
+ .json({ error: 'You can only create users (and not administrators or moderators)' })
+ }
+
+ if (req.body.channelName) {
+ if (req.body.channelName === req.body.username) {
+ return res
+ .status(HttpStatusCode.BAD_REQUEST_400)
+ .json({ error: 'Channel name cannot be the same as user username.' })
+ }
+
+ const existing = await ActorModel.loadLocalByName(req.body.channelName)
+ if (existing) {
+ return res
+ .status(HttpStatusCode.CONFLICT_409)
+ .json({ error: `Channel with name ${req.body.channelName} already exists.` })
+ }
+ }
+