implement login and logout
- add LogoutView to dashboard app - define logout URL pattern - only use login view from django.contrib.auth.views instead of including all auth URLs - change base template to support login/logout - add template dashboard/user_dashboard.html
This commit is contained in:
parent
1deed46d34
commit
2bc278ae92
5 changed files with 55 additions and 9 deletions
|
@ -4,6 +4,7 @@ from django.conf.urls import patterns, url
|
||||||
|
|
||||||
from .views import (
|
from .views import (
|
||||||
IndexView,
|
IndexView,
|
||||||
|
LogoutView,
|
||||||
UserDashboardView,
|
UserDashboardView,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,4 +14,6 @@ urlpatterns = patterns(
|
||||||
url(r'^$', IndexView.as_view(), name='dashboard'),
|
url(r'^$', IndexView.as_view(), name='dashboard'),
|
||||||
url(r'^user/(?P<slug>[\w0-9@.+-_]+)/$',
|
url(r'^user/(?P<slug>[\w0-9@.+-_]+)/$',
|
||||||
UserDashboardView.as_view(), name='customer_dashboard'),
|
UserDashboardView.as_view(), name='customer_dashboard'),
|
||||||
|
url(r'^logout/',
|
||||||
|
LogoutView.as_view(), name='logout'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,11 +4,14 @@ This module defines the views for the gnuviechadmin customer dashboard.
|
||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.http import HttpResponseForbidden
|
||||||
from django.views.generic import (
|
from django.views.generic import (
|
||||||
DetailView,
|
DetailView,
|
||||||
TemplateView,
|
TemplateView,
|
||||||
)
|
)
|
||||||
from django.contrib.auth import get_user_model
|
from django.views.generic.base import RedirectView
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.contrib.auth import get_user_model, logout
|
||||||
|
|
||||||
from braces.views import LoginRequiredMixin
|
from braces.views import LoginRequiredMixin
|
||||||
|
|
||||||
|
@ -21,11 +24,33 @@ class IndexView(TemplateView):
|
||||||
template_name = 'dashboard/index.html'
|
template_name = 'dashboard/index.html'
|
||||||
|
|
||||||
|
|
||||||
class UserDashboardView(DetailView, LoginRequiredMixin):
|
class UserDashboardView(LoginRequiredMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
This is the user dashboard view.
|
This is the user dashboard view.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
model = get_user_model()
|
model = get_user_model()
|
||||||
|
context_object_name = 'dashboard_user'
|
||||||
slug_field = 'username'
|
slug_field = 'username'
|
||||||
template_name = 'dashboard/user_dashboard.html'
|
template_name = 'dashboard/user_dashboard.html'
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if (request.user.is_staff or request.user == self.get_object()):
|
||||||
|
return super(UserDashboardView, self).dispatch(
|
||||||
|
request, *args, **kwargs
|
||||||
|
)
|
||||||
|
return HttpResponseForbidden(
|
||||||
|
_('You are not allowed to view this page.')
|
||||||
|
)
|
||||||
|
|
||||||
|
class LogoutView(RedirectView):
|
||||||
|
pattern_name = 'dashboard'
|
||||||
|
|
||||||
|
def get(self, *args, **kwargs):
|
||||||
|
logout(self.request)
|
||||||
|
return super(LogoutView, self).get(*args, **kwargs)
|
||||||
|
|
||||||
|
def get_redirect_url(self, *args, **kwargs):
|
||||||
|
if 'next' in self.request.GET:
|
||||||
|
return self.request.GET['next']
|
||||||
|
return super(LogoutView, self).get_redirect_url(*args, **kwargs)
|
||||||
|
|
|
@ -5,15 +5,13 @@ from django.conf import settings
|
||||||
|
|
||||||
import dashboard.urls
|
import dashboard.urls
|
||||||
|
|
||||||
from django.contrib.auth import urls as auth_urls
|
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
url(r'', include(dashboard.urls)),
|
url(r'', include(dashboard.urls)),
|
||||||
url(r'^auth/', include(auth_urls)),
|
url(r'^accounts/login/$', 'django.contrib.auth.views.login', name='login'),
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load staticfiles %}
|
{% load staticfiles i18n %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@ -32,21 +32,29 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||||
<div class="container">
|
<div class="container-fluid">
|
||||||
<div class="navbar-header">
|
<div class="navbar-header">
|
||||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</button>
|
</button>
|
||||||
<a class="navbar-brand" href="#">gnuviechadmin</a>
|
<a class="navbar-brand" href="{% url "dashboard" %}">gnuviechadmin</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="collapse navbar-collapse">
|
<div class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li class="active"><a href="#">Home</a></li>
|
<li class="active"><a href="{% if user.is_authenticated %}{% url 'customer_dashboard' slug=user.username %}{% else %}{% url 'dashboard' %}{% endif %}">Home</a></li>
|
||||||
<li><a href="#about">About</a></li>
|
<li><a href="#about">About</a></li>
|
||||||
<li><a href="#contact">Contact</a></li>
|
<li><a href="#contact">Contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<li><a href="#">{% trans "My Profile" %}</a></li>
|
||||||
|
<li><a href="{% url 'logout' %}">{% trans "Logout" %}</a></li>
|
||||||
|
{% else %}
|
||||||
|
<li><a href="{% url 'login' %}?next={{ request.path }}">{% trans "Sign In" %}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
</div><!--/.nav-collapse -->
|
</div><!--/.nav-collapse -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
12
gnuviechadmin/templates/dashboard/user_dashboard.html
Normal file
12
gnuviechadmin/templates/dashboard/user_dashboard.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% block title %}{{ block.super }} - {% blocktrans with full_name=dashboard_user.get_full_name %}Dashboard for {{ full_name }}{% endblocktrans %}{% endblock title %}
|
||||||
|
{% block page_title %}{% blocktrans with full_name=dashboard_user.get_full_name %}Dashboard for {{ full_name }}{% endblocktrans %}{% endblock page_title %}
|
||||||
|
{% block content %}
|
||||||
|
<p>Contract details</p>
|
||||||
|
<ul>
|
||||||
|
<li>Domains</li>
|
||||||
|
<li>Email mailboxes</li>
|
||||||
|
<li>Email addresses</li>
|
||||||
|
</ul>
|
||||||
|
{% endblock content %}
|
Loading…
Reference in a new issue