This commit is contained in:
j 2010-01-26 18:54:50 +05:30
parent 4cb8078b4d
commit e6601e6dca

View file

@ -24,6 +24,8 @@ def api_login(request):
return {'status': {'code': int, 'text': string}} return {'status': {'code': int, 'text': string}}
''' '''
print "lgin"
response = {'status': {'code': 403, 'text': 'login failed'}} response = {'status': {'code': 403, 'text': 'login failed'}}
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
form = LoginForm(data, request.FILES) form = LoginForm(data, request.FILES)
@ -68,24 +70,28 @@ def api_register(request):
return {'status': {'code': int, 'text': string}} return {'status': {'code': int, 'text': string}}
''' '''
print "register"
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
form = RegisterForm(data, request.FILES) form = RegisterForm(data, request.FILES)
if form.is_valid(): if form.is_valid():
if models.User.objects.filter(username=form.data['username']).count() > 0: if models.User.objects.filter(username=form.data['username']).count() > 0:
response = {'status': 422, 'statusText': 'username or email exists'} print "username taken", form.data['username']
response = {'status': {'code':422, 'text': 'username or email exists'}}
elif models.User.objects.filter(email=form.data['email']).count() > 0: elif models.User.objects.filter(email=form.data['email']).count() > 0:
print "username taken", form.data['email']
response = {'status': {'code':422, 'text': 'username or email exists'}} response = {'status': {'code':422, 'text': 'username or email exists'}}
else: else:
user = models.User(username=form.data['username'], email=form.data['email']) user = models.User(username=form.data['username'], email=form.data['email'])
user.set_password(form.data['password']) user.set_password(form.data['password'])
user.save()
user = authenticate(username=form.data['username'], user = authenticate(username=form.data['username'],
password=form.data['password']) password=form.data['password'])
login(request, user) login(request, user)
response = {'status': {'code':200, 'text': 'account created'}} response = {'status': {'code':200, 'text': 'account created'}}
else: else:
print "form invalid"
print form.errors
response = {'status': {'code':422, 'text': 'username exists'}} response = {'status': {'code':422, 'text': 'username exists'}}
response = {'status': {'code':420, 'text': 'username or email exists'}}
return render_to_json_response(response) return render_to_json_response(response)
class RecoverForm(forms.Form): class RecoverForm(forms.Form):