mirror of
https://github.com/bspeice/Melodia
synced 2024-12-04 13:58:18 -05:00
Commit the login page
Contains some fixes, etc. in order to make the login page work.
This commit is contained in:
parent
e3e6a6e475
commit
c5fec8cfd3
@ -130,7 +130,7 @@ TEMPLATE_DIRS = (
|
||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
os.path.join(PROJECT_FOLDER, 'web', 'templates')
|
||||
os.path.join(PROJECT_FOLDER, '..', 'web', 'views', 'templates')
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
|
5
web/static/js/jquery-ui.min.js
vendored
Normal file
5
web/static/js/jquery-ui.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
web/static/js/jquery.min.js
vendored
Normal file
2
web/static/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,11 +0,0 @@
|
||||
{% extends "base" %}
|
||||
|
||||
{% block page_title %}Login to Melodia{% endblock %}
|
||||
|
||||
{% block navbar_title %}Login to Melodia{% endblock %}
|
||||
|
||||
{# Specifying a blank sidebar, rather than sidebar_content, allows us to remove the sidebar entirely. #}
|
||||
{% block sidebar %}{% endblock %}
|
||||
|
||||
{% block body_content %}
|
||||
{% endblock %}
|
@ -1,11 +1,10 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
web_urls = patterns('web.views',
|
||||
web_urls = patterns('web.views.views',
|
||||
# Examples:
|
||||
# url(r'^$', 'Melodia.views.home', name='home'),
|
||||
# url(r'^Melodia/', include('Melodia.foo.urls')),
|
||||
|
||||
url(r'^$|main/', 'main'),
|
||||
url(r'^login/', 'login_page'),
|
||||
url(r'^authenticate/', 'authenticate'),
|
||||
)
|
||||
|
15
web/utils.py
Normal file
15
web/utils.py
Normal file
@ -0,0 +1,15 @@
|
||||
#Utilities file for the web client
|
||||
from django.utils import simplejson
|
||||
from django.http import HttpResponse
|
||||
|
||||
def json_response(**kwargs):
|
||||
#This is used to make sure that we have a standard json response
|
||||
response[]
|
||||
for key, value in kwargs.iteritems():
|
||||
response[key] = value
|
||||
|
||||
#After including anything specified in our arguments, make sure that we have a "success" parameter
|
||||
if not "success" in response:
|
||||
response["success"] = True
|
||||
|
||||
return HttpResponse(simplejson.dumps(response))
|
28
web/views.py
28
web/views.py
@ -1,28 +0,0 @@
|
||||
from django.http import HttpResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response, redirect
|
||||
|
||||
@login_required
|
||||
def main(request):
|
||||
return render_to_response("main", context_instance = RequestContext(request))
|
||||
|
||||
def login_page(request):
|
||||
return render_to_response("login", context_instance = RequestContext(request))
|
||||
|
||||
def authenticate(request):
|
||||
username = request.POST["username"]
|
||||
password = request.POST["password"]
|
||||
user = authenticate(username, password)
|
||||
|
||||
if user is not None:
|
||||
if user.isactive:
|
||||
login(request, user)
|
||||
redirect("/")
|
||||
else:
|
||||
#User is inactive
|
||||
pass
|
||||
else:
|
||||
#Authentication failed
|
||||
pass
|
0
web/views/__init__.py
Normal file
0
web/views/__init__.py
Normal file
@ -9,6 +9,8 @@ List of block elements in this page:
|
||||
body
|
||||
body_content
|
||||
scripts
|
||||
global_scripts
|
||||
page_scripts
|
||||
|
||||
{% endcomment %}
|
||||
|
||||
@ -40,7 +42,7 @@ List of block elements in this page:
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="row-fluid">
|
||||
|
||||
{# Sidebar code #}
|
||||
{# Note that the sidebar is its own block, so we can remove it if need be. #}
|
||||
@ -53,7 +55,7 @@ List of block elements in this page:
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="span10">
|
||||
<div class="span9">
|
||||
{% block body_content %}{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -66,5 +68,18 @@ List of block elements in this page:
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery-ui.min.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/bootstrap.min.js"></script>
|
||||
|
||||
{% block global_scripts %}
|
||||
<script type="text/javascript">
|
||||
{# Scripts used globally go here. #}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
<script type="text/javascript">
|
||||
{% block page_scripts %}
|
||||
{# This block is used by each page if they want to add additional scripts. #}
|
||||
{% endblock %}
|
||||
</script>
|
||||
{% endblock %}{# endblock scripts #}
|
||||
</html>
|
||||
<!-- vim: ft=htmldjango
|
33
web/views/templates/login
Normal file
33
web/views/templates/login
Normal file
@ -0,0 +1,33 @@
|
||||
{% extends "base" %}
|
||||
|
||||
{% block page_title %}Login to Melodia{% endblock %}
|
||||
|
||||
{% block navbar_title %}Login to Melodia{% endblock %}
|
||||
|
||||
{# Specifying a blank sidebar, rather than sidebar_content, allows us to remove the sidebar entirely. #}
|
||||
{% block sidebar %}{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<center>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
{# We display the elements ourselves, since we don't want to render errors #}
|
||||
<p><label>Username:</label>
|
||||
{{ auth_form.username }}
|
||||
</p>
|
||||
<p><label>Password:</label>
|
||||
{{ auth_form.password }}
|
||||
</p>
|
||||
<button class="btn btn-primary">Login to Melodia</button>
|
||||
</form>
|
||||
|
||||
{% if auth_form.non_field_errors %}
|
||||
<div class="alert alert-error span4 offset4">{{ auth_form.non_field_errors }}</div>
|
||||
{% endif %}
|
||||
|
||||
</center>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
<!-- vim: ft=htmldjango
|
@ -11,3 +11,5 @@
|
||||
{% block body_content %}
|
||||
<h1>Welcome to Melodia!</h1>
|
||||
{% endblock %}
|
||||
|
||||
<!-- vim: ft=htmldjango
|
40
web/views/views.py
Normal file
40
web/views/views.py
Normal file
@ -0,0 +1,40 @@
|
||||
from django.http import HttpResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth import authenticate, login, forms
|
||||
from django import forms as django_forms
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response, redirect
|
||||
|
||||
#Melodia-specific utilities
|
||||
from web_utils import json_response as json
|
||||
|
||||
@login_required
|
||||
def main(request):
|
||||
return render_to_response("main", context_instance = RequestContext(request))
|
||||
|
||||
def login_page(request):
|
||||
if request.method == "POST":
|
||||
#Someone is trying to log in
|
||||
return _user_authenticate(request)
|
||||
else:
|
||||
return render_to_response("login", context_instance = RequestContext(request,
|
||||
{"auth_form": forms.AuthenticationForm()} ))
|
||||
|
||||
def _user_authenticate(request):
|
||||
form = forms.AuthenticationForm(data=request.POST)
|
||||
if form.is_valid():
|
||||
try:
|
||||
cleaned_data = form.clean()
|
||||
print cleaned_data
|
||||
login(request, form.get_user())
|
||||
return redirect("/")
|
||||
|
||||
except django_forms.ValidationError:
|
||||
#Invalid login
|
||||
return json(success = False,
|
||||
message = "Either the username or the password was not recognized.")
|
||||
|
||||
else:
|
||||
return render_to_response("login", context_instance = RequestContext(request,
|
||||
{"auth_form": forms.AuthenticationForm(data=request.POST),
|
||||
"login_error": form.errors} ))
|
1
web/views/web_utils.py
Symbolic link
1
web/views/web_utils.py
Symbolic link
@ -0,0 +1 @@
|
||||
../web_utils.py
|
15
web/web_utils.py
Normal file
15
web/web_utils.py
Normal file
@ -0,0 +1,15 @@
|
||||
#Utilities file for the web client
|
||||
from django.utils import simplejson
|
||||
from django.http import HttpResponse
|
||||
|
||||
def json_response(**kwargs):
|
||||
#This is used to make sure that we have a standard json response
|
||||
response = []
|
||||
for key, value in kwargs.iteritems():
|
||||
response[key] = value
|
||||
|
||||
#After including anything specified in our arguments, make sure that we have a "success" parameter
|
||||
if not "success" in response:
|
||||
response["success"] = True
|
||||
|
||||
return HttpResponse(simplejson.dumps(response))
|
Loading…
Reference in New Issue
Block a user