def post(self): data = _user_parser.parse_args() if UserModel.find_by_email(data['email']): return {"message": "A user with that email already exits."}, 400 user = UserModel(data['user_name'], data['email'], data['password'], data['auth_level']) user.save_to_db() return {"message": "Student created successfully."}, 201
def put(self, id): claims = get_jwt_claims() data = _user_parser.parse_args() user = UserModel.find_by_id(id) if user or claims['role'] == 'admin': user.username = data['user_name'] user.email = data['email'] user.auth_level = data['auth_level'] if data['password']: user.password = data['password'] else: user = UserModel(id, **data) user.save_to_db() return user.json()