def create_user(request): data = json.loads(request.body) errors = {} for field in REQ_FIELDS: if field not in data: errors[field] = [_('This field is required')] for inputfield in data: if inputfield not in ALL_FIELDS: errors[inputfield] = [_('Unrecognized field')] if errors: raise ValidationError(errors) dup_username = User.objects.filter(username=data['username']) dup_email = User.objects.filter(email=data['email']) if dup_username.exists(): return _conflict_response(_('Username is already in use')) if dup_email.exists(): # BE WARNED - The iOS application relies on this error message string. # If you change this you WILL NEED TO ALTER CODE THERE AS WELL. return _conflict_response(_('Email is already in use')) user = User(**data) # Needed to properly hash the password user.set_password(data['password']) user.active = True user.save() RegistrationProfile.objects.create_profile(user) return {'status': 'success', 'id': user.pk}
def create_user(request): data = json.loads(request.body) errors = {} for field in REQ_FIELDS: if field not in data: errors[field] = [trans('This field is required')] for inputfield in data: if inputfield not in ALL_FIELDS: errors[inputfield] = [trans('Unrecognized field')] if errors: raise ValidationError(errors) dup_username = User.objects.filter(username=data['username']) dup_email = User.objects.filter(email=data['email']) if dup_username.exists(): return _conflict_response(trans('Username is already in use')) if dup_email.exists(): # BE WARNED - The iOS application relies on this error message string. # If you change this you WILL NEED TO ALTER CODE THERE AS WELL. return _conflict_response(trans('Email is already in use')) user = User(**data) # Needed to properly hash the password user.set_password(data['password']) user.active = True user.save() RegistrationProfile.objects.create_profile(user) return {'status': 'success', 'id': user.pk}
def create_user(request): data = json.loads(request.body) if 'allow_email_contact' not in data: data['allow_email_contact'] = False errors = {} for field in REQ_FIELDS: if field not in data: errors[field] = [trans('This field is required')] for inputfield in data: if inputfield not in ALL_FIELDS: errors[inputfield] = [trans('Unrecognized field')] if errors: raise ValidationError(errors) dup_username = User.objects.filter(username=data['username']) dup_email = User.objects.filter(email=data['email']) if dup_username.exists(): return _conflict_response(trans('Username is already in use')) if dup_email.exists(): return _conflict_response(trans('Email is already in use')) user = User(**data) # Needed to properly hash the password user.set_password(data['password']) user.active = True user.save() RegistrationProfile.objects.create_profile(user) return {'status': 'success', 'id': user.pk}