diff --git a/web/urls.py b/web/urls.py index a8e7b4e..9686a23 100644 --- a/web/urls.py +++ b/web/urls.py @@ -1,10 +1,11 @@ from django.conf.urls import patterns, include, url -web_urls = patterns('web.views.views', +web_urls = patterns('web.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'^$|main/', 'index.main'), + url(r'^login/', 'authentication.login'), + url(r'^logout/', 'authentication.logout'), ) diff --git a/web/views/views.py b/web/views/authentication.py similarity index 57% rename from web/views/views.py rename to web/views/authentication.py index de72d9e..44f4cf9 100644 --- a/web/views/views.py +++ b/web/views/authentication.py @@ -1,18 +1,33 @@ 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.contrib.auth import login as django_login +from django.contrib.auth import logout as django_logout +from django.contrib.auth import 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 _user_authenticate(request): + form = forms.AuthenticationForm(data=request.POST) + if form.is_valid(): + try: + cleaned_data = form.clean() + django_login(request, form.get_user()) + return redirect("/") -def login_page(request): + except: + #Invalid login, or ValidationError + return render_to_response("login", context_instance = RequestContext(request, + {"auth_form": forms.AuthenticationForm(data=request.POST), + "login_error": "Internal error trying to log in."} )) + else: + return render_to_response("login", context_instance = RequestContext(request, + {"auth_form": forms.AuthenticationForm(data=request.POST), + "login_error": "Unrecognized username or password."} )) + +def login(request): if request.method == "POST": #Someone is trying to log in return _user_authenticate(request) @@ -20,21 +35,6 @@ def login_page(request): 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} )) +def logout(request): + django_logout(request) + return redirect("/login") diff --git a/web/views/index.py b/web/views/index.py new file mode 100644 index 0000000..cb36d67 --- /dev/null +++ b/web/views/index.py @@ -0,0 +1,13 @@ +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("index", context_instance = RequestContext(request)) diff --git a/web/views/templates/base b/web/views/templates/base index 419da00..7355bda 100644 --- a/web/views/templates/base +++ b/web/views/templates/base @@ -36,7 +36,18 @@ List of block elements in this page: diff --git a/web/views/templates/components/playlist_sidebar b/web/views/templates/components/playlist_sidebar new file mode 100644 index 0000000..a0d9ecf --- /dev/null +++ b/web/views/templates/components/playlist_sidebar @@ -0,0 +1,11 @@ +{# This component assumes it has been placed in a sidebar, and controls options related to playlists. #} + + + + +