mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-11-16 08:36:27 +01:00
1c67c26bd8
* wip * wip * wip * Update following.ts * wip * wip * wip * Update resolve-user.ts * maxQueryExecutionTime * wip * wip
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { validate as validateEmail } from 'deep-email-validator';
|
|
import { UserProfiles } from '@/models/index.js';
|
|
|
|
export async function validateEmailForAccount(emailAddress: string): Promise<{
|
|
available: boolean;
|
|
reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp';
|
|
}> {
|
|
const exist = await UserProfiles.countBy({
|
|
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,
|
|
};
|
|
}
|