mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
Handle email update on server
This commit is contained in:
parent
fff77ba231
commit
d1ab89deb7
12 changed files with 164 additions and 30 deletions
|
@ -28,6 +28,7 @@ import { VideoImportModel } from '../../../models/video/video-import'
|
|||
import { AccountModel } from '../../../models/account/account'
|
||||
import { CONFIG } from '../../../initializers/config'
|
||||
import { sequelizeTypescript } from '../../../initializers/database'
|
||||
import { sendVerifyUserEmail } from '../../../lib/user'
|
||||
|
||||
const auditLogger = auditLoggerFactory('users-me')
|
||||
|
||||
|
@ -171,17 +172,26 @@ async function deleteMe (req: express.Request, res: express.Response) {
|
|||
|
||||
async function updateMe (req: express.Request, res: express.Response) {
|
||||
const body: UserUpdateMe = req.body
|
||||
let sendVerificationEmail = false
|
||||
|
||||
const user = res.locals.oauth.token.user
|
||||
const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
|
||||
|
||||
if (body.password !== undefined) user.password = body.password
|
||||
if (body.email !== undefined) user.email = body.email
|
||||
if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy
|
||||
if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled
|
||||
if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
|
||||
if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled
|
||||
|
||||
if (body.email !== undefined) {
|
||||
if (CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) {
|
||||
user.pendingEmail = body.email
|
||||
sendVerificationEmail = true
|
||||
} else {
|
||||
user.email = body.email
|
||||
}
|
||||
}
|
||||
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
const userAccount = await AccountModel.load(user.Account.id)
|
||||
|
||||
|
@ -196,6 +206,10 @@ async function updateMe (req: express.Request, res: express.Response) {
|
|||
auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
|
||||
})
|
||||
|
||||
if (sendVerificationEmail === true) {
|
||||
await sendVerifyUserEmail(user, true)
|
||||
}
|
||||
|
||||
return res.sendStatus(204)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue