Commit 4349a128 authored by Jason Yeomans's avatar Jason Yeomans
Browse files

Add lots of user stuff... still having issues

parent 83935a43
......@@ -6,6 +6,7 @@ admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^login/$', views.login, name='login'),
url(r'^logout/$', views.logout_view, name='logout_view'),
url(r'^buildings/$', views.buildings, name='buildings'),
url(r'^building/(?P<buildingName>[a-zA-Z]+)$', views.building, name='building'),
)
from django.http import HttpResponse
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.template import RequestContext, loader
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import authenticate, logout
from api.models import Building, Room
......@@ -30,7 +32,33 @@ def building(request, buildingName):
return HttpResponse(template.render(context))
def login(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = AuthenticationForm(data = request.POST)
# check whether it's valid:
form.is_valid()
form_data = form.clean()
user = form.get_user()
if user is not None:
# the password verified for the user
if user.is_active:
print("User is valid, active and authenticated")
else:
print("The password is valid, but the account has been disabled!")
else:
# the authentication system was unable to verify the username and password
print("The username and password were incorrect.")
return HttpResponseRedirect('/')
# if a GET (or any other method) we'll create a blank form
else:
form = AuthenticationForm()
template = loader.get_template('login.html')
context = RequestContext(request, {
'form' : form,
})
return HttpResponse(template.render(context))
def logout_view(request):
logout(request)
return HttpResponseRedirect('/')
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #eee;
}
.form-signin {
max-width: 330px;
padding: 15px;
......@@ -28,7 +22,7 @@ body {
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="email"] {
.form-signin input[type="text"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
......
......@@ -5,7 +5,7 @@
{% load staticfiles %}
<link href="/static/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="/static/css/style.css" rel="stylesheet" media="screen">
<script src="/static/js/jquery-1.10.2.min.js"></script>
<script src="/static/js/jquery-2.1.1.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<link rel="icon" href="/static/img/favicon.ico">
<meta charset="utf-8">
......
......@@ -19,13 +19,13 @@
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
{% if use.is_authenticated %}
{% if user.is_authenticated %}
<li><a href="#">{{ user.username }}</a>
</li>
<li><a href="#">Logout</a>
<li><a href="/logout/">Logout</a>
</li>
{% else %}
<li><a href="/login">Login</a>
<li><a href="/login/">Login</a>
</li>
{% endif %}
</ul>
......
{% extends 'layouts/base.html' %} {% block title %} GMU RoomList &bull; Homepage {% endblock %} {% block content %}
{% extends 'layouts/base.html' %} {% block title %} GMU RoomList &bull; Login {% endblock %} {% block content %}
<link href="/static/css/signin.css" rel="stylesheet" media="screen">
......@@ -11,12 +11,13 @@
</div>
</div>
<form class="form-signin" role="form">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputEmail" class="sr-only">Username</label>
<input type="username" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<form class="form-signin" role="form" action="/login/" method="post">
{% csrf_token %}
<h2 class="form-signin-heading">Please sign in</h2>{{ form.errors }} {{ form.non_field_errors }} {{ form.username.errors }}
<label for="{{ form.username.id_for_label }}" class="sr-only">NetID</label>
{{ form.username }} {{ form.password.errors }}
<label for="{{ form.password.id_for_label }}" class="sr-only">Password</label>
{{ form.password }}
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
......@@ -25,5 +26,4 @@
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment