Skip to content

Commit

Permalink
added custom SMTP error response
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Sutton committed Jan 19, 2024
1 parent 92698f7 commit d882c15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions webapp/api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from django.shortcuts import render
from django.utils import timezone
from django_filters import rest_framework as drf
from django.contrib.auth.views import PasswordResetView
from medcat.cdb import CDB
from medcat.utils.helpers import tkns_from_doc
from rest_framework import viewsets
from rest_framework.decorators import api_view
from rest_framework.response import Response
from smtplib import SMTPException

from core.settings import MEDIA_ROOT
from .admin import download_projects_with_text, download_projects_without_text, \
Expand Down Expand Up @@ -213,6 +215,17 @@ class OPCSCodeViewSet(viewsets.ModelViewSet):
filterset_class = OPCSCodeFilter
filterset_fields = ['code', 'id']

class ResetPasswordView(PasswordResetView):
email_template_name = 'password_reset_email.html'
subject_template_name = 'password_reset_subject.txt'
def post(self, request, *args, **kwargs):
try:
return super().post(request, *args, **kwargs)
except SMTPException:
return HttpResponseServerError('''SMTP settings have not been configured. <br>
Please visit https://medcattrainer.readthedocs.io for more information to resolve this. <br>
You can also ask a question at: https://discourse.cogstack.org/c/medcat/5''')


@api_view(http_method_names=['GET'])
def get_anno_tool_conf(_):
Expand Down
2 changes: 1 addition & 1 deletion webapp/api/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
path('api/concept-path/', api.views.cdb_concept_path),
path('api/generate-concept-filter-json/', api.views.generate_concept_filter_flat_json),
path('api/generate-concept-filter/', api.views.generate_concept_filter),
path('reset_password/', pw_views.PasswordResetView.as_view(email_template_name="password_reset_email.html", subject_template_name="password_reset_subject.txt"), name ='reset_password'),
path('reset_password/', api.views.ResetPasswordView.as_view(), name ='reset_password'),
path('reset_password_sent/', pw_views.PasswordResetDoneView.as_view(), name ='password_reset_done'),
path('reset/<uidb64>/<token>', pw_views.PasswordResetConfirmView.as_view(), name ='password_reset_confirm'),
path('reset_password_complete/', pw_views.PasswordResetCompleteView.as_view(), name ='password_reset_complete'),
Expand Down

0 comments on commit d882c15

Please sign in to comment.