def add(request): POSTdata = json.loads(request.body) user = POSTdata['user'] password = POSTdata['password'] response_data = {} try: dbData = model_to_dict(Users.objects.get(user=user)) except Users.DoesNotExist: dbData = {'user': None} if dbData['user'] == user: response_data['errCode'] = ERR_USER_EXISTS elif user == '' or len(user) > 128: response_data['errCode'] = ERR_BAD_USERNAME elif len(password) > 128: response_data['errCode'] = ERR_BAD_PASSWORD else: newEntry = Users(user=user, password=password, count=1) newEntry.save() response_data['errCode'] = SUCCESS response_data['count'] = 1 return HttpResponse(json.dumps(response_data), content_type="application/json")
def add(request): # return HttpResponse("Hello, world. This is an add.") # if username not already in the db, add username and password, perform login data = json.loads(request.body) username = data['username'] password = data['pwd'] user = Users.objects.filter(uid=username) if user.count() != 0: return HttpResponse(json.dumps({ 'errCode' : ERR_USER_EXISTS}), content_type="application/json") if len(username) > MAX_USERNAME_LENGTH or len(username) == 0: return HttpResponse(json.dumps({ 'errCode' : ERR_BAD_USERNAME}), content_type="application/json") if len(password) > MAX_PASSWORD_LENGTH: return HttpResponse(json.dumps({ 'errCode' : ERR_BAD_PASSWORD}), content_type="application/json") user = Users(uid=username, pid=password) user.save() return HttpResponse(json.dumps({ 'errCode' : SUCCESS, 'count' : user.count}), content_type="application/json")