File size: 1,990 Bytes
9a89b87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Email validation utilities to ensure only business emails are allowed.
"""
from fastapi import HTTPException

# List of personal email domains to block
PERSONAL_EMAIL_DOMAINS = {
    'gmail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 
    'aol.com', 'icloud.com', 'mail.com', 'protonmail.com',
    'yandex.com', 'zoho.com', 'gmx.com', 'live.com', 'msn.com',
    'me.com', 'mac.com', 'yahoo.co.uk', 'yahoo.co.jp', 'yahoo.fr',
    'yahoo.de', 'yahoo.it', 'yahoo.es', 'yahoo.in', 'yahoo.com.au',
    'gmail.co.uk', 'gmail.fr', 'gmail.de', 'gmail.it', 'gmail.es',
    'gmail.in', 'gmail.com.au', 'hotmail.co.uk', 'hotmail.fr',
    'hotmail.de', 'hotmail.it', 'hotmail.es', 'outlook.co.uk',
    'outlook.fr', 'outlook.de', 'outlook.it', 'outlook.es',
    'rediffmail.com', 'sina.com', 'qq.com', '163.com', '126.com',
    'mail.ru', 'inbox.com', 'fastmail.com', 'tutanota.com',
    'hey.com', 'pm.me'
}


def is_business_email(email: str) -> bool:
    """
    Check if email is a business email (not personal).
    
    Args:
        email: Email address to validate
        
    Returns:
        True if business email, False if personal email
    """
    if not email or '@' not in email:
        return False
    
    domain = email.split('@')[1].lower().strip()
    return domain not in PERSONAL_EMAIL_DOMAINS


def validate_business_email(email: str) -> None:
    """
    Raise exception if email is not a business email.
    
    Args:
        email: Email address to validate
        
    Raises:
        HTTPException: If email is a personal email domain
    """
    if not email:
        raise HTTPException(
            status_code=400,
            detail="Email address is required"
        )
    
    if not is_business_email(email):
        raise HTTPException(
            status_code=400,
            detail="Only business email addresses are allowed. Personal email accounts (Gmail, Yahoo, Outlook, etc.) are not permitted. Please use your work email address."
        )