diff --git a/backend/backend/urls.py b/backend/backend/urls.py index 77d54eb..0cfddce 100644 --- a/backend/backend/urls.py +++ b/backend/backend/urls.py @@ -17,6 +17,6 @@ from django.contrib import admin from django.urls import include, path urlpatterns = [ - path('multimail/', include('multimail.urls')), + path('', include('multimail.urls')), path('admin/', admin.site.urls), ] diff --git a/backend/multimail/actions.py b/backend/multimail/actions.py index 8bc52c8..feaeb13 100644 --- a/backend/multimail/actions.py +++ b/backend/multimail/actions.py @@ -1,29 +1,32 @@ from django.http import HttpResponseRedirect -from django.shortcuts import get_object_or_404, render +from django.shortcuts import get_object_or_404 from django.urls import reverse -from django.views import generic -from django.utils import timezone from django.contrib.auth.decorators import login_required -from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth import logout as auth_logout -from .models import Choice, Question, Domain +from .models import Domain, Mailbox, Alias + +@login_required(login_url='/login/') +def delete_domain(request, domain_id): + domain = get_object_or_404(Domain, pk=domain_id) + domain.delete() + return HttpResponseRedirect(reverse('multimail:domains')) @login_required(login_url='/login/') -def vote(request, question_id): - question = get_object_or_404(Question, pk=question_id) - try: - selected_choice = question.choice_set.get(pk=request.POST['choice']) - except (KeyError, Choice.DoesNotExist): - # Redisplay the question voting form. - return render(request, 'multimail/detail.html', { - 'question': question, - 'error_message': "You didn't select a choice.", - }) - else: - selected_choice.votes += 1 - selected_choice.save() - # Always return an HttpResponseRedirect after successfully dealing - # with POST data. This prevents data from being posted twice if a - # user hits the Back button. - return HttpResponseRedirect(reverse('multimail:results', args=(question.id,))) +def delete_mailbox(request, mailbox_id): + mailbox = get_object_or_404(Mailbox, pk=mailbox_id) + mailbox.delete() + return HttpResponseRedirect(reverse('multimail:mailboxes')) + + +@login_required(login_url='/login/') +def delete_alias(request, alias_id): + alias = get_object_or_404(Alias, pk=alias_id) + alias.delete() + return HttpResponseRedirect(reverse('multimail:aliases')) + + +def logout(request): + auth_logout(request) + return HttpResponseRedirect(reverse('multimail:login')) diff --git a/backend/multimail/forms.py b/backend/multimail/forms.py new file mode 100644 index 0000000..7df34d9 --- /dev/null +++ b/backend/multimail/forms.py @@ -0,0 +1,64 @@ +from django.contrib.auth.decorators import login_required +from django.forms import ModelForm +from django.http import HttpResponseRedirect +from django.shortcuts import render + +from multimail.models import Domain, Mailbox, Alias + + +class DomainForm(ModelForm): + class Meta: + model = Domain + fields = ['domain'] + +class MailboxForm(ModelForm): + class Meta: + model = Mailbox + fields = '__all__' + +class AliasForm(ModelForm): + class Meta: + model = Alias + fields = '__all__' + +@login_required(login_url='/login/') +def edit_domain(request, domain_id): + domain = Domain.objects.get(id=domain_id) + if request.method == 'POST': + form = DomainForm(request.POST, instance=domain) + if form.is_valid(): + form.save() + return HttpResponseRedirect('/domains/') + + else: + form = DomainForm(instance=domain) + + return render(request, 'multimail/edit_domain.html', {'form': form}) + +@login_required(login_url='/login/') +def edit_mailbox(request, mailbox_id): + mailbox = Mailbox.objects.get(id=mailbox_id) + if request.method == 'POST': + form = MailboxForm(request.POST, instance=mailbox) + if form.is_valid(): + form.save() + return HttpResponseRedirect('/mailboxes/') + + else: + form = MailboxForm(instance=mailbox) + + return render(request, 'multimail/edit_mailbox.html', {'form': form}) + +@login_required(login_url='/login/') +def edit_alias(request, alias_id): + alias = Alias.objects.get(id=alias_id) + if request.method == 'POST': + form = AliasForm(request.POST, instance=alias) + if form.is_valid(): + form.save() + return HttpResponseRedirect('/aliases/') + + else: + form = AliasForm(instance=alias) + + return render(request, 'multimail/edit_alias.html', {'form': form}) \ No newline at end of file diff --git a/backend/multimail/templates/multimail/aliases.html b/backend/multimail/templates/multimail/aliases.html new file mode 100644 index 0000000..d41052a --- /dev/null +++ b/backend/multimail/templates/multimail/aliases.html @@ -0,0 +1,31 @@ +{% extends 'multimail/base.html' %} + +{% block content %} +

Aliases

+ + {% if alias_list %} + + + + + + + + + + + {% for alias in alias_list %} + + + + + + {% endfor %} + + +
SourceDestinationActions
{{ alias.source_username }}@{{ alias.source_domain }}{{ alias.destination_username }}@{{ alias.destination_domain }}Delete
+ {% else %} +

You haven't set up any aliases yet.

+ {% endif %} + +{% endblock %} \ No newline at end of file diff --git a/backend/multimail/templates/multimail/base.html b/backend/multimail/templates/multimail/base.html index 5f57bba..2e71a3a 100644 --- a/backend/multimail/templates/multimail/base.html +++ b/backend/multimail/templates/multimail/base.html @@ -16,6 +16,7 @@ + @@ -29,7 +30,7 @@
Domains Mailboxes - Aliases + Aliases
diff --git a/backend/multimail/templates/multimail/detail.html b/backend/multimail/templates/multimail/detail.html deleted file mode 100644 index 6025e4b..0000000 --- a/backend/multimail/templates/multimail/detail.html +++ /dev/null @@ -1,12 +0,0 @@ -

{{ question.question_text }}

- -{% if error_message %}

{{ error_message }}

{% endif %} - -
-{% csrf_token %} -{% for choice in question.choice_set.all %} - -
-{% endfor %} - -
\ No newline at end of file diff --git a/backend/multimail/templates/multimail/domains.html b/backend/multimail/templates/multimail/domains.html index c0d7e63..c697528 100644 --- a/backend/multimail/templates/multimail/domains.html +++ b/backend/multimail/templates/multimail/domains.html @@ -4,13 +4,26 @@

Domains

{% if domain_list %} -