remove forms

This commit is contained in:
j 2011-10-22 14:27:00 +02:00
parent e6b3bd3e55
commit 485cca69b0

View file

@ -4,7 +4,6 @@ import random
random.seed() random.seed()
import re import re
from django import forms
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout from django.contrib.auth import authenticate, login, logout
from django.template import RequestContext, loader from django.template import RequestContext, loader
@ -27,11 +26,6 @@ import models
import managers import managers
class SigninForm(forms.Form):
username = forms.TextInput()
password = forms.TextInput()
def signin(request): def signin(request):
''' '''
param data { param data {
@ -53,9 +47,10 @@ def signin(request):
} }
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
form = SigninForm(data, request.FILES) if 'username' in data and 'password' in data:
if form.is_valid(): data['username'] = data['username'].strip()
if models.User.objects.filter(username=form.data['username']).count() == 0: data['password'] = data['password'].strip()
if models.User.objects.filter(username=data['username']).count() == 0:
response = json_response({ response = json_response({
'errors': { 'errors': {
'username': 'Unknown Username' 'username': 'Unknown Username'
@ -113,12 +108,6 @@ def signout(request):
actions.register(signout, cache=False) actions.register(signout, cache=False)
class SignupForm(forms.Form):
username = forms.TextInput()
password = forms.TextInput()
email = forms.TextInput()
def signup(request): def signup(request):
''' '''
param data { param data {
@ -141,21 +130,22 @@ def signup(request):
} }
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
form = SignupForm(data, request.FILES) if 'username' in data and 'password' in data:
if form.is_valid(): data['username'] = data['username'].strip()
if models.User.objects.filter(username=form.data['username']).count() > 0: data['password'] = data['password'].strip()
if models.User.objects.filter(username=data['username']).count() > 0:
response = json_response({ response = json_response({
'errors': { 'errors': {
'username': 'Username already exists' 'username': 'Username already exists'
} }
}) })
elif models.User.objects.filter(email=form.data['email']).count() > 0: elif models.User.objects.filter(email=data['email']).count() > 0:
response = json_response({ response = json_response({
'errors': { 'errors': {
'email': 'Email address already exits' 'email': 'Email address already exits'
} }
}) })
elif not form.data['password']: elif not data['password']:
response = json_response({ response = json_response({
'errors': { 'errors': {
'password': 'Password can not be empty' 'password': 'Password can not be empty'
@ -163,8 +153,8 @@ def signup(request):
}) })
else: else:
first_user = models.User.objects.count() == 0 first_user = models.User.objects.count() == 0
user = models.User(username=form.data['username'], email=form.data['email']) user = models.User(username=data['username'], email=data['email'])
user.set_password(form.data['password']) user.set_password(data['password'])
#make first user admin #make first user admin
user.is_superuser = first_user user.is_superuser = first_user
user.is_staff = first_user user.is_staff = first_user
@ -177,8 +167,8 @@ def signup(request):
setattr(list, key, l[key]) setattr(list, key, l[key])
list.save() list.save()
user = authenticate(username=form.data['username'], user = authenticate(username=data['username'],
password=form.data['password']) password=data['password'])
login(request, user) login(request, user)
user_json = models.init_user(user) user_json = models.init_user(user)
response = json_response({ response = json_response({
@ -529,12 +519,6 @@ Positions
actions.register(findUsers) actions.register(findUsers)
class ContactForm(forms.Form):
email = forms.EmailField()
subject = forms.TextInput()
message = forms.TextInput()
def contact(request): def contact(request):
''' '''
param data { param data {
@ -548,8 +532,7 @@ def contact(request):
} }
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
form = ContactForm(data, request.FILES) if 'email' in data and 'message' in data:
if form.is_valid():
email = data['email'] email = data['email']
template = loader.get_template('contact_email.txt') template = loader.get_template('contact_email.txt')
context = RequestContext(request, { context = RequestContext(request, {