mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Migrate renderSetPasswordForm to zod
GitOrigin-RevId: ddb6f06c6dc838ecee5c4bd31824f9e1c92c2cfe
This commit is contained in:
@@ -155,23 +155,32 @@ async function requestReset(req, res, next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const renderSetPasswordFormSchema = z.object({
|
||||||
|
query: z.object({
|
||||||
|
email: z.string(),
|
||||||
|
passwordResetToken: z.string().optional(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
async function renderSetPasswordForm(req, res, next) {
|
async function renderSetPasswordForm(req, res, next) {
|
||||||
if (req.query.passwordResetToken != null) {
|
const { query } = validateReq(req, renderSetPasswordFormSchema)
|
||||||
|
|
||||||
|
if (query.passwordResetToken != null) {
|
||||||
try {
|
try {
|
||||||
const result =
|
const result =
|
||||||
await PasswordResetHandler.promises.getUserForPasswordResetToken(
|
await PasswordResetHandler.promises.getUserForPasswordResetToken(
|
||||||
req.query.passwordResetToken
|
query.passwordResetToken
|
||||||
)
|
)
|
||||||
|
|
||||||
const { user, remainingPeeks } = result || {}
|
const { user, remainingPeeks } = result || {}
|
||||||
if (!user || remainingPeeks <= 0) {
|
if (!user || remainingPeeks <= 0) {
|
||||||
return res.redirect('/user/password/reset?error=token_expired')
|
return res.redirect('/user/password/reset?error=token_expired')
|
||||||
}
|
}
|
||||||
req.session.resetToken = req.query.passwordResetToken
|
req.session.resetToken = query.passwordResetToken
|
||||||
let emailQuery = ''
|
let emailQuery = ''
|
||||||
|
|
||||||
if (typeof req.query.email === 'string') {
|
if (typeof query.email === 'string') {
|
||||||
const email = EmailsHelper.parseEmail(req.query.email)
|
const email = EmailsHelper.parseEmail(query.email)
|
||||||
if (email) {
|
if (email) {
|
||||||
emailQuery = `?email=${encodeURIComponent(email)}`
|
emailQuery = `?email=${encodeURIComponent(email)}`
|
||||||
}
|
}
|
||||||
@@ -190,7 +199,7 @@ async function renderSetPasswordForm(req, res, next) {
|
|||||||
return res.redirect('/user/password/reset')
|
return res.redirect('/user/password/reset')
|
||||||
}
|
}
|
||||||
|
|
||||||
const email = EmailsHelper.parseEmail(req.query.email)
|
const email = EmailsHelper.parseEmail(query.email)
|
||||||
|
|
||||||
// clean up to avoid leaking the token in the session object
|
// clean up to avoid leaking the token in the session object
|
||||||
const passwordResetToken = req.session.resetToken
|
const passwordResetToken = req.session.resetToken
|
||||||
|
|||||||
@@ -30,12 +30,6 @@ export default {
|
|||||||
|
|
||||||
webRouter.get(
|
webRouter.get(
|
||||||
'/user/password/set',
|
'/user/password/set',
|
||||||
validate({
|
|
||||||
query: {
|
|
||||||
email: Joi.string().required(),
|
|
||||||
passwordResetToken: Joi.string(),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
rateLimit,
|
rateLimit,
|
||||||
PasswordResetController.renderSetPasswordForm
|
PasswordResetController.renderSetPasswordForm
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user