def post(self, type=1): """ Adds a new User. """ data = api.payload form = RegistrationForm.from_json(data) if form.validate(): username = data.get('username', ) password = data.get('password') birthday = data.get('birthday') description = data.get('description') phone_number = data.get('phone_number') email = data.get('email') first_name = data.get('first_name') last_name = data.get('last_name') address = data.get('address') user = User(id=uuid.uuid4().hex, username=username.lower(), email=email.lower(), first_name=first_name, last_name=last_name, address=address, role_id=type, birthday=birthday, description=description, phone_number=phone_number) user.hash_password(password) cases = data.get('cases') if cases: user.add_cases(cases) db.session.add(user) db.session.commit() return {'element': user.to_json()}, 201 return {"message": form.errors}, 400
def post(self): """ Adds a new User. """ data = api.payload form = RegistrationForm.from_json(data) if form.validate(): username = data.get('username') password = data.get('password') refugee = data.get('is_refugee', False) email = data.get('email') user = User(id=uuid.uuid4().hex, username=username.lower(), email=email.lower(), refugee=refugee, role_id=1) user.hash_password(password) db.session.add(user) db.session.commit() return {'element': user.to_json()}, 201 return {"form_errors": form.errors}, 400