def post(self): dados = _ARGUMENTOS.parse_args() if UsuarioModel.find_by_login(dados.get('login')) is not None: return errors._EXISTENT, server_code.BAD_REQUEST if UsuarioModel.find_by_email(dados.get('email')) is not None: return errors._EXISTENT, server_code.BAD_REQUEST user = UsuarioModel(**dados) user.ativado = False try: user.save() user.send_confirmation_email() except Exception as e: user.delete() traceback.print_exc() return errors._SAVE_ERROR, server_code.INTERNAL_SERVER_ERROR return user.json(), server_code.OK
def post(self): dados = atributos.parse_args() if not dados['email'] or dados['email'] is None: return {"message": "The field 'email' cannot be left blank."}, 422 if UsuarioModel.find_by_email(dados['email']): return {'message': 'The email "{}" already exists.'.format(dados['email'])}, 422 if UsuarioModel.find_by_login(dados['login']): return {'message': 'The login "{}" already exists.'.format(dados['login'])}, 422 user = UsuarioModel(**dados) try: user.save() user.send_confirmacao_email() except: user.delete() traceback.print_exc() return {"message":"An internal error ocurred trying registry 'User'."}, 500 return {'message':'User created!'}, 201