diff options
Diffstat (limited to 'server/controllers/api/users/me.ts')
-rw-r--r-- | server/controllers/api/users/me.ts | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index ddb239e7b..1750a02e9 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -28,6 +28,7 @@ import { VideoImportModel } from '../../../models/video/video-import' | |||
28 | import { AccountModel } from '../../../models/account/account' | 28 | import { AccountModel } from '../../../models/account/account' |
29 | import { CONFIG } from '../../../initializers/config' | 29 | import { CONFIG } from '../../../initializers/config' |
30 | import { sequelizeTypescript } from '../../../initializers/database' | 30 | import { sequelizeTypescript } from '../../../initializers/database' |
31 | import { sendVerifyUserEmail } from '../../../lib/user' | ||
31 | 32 | ||
32 | const auditLogger = auditLoggerFactory('users-me') | 33 | const auditLogger = auditLoggerFactory('users-me') |
33 | 34 | ||
@@ -171,17 +172,26 @@ async function deleteMe (req: express.Request, res: express.Response) { | |||
171 | 172 | ||
172 | async function updateMe (req: express.Request, res: express.Response) { | 173 | async function updateMe (req: express.Request, res: express.Response) { |
173 | const body: UserUpdateMe = req.body | 174 | const body: UserUpdateMe = req.body |
175 | let sendVerificationEmail = false | ||
174 | 176 | ||
175 | const user = res.locals.oauth.token.user | 177 | const user = res.locals.oauth.token.user |
176 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) | 178 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) |
177 | 179 | ||
178 | if (body.password !== undefined) user.password = body.password | 180 | if (body.password !== undefined) user.password = body.password |
179 | if (body.email !== undefined) user.email = body.email | ||
180 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy | 181 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy |
181 | if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled | 182 | if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled |
182 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo | 183 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo |
183 | if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled | 184 | if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled |
184 | 185 | ||
186 | if (body.email !== undefined) { | ||
187 | if (CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { | ||
188 | user.pendingEmail = body.email | ||
189 | sendVerificationEmail = true | ||
190 | } else { | ||
191 | user.email = body.email | ||
192 | } | ||
193 | } | ||
194 | |||
185 | await sequelizeTypescript.transaction(async t => { | 195 | await sequelizeTypescript.transaction(async t => { |
186 | const userAccount = await AccountModel.load(user.Account.id) | 196 | const userAccount = await AccountModel.load(user.Account.id) |
187 | 197 | ||
@@ -196,6 +206,10 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
196 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) | 206 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) |
197 | }) | 207 | }) |
198 | 208 | ||
209 | if (sendVerificationEmail === true) { | ||
210 | await sendVerifyUserEmail(user, true) | ||
211 | } | ||
212 | |||
199 | return res.sendStatus(204) | 213 | return res.sendStatus(204) |
200 | } | 214 | } |
201 | 215 | ||