diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-07 20:16:01 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-07 20:16:01 +0900 |
| commit | 68192126e6a902d4f9267970d8cb3a98d0910161 (patch) | |
| tree | 1749f325563fb7c46506d525e7c413b1538a42a2 /src/services | |
| parent | feat: make possible to configure following/followers visibility (#7959) (diff) | |
| download | misskey-68192126e6a902d4f9267970d8cb3a98d0910161.tar.gz misskey-68192126e6a902d4f9267970d8cb3a98d0910161.tar.bz2 misskey-68192126e6a902d4f9267970d8cb3a98d0910161.zip | |
feat: improve email validation
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/validate-email-for-account.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/services/validate-email-for-account.ts b/src/services/validate-email-for-account.ts new file mode 100644 index 0000000000..1d039fb263 --- /dev/null +++ b/src/services/validate-email-for-account.ts @@ -0,0 +1,34 @@ +import validateEmail from 'deep-email-validator'; +import { UserProfiles } from '@/models'; + +export async function validateEmailForAccount(emailAddress: string): Promise<{ + available: boolean; + reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp'; +}> { + const exist = await UserProfiles.count({ + emailVerified: true, + email: emailAddress, + }); + + const validated = await validateEmail({ + email: emailAddress, + validateRegex: true, + validateMx: true, + validateTypo: false, // TLDを見ているみたいだけどclubとか弾かれるので + validateDisposable: true, // 捨てアドかどうかチェック + validateSMTP: false, // 日本だと25ポートが殆どのプロバイダーで塞がれていてタイムアウトになるので + }); + + 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, + }; +} |