-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
108 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/backend/migration/1657346559800-active-email-validation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export class activeEmailValidation1657346559800 { | ||
name = 'activeEmailValidation1657346559800' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "meta" ADD "enableActiveEmailValidation" boolean NOT NULL DEFAULT true`); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "enableActiveEmailValidation"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 11 additions & 8 deletions
19
packages/backend/src/services/validate-email-for-account.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
import { validate as validateEmail } from 'deep-email-validator'; | ||
import { UserProfiles } from '@/models/index.js'; | ||
import { fetchMeta } from '@/misc/fetch-meta.js'; | ||
|
||
export async function validateEmailForAccount(emailAddress: string): Promise<{ | ||
available: boolean; | ||
reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp'; | ||
}> { | ||
const meta = await fetchMeta(); | ||
|
||
const exist = await UserProfiles.countBy({ | ||
emailVerified: true, | ||
email: emailAddress, | ||
}); | ||
|
||
const validated = await validateEmail({ | ||
const validated = meta.enableActiveEmailValidation ? await validateEmail({ | ||
email: emailAddress, | ||
validateRegex: true, | ||
validateMx: true, | ||
validateTypo: false, // TLDを見ているみたいだけどclubとか弾かれるので | ||
validateDisposable: true, // 捨てアドかどうかチェック | ||
validateSMTP: false, // 日本だと25ポートが殆どのプロバイダーで塞がれていてタイムアウトになるので | ||
}); | ||
}) : { valid: true }; | ||
|
||
const available = exist === 0 && validated.valid; | ||
|
||
return { | ||
available, | ||
reason: available ? null : | ||
exist !== 0 ? 'used' : | ||
validated.reason === 'regex' ? 'format' : | ||
validated.reason === 'disposable' ? 'disposable' : | ||
validated.reason === 'mx' ? 'mx' : | ||
validated.reason === 'smtp' ? 'smtp' : | ||
null, | ||
exist !== 0 ? 'used' : | ||
validated.reason === 'regex' ? 'format' : | ||
validated.reason === 'disposable' ? 'disposable' : | ||
validated.reason === 'mx' ? 'mx' : | ||
validated.reason === 'smtp' ? 'smtp' : | ||
null, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters