diff --git a/account/views.py b/account/views.py index 8601dc6..fd98bd3 100644 --- a/account/views.py +++ b/account/views.py @@ -1,12 +1,13 @@ +#-*- coding: utf-8 -*- + from django.shortcuts import render, redirect from django.contrib.auth import authenticate from django.contrib.auth.models import User from django.contrib.auth import login as a_login, logout as a_logout from django.core.urlresolvers import reverse -from django.core.validators import validate_email from django.conf import settings as s from django.http import JsonResponse -from django.http import HttpResponseNotFound +from django.http import Http404 from account.forms import * from home.views import homepage @@ -38,12 +39,12 @@ def login(request): return JsonResponse(data) return render(request, 'account/login.html', locals()) else: - #someone trying to do unwanted things, log it + #hack attempt, log it print(request.POST) elif request.method == "GET": return render(request, 'account/login.html') - return HttpResponseNotFound() + raise Http404 def logout(request): """ @@ -94,7 +95,7 @@ def signup(request): return render(request, 'account/signup.html', locals()) elif request.method == "GET": return render(request, 'account/signup.html', locals()) - return HttpResponseNotFound() + raise Http404 def account(request): return render(request, 'account.html') diff --git a/home/urls.py b/home/urls.py index fa87bef..9b6d1f5 100644 --- a/home/urls.py +++ b/home/urls.py @@ -3,4 +3,6 @@ from django.conf.urls import url import home.views as v urlpatterns = [ url(r'^$', v.homepage, name="homepage"), + url(r'^contact$', v.contact, name="contact"), + url(r'^articlĂȘ$', v.article, name="article") ] diff --git a/home/views.py b/home/views.py index baec0b4..4e42abd 100644 --- a/home/views.py +++ b/home/views.py @@ -1,9 +1,39 @@ #-*- coding: utf-8 -*- from django.shortcuts import render, redirect -from django.contrib.auth import authenticate -from django.http import HttpResponse, Http404 +from django.contrib.auth import authenticate, get_user +from django.contrib.auth.models import User +from django.http import Http404 +from django.http import JsonResponse +from home.forms import * def homepage(request): + """ + Render home page. + """ + return render(request, 'home/homepage.html', locals()) - return render(request, 'home/homepage.html', locals()) \ No newline at end of file +def contact(request): + """ + Form validation and contact page rendering. + """ + user = get_user(request) + form = ContactForm(request.POST or None, initial={'email': user.email if user.is_authenticated else ''}) + if request.method == "POST": + if form.is_valid(): + #TODO send email ? save into database ? + data = { + 'sent':True + } + if('HTTP_X_REQUESTED_WITH' in request.META and request.META['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'): + return JsonResponse(data) + return render(request, 'home/contact.html', locals()) + else: + #hack attempt, log it + print(request.POST) + elif request.method == "GET": + return render(request, 'home/contact.html', locals()) + raise Http404 + +def article(request): + return render(request, 'home/article.html') \ No newline at end of file diff --git a/planete_casio/settings.py b/planete_casio/settings.py index c0aa499..dc041cd 100644 --- a/planete_casio/settings.py +++ b/planete_casio/settings.py @@ -151,4 +151,8 @@ STATICFILES_DIRS = ( USERNAME_MIN_LENGTH = 3 USERNAME_MAX_LENGTH = 30 PASSWORD_MIN_LENGTH = 8 -PASSWORD_MAX_LENGTH = 72 # maximum number of characters for bcrypt \ No newline at end of file +PASSWORD_MAX_LENGTH = 72 # maximum number of characters for bcrypt +OBJECT_MIN_LENGTH = 3 +OBJECT_MAX_LENGTH = 255 +MAILBODY_MIN_LENGTH = 3 +MAILBODY_MAX_LENGTH = 10000 \ No newline at end of file diff --git a/sfiles/scripts/pc-utils.js b/sfiles/scripts/pc-utils.js index 31d8020..f3dd880 100644 --- a/sfiles/scripts/pc-utils.js +++ b/sfiles/scripts/pc-utils.js @@ -48,13 +48,27 @@ function ajaxWrapper(evt){ /* Add event listener on submit for all form with class with-ajax. */ -var ele; -var elems = document.getElementsByClassName('with-ajax'); -for(i = 0; i < elems.length; i++){ - ele = elems[i]; - if(ele.addEventListener){ // Normal people - ele.addEventListener("submit", ajaxWrapper, false); - }else if(ele.attachEvent){ // Retarded user using IE - ele.attachEvent("onsubmit", ajaxWrapper); + +window.onload = function(){ + + var ele; + var elems = document.getElementsByClassName('with-ajax'); + for(i = 0; i < elems.length; i++){ + ele = elems[i]; + if(ele.addEventListener){ // Normal people + ele.addEventListener("submit", ajaxWrapper, false); + }else if(ele.attachEvent){ // Retarded user using IE + ele.attachEvent("onsubmit", ajaxWrapper); + } } + + if(getCookie('pc_notif') == 'true') + document.getElementsByClassName('alert')[0].parentNode.removeChild(document.getElementsByClassName('alert')[0]); + if(getCookie('pc_notif_2') == 'true') + document.getElementsByClassName('alert')[0].parentNode.removeChild(document.getElementsByClassName('alert')[0]); + +} + +function login(response){ + alert(response); } \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 1bc285f..2729e91 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,7 +12,6 @@ - @@ -359,21 +358,10 @@ --> +{% block javascript %} - - +{% endblock %}