aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users/registrations.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-01-20 15:34:01 +0100
committerChocobozzz <me@florianbigard.com>2023-01-20 15:34:01 +0100
commit4115f20084f302f497be9cb12237564679ca54ec (patch)
tree74cf8f5b3884edeb0b47b529cf04b306cd12b23d /server/controllers/api/users/registrations.ts
parente854d57bed56bcbba4d191af54125ae6dd569a88 (diff)
downloadPeerTube-4115f20084f302f497be9cb12237564679ca54ec.tar.gz
PeerTube-4115f20084f302f497be9cb12237564679ca54ec.tar.zst
PeerTube-4115f20084f302f497be9cb12237564679ca54ec.zip
Add ability to not send an email for registration
Diffstat (limited to 'server/controllers/api/users/registrations.ts')
-rw-r--r--server/controllers/api/users/registrations.ts23
1 files changed, 18 insertions, 5 deletions
diff --git a/server/controllers/api/users/registrations.ts b/server/controllers/api/users/registrations.ts
index 3d4e0aa18..5e213d6cc 100644
--- a/server/controllers/api/users/registrations.ts
+++ b/server/controllers/api/users/registrations.ts
@@ -3,7 +3,14 @@ import { Emailer } from '@server/lib/emailer'
3import { Hooks } from '@server/lib/plugins/hooks' 3import { Hooks } from '@server/lib/plugins/hooks'
4import { UserRegistrationModel } from '@server/models/user/user-registration' 4import { UserRegistrationModel } from '@server/models/user/user-registration'
5import { pick } from '@shared/core-utils' 5import { pick } from '@shared/core-utils'
6import { HttpStatusCode, UserRegister, UserRegistrationRequest, UserRegistrationState, UserRight } from '@shared/models' 6import {
7 HttpStatusCode,
8 UserRegister,
9 UserRegistrationRequest,
10 UserRegistrationState,
11 UserRegistrationUpdateState,
12 UserRight
13} from '@shared/models'
7import { auditLoggerFactory, UserAuditView } from '../../../helpers/audit-logger' 14import { auditLoggerFactory, UserAuditView } from '../../../helpers/audit-logger'
8import { logger } from '../../../helpers/logger' 15import { logger } from '../../../helpers/logger'
9import { CONFIG } from '../../../initializers/config' 16import { CONFIG } from '../../../initializers/config'
@@ -125,6 +132,7 @@ async function requestRegistration (req: express.Request, res: express.Response)
125 132
126async function acceptRegistration (req: express.Request, res: express.Response) { 133async function acceptRegistration (req: express.Request, res: express.Response) {
127 const registration = res.locals.userRegistration 134 const registration = res.locals.userRegistration
135 const body: UserRegistrationUpdateState = req.body
128 136
129 const userToCreate = buildUser({ 137 const userToCreate = buildUser({
130 username: registration.username, 138 username: registration.username,
@@ -150,26 +158,31 @@ async function acceptRegistration (req: express.Request, res: express.Response)
150 158
151 registration.userId = user.id 159 registration.userId = user.id
152 registration.state = UserRegistrationState.ACCEPTED 160 registration.state = UserRegistrationState.ACCEPTED
153 registration.moderationResponse = req.body.moderationResponse 161 registration.moderationResponse = body.moderationResponse
154 162
155 await registration.save() 163 await registration.save()
156 164
157 logger.info('Registration of %s accepted', registration.username) 165 logger.info('Registration of %s accepted', registration.username)
158 166
159 Emailer.Instance.addUserRegistrationRequestProcessedJob(registration) 167 if (body.preventEmailDelivery !== true) {
168 Emailer.Instance.addUserRegistrationRequestProcessedJob(registration)
169 }
160 170
161 return res.sendStatus(HttpStatusCode.NO_CONTENT_204) 171 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
162} 172}
163 173
164async function rejectRegistration (req: express.Request, res: express.Response) { 174async function rejectRegistration (req: express.Request, res: express.Response) {
165 const registration = res.locals.userRegistration 175 const registration = res.locals.userRegistration
176 const body: UserRegistrationUpdateState = req.body
166 177
167 registration.state = UserRegistrationState.REJECTED 178 registration.state = UserRegistrationState.REJECTED
168 registration.moderationResponse = req.body.moderationResponse 179 registration.moderationResponse = body.moderationResponse
169 180
170 await registration.save() 181 await registration.save()
171 182
172 Emailer.Instance.addUserRegistrationRequestProcessedJob(registration) 183 if (body.preventEmailDelivery !== true) {
184 Emailer.Instance.addUserRegistrationRequestProcessedJob(registration)
185 }
173 186
174 logger.info('Registration of %s rejected', registration.username) 187 logger.info('Registration of %s rejected', registration.username)
175 188