def post(self): data = UserRegister.parser.parse_args() if not data.get('phone', None) is None: parsed_phone = parse_phone(data['phone']) if parsed_phone is None: return {"message": "Invalid phone format for the user"}, 400 data['phone'] = "-".join(parsed_phone).strip('-') if UserModel.find_by_username(data['username']): return {"message": "A user with that username already exists"}, 400 user = UserModel(**data) try: user.save_to_db() except: return {"message": "An error occurred creating the user."}, 500 return {"message": "User created successfully."}, 201
def post(self): ''' Create a new user ''' args = user_parser.parse_args() if UserModel.find_by_email(args['email']): return {"message": "Email is already registered."}, 400 new_user = UserModel(fname=args['fname'], lname=args['lname'], username=args['username'], email=args['email']) new_user.set_password(args['password']) new_user.save_to_db() result = api_ns.marshal(new_user, user_model) return result, http.client.CREATED