Adds login and logout and some buttons.
This commit is contained in:
1 parent
96bacb586d
commit
59bf27b5ab
8 files changed
+94
-19
No files matched your search
@@ -2,4 +2,5 @@ from django.conf.urls.defaults import patterns, include, url
|
|||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^$', 'bbs.main.views.home', name='home'),
|
url(r'^$', 'bbs.main.views.home', name='home'),
|
||||||
|
url(r'^register/$', 'bbs.main.views.register', name='register'),
|
||||||
)
|
)
|
||||||
+24
-1
@@ -1,11 +1,34 @@
|
|||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
from django.contrib.auth import login, logout as auth_logout
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import render_to_response, get_object_or_404
|
from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
|
|
||||||
from models import *
|
from models import *
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
|
if request.method == "POST":
|
||||||
|
form = AuthenticationForm(data=request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
# Log the user in.
|
||||||
|
login(request, form.get_user())
|
||||||
|
else:
|
||||||
|
if request.user.is_authenticated():
|
||||||
|
# Redirect to the register
|
||||||
|
return HttpResponseRedirect( reverse('bbs.main.views.register') )
|
||||||
|
else:
|
||||||
|
form = AuthenticationForm(request)
|
||||||
|
return render_to_response('home.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def register(request):
|
||||||
products = Product.objects.all()
|
products = Product.objects.all()
|
||||||
users = User.objects.all()
|
users = User.objects.all()
|
||||||
return render_to_response('home.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('register.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
def logout(request):
|
||||||
|
auth_logout(request)
|
||||||
|
return render_to_response('registration/logout.html', locals(), context_instance=RequestContext(request))
|
||||||
+1
-17
@@ -4,21 +4,5 @@
|
|||||||
{%endblock%}
|
{%endblock%}
|
||||||
|
|
||||||
{%block content%}
|
{%block content%}
|
||||||
<section id="register">
|
<a href="/register/">Kasse</a>
|
||||||
<div id="user">
|
|
||||||
Selg til:
|
|
||||||
{% for user in users %}
|
|
||||||
<button id="{{ user }}">{{ user }}</button>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<div id="products">
|
|
||||||
Vi selger:<br />
|
|
||||||
{% for product in products %}
|
|
||||||
<button id="{{ product.id }}">+ {{ product.name }}</button>
|
|
||||||
<button id="{{ product.id }}">- {{ product.name }}</button>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<div id="total">Totalt: <span class="total_text"></span></div>
|
|
||||||
<button id="submit">Kjøp</button>
|
|
||||||
</section>
|
|
||||||
{%endblock%}
|
{%endblock%}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{%block header%}
|
||||||
|
<h1>Biceps Bar System</h1>
|
||||||
|
{%endblock%}
|
||||||
|
|
||||||
|
{%block content%}
|
||||||
|
<section id="nav">
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% url main.views.logout %}">Logout</a></li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
<section id="register">
|
||||||
|
<div id="user">
|
||||||
|
Selg til:
|
||||||
|
{% for user in users %}
|
||||||
|
<button id="{{ user }}">{{ user }}</button>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div id="products">
|
||||||
|
Vi selger:<br />
|
||||||
|
{% for product in products %}
|
||||||
|
<button id="{{ product.id }}">+ {{ product.name }}</button>
|
||||||
|
<button id="{{ product.id }}">- {{ product.name }}</button>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div id="total">Totalt: <span class="total_text"></span></div>
|
||||||
|
<button id="submit">Kjøp</button>
|
||||||
|
</section>
|
||||||
|
{%endblock%}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Logg inn{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% include "registration/login_form.html" %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{% if form.errors %}
|
||||||
|
<p>Brukernavn og passord stemmer ikke overens. Prøv igjen.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form method="post" action="{% url django.contrib.auth.views.login %}" class="bp">
|
||||||
|
{% csrf_token %}
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th><label for="id_username">Brukernavn:</label></th>
|
||||||
|
<td>{{ form.username }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><label for="id_password">Passord: </label></th>
|
||||||
|
<td>{{ form.password }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<input type="submit" value="Logg inn" />
|
||||||
|
<input type="hidden" name="next" value="{{ next }}" />
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Logg inn{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
Du er logget ut. Vil du <a href="{% url main.views.home %}">logge inn igjen</a>.
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -4,7 +4,9 @@ admin.autodiscover()
|
|||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^$', 'main.views.home', name='home'),
|
url(r'^$', 'main.views.home', name='home'),
|
||||||
url(r'^bbs/', include('main.urls')),
|
url(r'', include('main.urls')),
|
||||||
|
url(r'^accounts/login/$', 'django.contrib.auth.views.login'),
|
||||||
|
url(r'^logout/$', 'main.views.logout'),
|
||||||
|
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
# Uncomment the admin/doc line below to enable admin documentation:
|
# Uncomment the admin/doc line below to enable admin documentation:
|
||||||
|
|||||||
Reference in new issue
Block a user