Fix login / logout views

This commit is contained in:
M.Ravi 2023-11-30 15:02:21 +05:30
parent 889c71d069
commit 91e7f44eed
4 changed files with 45 additions and 9 deletions

View file

@ -11,31 +11,31 @@
{% trans "Welcome" %} {{request.user.name}}
</div>
<div class="hosting-dashboard-content">
<a href="{% url 'hosting:create_virtual_machine' %}" class="hosting-dashboard-item">
<a href="{% url 'hosting:dashboard' %}" class="hosting-dashboard-item">
<h2>{% trans "Create VM" %}</h2>
<div class="hosting-dashboard-image">
<img class="svg-img" src="{% static 'hosting/img/plusVM.svg' %}">
</div>
</a>
<a href="{% url 'hosting:virtual_machines' %}" class="hosting-dashboard-item">
<a href="{% url 'hosting:dashboard' %}" class="hosting-dashboard-item">
<h2>{% trans "My VMs" %}</h2>
<div class="hosting-dashboard-image">
<img class="svg-img" src="{% static 'hosting/img/vm.svg' %}">
</div>
</a>
<a href="{% url 'hosting:ssh_keys' %}" class="hosting-dashboard-item">
<a href="{% url 'hosting:dashboard' %}" class="hosting-dashboard-item">
<h2>{% trans "My SSH Keys" %}</h2>
<div class="hosting-dashboard-image">
<img class="svg-img" src="{% static 'hosting/img/key.svg' %}">
</div>
</a>
<a href="{% url 'hosting:invoices' %}" class="hosting-dashboard-item">
<a href="{% url 'hosting:dashboard' %}" class="hosting-dashboard-item">
<h2>{% trans "My Bills" %}</h2>
<div class="hosting-dashboard-image">
<img class="svg-img" src="{% static 'hosting/img/billing.svg' %}">
</div>
</a>
<a href="{% url 'hosting:settings' %}" class="hosting-dashboard-item">
<a href="{% url 'hosting:dashboard' %}" class="hosting-dashboard-item">
<h2>{% trans "My Settings" %}</h2>
<div class="hosting-dashboard-image">
<img class="svg-img" src="{% static 'hosting/img/dashboard_settings.svg' %}">

View file

@ -1,4 +1,4 @@
{% load static i18n %}
{% load static i18n custom_tags %}
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">

View file

@ -12,7 +12,7 @@ from .views import (
#HostingPricingView, CreateVirtualMachinesView, HostingBillListView,
#HostingBillDetailView, SSHKeyDeleteView, SSHKeyListView,
#SSHKeyChoiceView, DashboardView, SettingsView,
ResendActivationEmailView,
ResendActivationEmailView, DashboardView, CustomLogoutView
#InvoiceListView, InvoiceDetailView, CheckUserVM
)
@ -30,7 +30,8 @@ urlpatterns = [
name='reset_password'),
re_path(r'reset-password-confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
PasswordResetConfirmView.as_view(), name='reset_password_confirm'),
re_path('^logout/', auth_views.LogoutView.as_view(), name='logout'),
re_path('^logout/', CustomLogoutView.as_view(), name='logout'),
re_path(r'^validate/(?P<validate_slug>.*)/$',
SignupValidatedView.as_view(), name='validate')
SignupValidatedView.as_view(), name='validate'),
re_path(r'dashboard/?$', DashboardView.as_view(), name='dashboard'),
]

View file

@ -2,6 +2,8 @@ import uuid
from django.conf import settings
from django.contrib.auth.tokens import default_token_generator
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.views import LogoutView
from django.core.files.base import ContentFile
from django.http import HttpResponseRedirect
from django.urls import reverse_lazy, reverse
@ -316,3 +318,36 @@ class IndexView(View):
def get(self, request, *args, **kwargs):
context = self.get_context_data()
return render(request, self.template_name, context)
class DashboardView(LoginRequiredMixin, View):
template_name = "hosting/dashboard.html"
login_url = reverse_lazy('hosting:login')
def get_context_data(self, **kwargs):
context = {}
return context
@method_decorator(decorators)
def get(self, request, *args, **kwargs):
context = self.get_context_data()
context['has_invoices'] = False
bills = []
# try:
# if hasattr(self.request.user, 'stripecustomer'):
# bills = MonthlyHostingBill.objects.filter(
# customer=self.request.user.stripecustomer
# )
# if len(bills) > 0:
# context['has_invoices'] = True
# except MonthlyHostingBill.DoesNotExist as dne:
# logger.error("{}'s monthly hosting bill not imported ?".format(
# self.request.user.email
# ))
return render(request, self.template_name, context)
class CustomLogoutView(LogoutView):
next_page = reverse_lazy('hosting:login')