contact
This commit is contained in:
parent
92990d9a6e
commit
0fbb58849f
|
@ -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')
|
||||
|
|
|
@ -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")
|
||||
]
|
||||
|
|
|
@ -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())
|
||||
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')
|
|
@ -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
|
||||
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
|
|
@ -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);
|
||||
}
|
|
@ -12,7 +12,6 @@
|
|||
<link rel="stylesheet" media="all and (min-width: 700px)" type="text/css" href="{% static 'css/navbar.css' %}">
|
||||
<link rel="stylesheet" media="all and (min-width: 700px)" type="text/css" href="{% static 'css/container.css' %}">
|
||||
<link rel="stylesheet" media="all and (min-width: 700px)" type="text/css" href="{% static 'css/responsive.css' %}">
|
||||
|
||||
<link rel="stylesheet" media="all and (max-width: 699px)" type="text/css" href="{% static 'css/light.css' %}">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -359,21 +358,10 @@
|
|||
</div> -->
|
||||
</body>
|
||||
|
||||
{% block javascript %}
|
||||
<script type="text/javascript" src="{% static 'scripts/trigger_menu.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'scripts/smartphone_patch.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'scripts/pc-utils.js' %}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue