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