You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
878 B
27 lines
878 B
from django.shortcuts import render
|
|
from django.http.response import JsonResponse
|
|
import string
|
|
import random
|
|
from django.core.mail import send_mail
|
|
from .models import CaptchaModel
|
|
# Create your views here.
|
|
|
|
def login(request):
|
|
return render(request, 'login.html')
|
|
|
|
def register(request):
|
|
return render(request, 'register.html')
|
|
|
|
def send_email_captcha(request):
|
|
|
|
email = request.GET.get('email')
|
|
if not email:
|
|
return JsonResponse({'code': 400, 'message': '请输入邮箱'})
|
|
# 生成验证码
|
|
captcha ="".join(random.sample(string.digits, 4))
|
|
|
|
CaptchaModel.objects.update_or_create(email=email, defaults={'captcha': captcha})
|
|
send_mail("湖南工业大学论坛验证码", message=f"你的验证码是{captcha}", recipient_list=[email], from_email='3485393348@qq.com')
|
|
return JsonResponse({'code': 200, 'message': '发送成功'})
|
|
|