|
16 | 16 |
|
17 | 17 | from .permissions import IsTeacher, IsAdmin, IsStudent
|
18 | 18 | from .models import Course, AccountRoles, CourseLecture
|
| 19 | + |
19 | 20 | from .serializers import AddLectureSerializer, CourseUserSerializer, CustomTokenSerializer, CreateUserSerializer, LectureSerializer, MassEnrollSerializer, SetAttendenceTeacherSerializer, UserSerializer, CourseCreateSerializer, CourseSerializer
|
20 | 21 |
|
21 |
| -import pdb |
| 22 | + |
| 23 | + |
| 24 | +from django.core.mail import send_mail |
22 | 25 |
|
23 | 26 |
|
24 | 27 | User = get_user_model()
|
|
37 | 40 | def test(request):
|
38 | 41 | return Response({"ping": "pong"}, 200)
|
39 | 42 |
|
| 43 | +@extend_schema( |
| 44 | + summary="Send Test Email", |
| 45 | + description="Tries to send a test email.", |
| 46 | + responses={ |
| 47 | + status.HTTP_200_OK: OpenApiResponse(description="Success - An email was sent."), |
| 48 | + status.HTTP_400_BAD_REQUEST: OpenApiResponse(description="Failure - No email given as a parameter."), |
| 49 | + status.HTTP_418_IM_A_TEAPOT: OpenApiResponse(description="Failure - The email could not be sent.") |
| 50 | + } |
| 51 | +) |
| 52 | +class MailTestView(generics.CreateAPIView): |
| 53 | + serializer_class = MailTestSerializer |
| 54 | + |
| 55 | + def post(self, request, *args, **kwargs): |
| 56 | + subject = 'Welcome to My Site' |
| 57 | + message = 'Thank you for creating an account!' |
| 58 | + |
| 59 | + recipient_list = [request.POST.get("email", "")] |
| 60 | + if recipient_list[0] == "": |
| 61 | + Response({"status": "fail"}, 400) |
| 62 | + ret_code = send_mail(subject, message, from_email, recipient_list) |
| 63 | + if ret_code == 1: |
| 64 | + Response({"status": "success"}, 200) |
| 65 | + else: |
| 66 | + Response({"status": "fail", "return_code": ret_code}, 418) |
| 67 | + |
| 68 | + |
40 | 69 | # DEBUG function
|
41 | 70 | # Generate an admin account if no admin accounts exists
|
42 | 71 | # Dangerous endpoint which should be turned off in production but can be used to setup the DB
|
|
0 commit comments