Skip to content

Commit

Permalink
configured django authentication.
Browse files Browse the repository at this point in the history
refactored templates to make them slightly cleaner.
  • Loading branch information
aausch committed Nov 6, 2013
1 parent 73ce084 commit 2ecf247
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 24 deletions.
11 changes: 11 additions & 0 deletions chat/templates/chats/base_chat.html
@@ -0,0 +1,11 @@
{% extends "base.html" %}

{% block content %}
{{ block.super }}
<h1> {{ chat.name }} </h1>
<textarea name="term" id="inputbox" cols="40" rows="4"></textarea>
<div id="message_list">
<ul>
</ul>
</div>
{% endblock %}
14 changes: 4 additions & 10 deletions chat/templates/chats/chat_room.html
@@ -1,6 +1,7 @@
{% extends "chats/base_chat.html" %}
{% load staticfiles %}
<html>
<head>
{% block header %}
{{ block.super }}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="{% static "jquery.gracefulWebSocket.js" %}"></script>
<script type="text/javascript">
Expand Down Expand Up @@ -32,11 +33,4 @@

});
</script>
</head>
<h1> {{ chat.name }} </h1>
<textarea name="term" id="inputbox" cols="40" rows="4"></textarea>
<div id="message_list">
<ul>
</ul>
</div>
</html>
{% endblock %}
5 changes: 5 additions & 0 deletions chat/templates/chats/index.html
@@ -1,3 +1,7 @@
{% extends "base.html" %}

{% block content %}
{{ block.super }}
{% if chat_list %}
<ul>
{% for chat in chat_list %}
Expand All @@ -7,3 +11,4 @@
{% else %}
<p>No chats are available.</p>
{% endif %}
{% endblock %}
19 changes: 6 additions & 13 deletions chat/templates/chats/longpoll_chat_room.html
@@ -1,15 +1,8 @@
{% extends "chats/base_chat.html" %}
{% load staticfiles %}
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="{% static "long_poll.js" %}"></script>
</head>
{% block header %}
{{ block.super }}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="{% static "long_poll.js" %}"></script>
{% endblock %}

<h1>{{ chat.name }}</h1>
<textarea name="term" id="inputbox" cols="40" rows="4"></textarea>
<div id="message_list">
<ul>
</ul>
</div>

</html>
5 changes: 4 additions & 1 deletion chat/views.py
@@ -1,19 +1,22 @@
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required

from chat.models import ChatRoom

@login_required
def index(request):
chat_rooms = ChatRoom.objects.order_by('name')[:5]
context = {
'chat_list': chat_rooms,
}
return render(request,'chats/index.html', context)

@login_required
def chat_room(request, chat_room_id):
chat = get_object_or_404(ChatRoom, pk=chat_room_id)
return render(request, 'chats/chat_room.html', {'chat': chat})

@login_required
def longpoll_chat_room(request, chat_room_id):
chat = get_object_or_404(ChatRoom, pk=chat_room_id)
return render(request, 'chats/longpoll_chat_room.html', {'chat': chat})
9 changes: 9 additions & 0 deletions django_twisted_chat/templates/base.html
@@ -0,0 +1,9 @@
{% extends "base_generic.html" %}

{% block title %}
Some Chat App
{% endblock %}

{% block header %}
Welcome {{ user.username }}! Chat to your heart's content :) <br/><a href="/accounts/logout">logout</a>
{% endblock %}
13 changes: 13 additions & 0 deletions django_twisted_chat/templates/base_generic.html
@@ -0,0 +1,13 @@
<html>
<head>
{% block header %}
{% endblock %}
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<!-- header, etc -->
{% block content %}
{% endblock %}
<!-- footer -->
</body>
</html>
26 changes: 26 additions & 0 deletions django_twisted_chat/templates/registration/login.html
@@ -0,0 +1,26 @@
{% extends "base_generic.html" %}

{% block content %}

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>

{% endblock %}
14 changes: 14 additions & 0 deletions django_twisted_chat/templates/registration/logout.html
@@ -0,0 +1,14 @@
{% extends "base_generic.html" %}
{% block header %}
<script>
function redirect(){
window.location.href = "/";
}

setTimeout(redirect, 2000);
</script>
{% endblock %}

{% block content %}
<h2> Logging out ... </h2>
{% endblock %}
2 changes: 2 additions & 0 deletions django_twisted_chat/urls.py
Expand Up @@ -8,4 +8,6 @@
url(r'^(/)?$', RedirectView.as_view(url='/chats/')),
url(r'^chats/', include('chat.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/login/$', 'django.contrib.auth.views.login'),
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'template_name': 'registration/logout.html'}),
)

0 comments on commit 2ecf247

Please sign in to comment.