message.py
def message(doamin, uid64, token):
return f"아래 링크를 클릭하면 회원가입 인증이 완료됩니다.\n\n회원가입 링크 : http://{doamin}/user/emailcheck/{uid64}/{token}\n\n감사합니다."
#domain- current site domain
#uid- urlsafe base64 encode force bytes (user.pk)
#token - account activation toekn make token(user)
settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = '587'
EMAIL_HOST_USER = 'hwukjunwoo@gmail.com'
EMAIL_HOST_PASSWORD = my_settings.DATABASES.password
EMAIL_USE_TLS = True
# TLS 보안 방법
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
# 사이트와 관련한 자동응답을 받을 이메일 주소,'webmaster@local
class EmailCheckView(View):
def post(self, request):
try:
data = json.loads(request.body)
email = data.get('email', None)
auth_number = random.randint(10000, 100000)
if email:
validate_email(email)
if Member.objects.filter(email = email).exists():
return JsonResponse({'message': 'EXISTS_USER'}, status=409)
mail_subject = "[SOT] 회원가입 인증 메일입니다."
content = f"이메일 인증에 성공하셨습니다.\n\n인증번호는 {auth_number}"
user_email = data['email']
email = EmailMessage(mail_subject, content, to=[user_email])
email.send()
return JsonResponse({'message': 'SUCCESS'}, status=201)
except KeyError:
return JsonResponse({'message': 'KEY_ERROR'}, status=400)