Skip to content

Commit

Permalink
Mod: バリデーションを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
sakuhanight committed Nov 30, 2024
1 parent b95fb54 commit 14a9a63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/backend/src/core/EmailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ export class EmailService {
available: boolean;
reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp' | 'banned' | 'network' | 'blacklist' | 'allowedOnly';
}> {
if (this.utilityService.validateEmail(emailAddress)) {
return {
available: false,
reason: 'format',
};
}

const exist = await this.userProfilesRepository.countBy({
emailVerified: true,
email: emailAddress,
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/core/UtilityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export class UtilityService {
return this.punyHost(uri) === this.toPuny(this.config.host);
}

// メールアドレスのバリデーションを行う
// https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
@bindThis
public validateEmail(email: string): boolean {
const regexp = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
return regexp.test(email);
}

@bindThis
public isBlockedHost(blockedHosts: string[], host: string | null): boolean {
if (host == null) return false;
Expand Down

0 comments on commit 14a9a63

Please sign in to comment.