mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Change RESEND_TIME config name to EMAIL_CODE_VALID_TIME.
This commit is contained in:
parent
c975ac0aa2
commit
ac3340ec1c
@ -40,7 +40,7 @@ EMAIL_SMTP_URL=gmail.com
|
||||
EMAIL_SMTP_PORT=587
|
||||
EMAIL_LINK_VERIFICATION=http://localhost/checkEmail/{code}
|
||||
EMAIL_LINK_SETPASSWORD=http://localhost/reset/{code}
|
||||
RESEND_TIME=10
|
||||
EMAIL_CODE_VALID_TIME=10
|
||||
|
||||
# Webhook
|
||||
WEBHOOK_ELOPAGE_SECRET=secret
|
||||
@ -55,7 +55,9 @@ const loginServer = {
|
||||
}
|
||||
|
||||
// TODO: Hannes if I find you... this looks like blasphemy
|
||||
const resendTime = parseInt(process.env.RESEND_TIME ? process.env.RESEND_TIME : 'null')
|
||||
const resendTime = parseInt(
|
||||
process.env.EMAIL_CODE_VALID_TIME ? process.env.EMAIL_CODE_VALID_TIME : 'null',
|
||||
)
|
||||
const email = {
|
||||
EMAIL: process.env.EMAIL === 'true' || false,
|
||||
EMAIL_USERNAME: process.env.EMAIL_USERNAME || 'gradido_email',
|
||||
@ -67,7 +69,7 @@ const email = {
|
||||
process.env.EMAIL_LINK_VERIFICATION || 'http://localhost/checkEmail/{code}',
|
||||
EMAIL_LINK_SETPASSWORD:
|
||||
process.env.EMAIL_LINK_SETPASSWORD || 'http://localhost/reset-password/{code}',
|
||||
RESEND_TIME: isNaN(resendTime) ? 10 : resendTime,
|
||||
EMAIL_CODE_VALID_TIME: isNaN(resendTime) ? 10 : resendTime,
|
||||
}
|
||||
|
||||
const webhook = {
|
||||
|
||||
@ -158,9 +158,11 @@ const createEmailOptIn = async (
|
||||
})
|
||||
if (emailOptIn) {
|
||||
const timeElapsed = Date.now() - new Date(emailOptIn.updatedAt).getTime()
|
||||
if (timeElapsed <= parseInt(CONFIG.RESEND_TIME.toString()) * 60 * 1000) {
|
||||
if (timeElapsed <= parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
|
||||
throw new Error(
|
||||
'email already sent less than ' + parseInt(CONFIG.RESEND_TIME.toString()) + ' minutes ago',
|
||||
'email already sent less than ' +
|
||||
parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) +
|
||||
' minutes ago',
|
||||
)
|
||||
} else {
|
||||
emailOptIn.updatedAt = new Date()
|
||||
@ -189,9 +191,11 @@ const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
|
||||
// Check for 10 minute delay
|
||||
if (optInCode) {
|
||||
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
|
||||
if (timeElapsed <= parseInt(CONFIG.RESEND_TIME.toString()) * 60 * 1000) {
|
||||
if (timeElapsed <= parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
|
||||
throw new Error(
|
||||
'email already sent less than ' + parseInt(CONFIG.RESEND_TIME.toString()) + ' minutes ago',
|
||||
'email already sent less than ' +
|
||||
parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) +
|
||||
' minutes ago',
|
||||
)
|
||||
} else {
|
||||
optInCode.updatedAt = new Date()
|
||||
@ -486,8 +490,10 @@ export class UserResolver {
|
||||
|
||||
// Code is only valid for 10minutes
|
||||
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
|
||||
if (timeElapsed > parseInt(CONFIG.RESEND_TIME.toString()) * 60 * 1000) {
|
||||
throw new Error('Code is older than ' + parseInt(CONFIG.RESEND_TIME.toString()) + ' minutes')
|
||||
if (timeElapsed > parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
|
||||
throw new Error(
|
||||
'Code is older than ' + parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) + ' minutes',
|
||||
)
|
||||
}
|
||||
|
||||
// load user
|
||||
@ -562,11 +568,12 @@ export class UserResolver {
|
||||
@Query(() => Boolean)
|
||||
async queryOptIn(@Arg('optIn') optIn: string): Promise<boolean> {
|
||||
const optInCode = await LoginEmailOptIn.findOneOrFail({ verificationCode: optIn })
|
||||
console.log('optInCode', optInCode)
|
||||
// Code is only valid for 10minutes
|
||||
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
|
||||
if (timeElapsed > parseInt(CONFIG.RESEND_TIME.toString()) * 60 * 1000) {
|
||||
throw new Error('Code is older than ' + parseInt(CONFIG.RESEND_TIME.toString()) + ' minutes')
|
||||
if (timeElapsed > parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
|
||||
throw new Error(
|
||||
'Code is older than ' + parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) + ' minutes',
|
||||
)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user