def post(self): dados = arguments.parse_args() if not dados.get('email') or dados.get('email') is None: return {"message": "The field 'E-mail' cannot be left blank!"}, 400 if UserModel.find_by_email(dados['email']): return { "message": f"E-mail ({dados['email']}) already exists!" }, 400 if UserModel.find_by_login(dados['login']): return {"message": f"User ({dados['login']}) already exists!"}, 400 obj_user = UserModel(**dados) obj_user.ativado = False try: obj_user.save_user() obj_user.send_confirmation_email() except: obj_user.delete_user() traceback.print_exc() return { "message": "An internal error ocurred trying to save user." }, 500 return {"message": "User created successfully."}, 201
def post(self): dados = atributos.parse_args() if not dados.get('email') or dados.get('email') is None: return {"message": "The field 'email' cannot be left blank."}, 400 if UserModel.find_email(dados.get('email')): return { "message": "The email '{}' already exists.".format(dados.get('email')) }, 400 if UserModel.find_login(dados['login']): return { "message": "The login '{}' already exists.".format(dados['login']) }, 400 user = UserModel(**dados) user.ativado = False try: user.save() user.send_confirmation_email() except: user.delete() traceback.print_exc() return {"message": "An internal server error has occurred."}, 500 return {"message": "User created successfully!"}, 201
def post(self): dados = atributos.parse_args() if not dados.get('email') or dados.get( 'email') is None: #verifica se ela nulo ou se foi informado return {'message': "The field 'email' cannot be left blank."}, 400 if UserModel.find_by_email( dados['email']): #verificar se o email existe return { 'message': f"The email '{dados['email']}' already exists. " }, 400 if UserModel.find_by_login( dados['login']): #verificar se já existe o login na tabela return { "message": "The login '{}' already exists.".format(dados['login']) } user = UserModel(**dados) #ou dados['login'], dados['senha'] user.ativado = False #garantir que seja falso try: user.save_user() user.send_confirmation_email() except: user.delete_user() traceback.print_exc() return {'message': 'An internal server error has ocurred.'}, 500 return {'message': 'User created successfully!'}, 201 #created
def post(self): dados = argumentos.parse_args() if not dados.get('email') or dados.get('email') is None: return {"messege": "The field 'email' cannot be left blank"}, 400 if UserModel.find_by_email(dados['email']): return { "messege": "The email {} already existis".format(dados['email']) }, 400 if UserModel.find_by_login(dados['login']): return { "messege": "The login '{}' already existis.".format(dados['login']) } return { "messege": "The login '{}' already existis.".format(dados['login']) }, 400 user = UserModel(**dados) user.ativado = False user.save_user() try: user.save_user() user.send_confirmation_email() except: user.delete_user() traceback.print_exc() return {'messege': 'An internal server erro has ocurred.'}, 500 return {'messege': 'User created successfully!'}, 201
def post(self): dados = atributos.parse_args() if UserModel.find_by_login(dados['login']): return { "message": "The login '{}' already exists.".format(dados['login']) }, 400 #Bad Request user = UserModel(**dados) user.ativado = False user.save_user() return {'message': 'User created successfully!'}, 201 # Created
def post(self): dados = atributos.parse_args() if UserModel.find_by_login(dados['login']): return { "message": "The login '{}' already exists".format(dados['login']) } user = UserModel(**dados) user.ativado = False try: user.save_user() return {'message': 'User created success.'}, 201 except: return { 'message': 'An error ocurred trying to save user.' }, 500 # Internal Server Error
def post(self): atributos = reqparse.RequestParser() atributos.add_argument('nome', type=str) atributos.add_argument('login', type=str, required=True, help="The field 'login' cannot be left blank.") atributos.add_argument('email', type=str, required=True, help="The field 'email' cannot be left blank.") atributos.add_argument('senha', type=str, required=True, help="The field 'senha' cannot be left blank.") atributos.add_argument('ativado', type=bool) dados = atributos.parse_args() if UserModel.find_user_by_login(dados['login']): return {"message": f"User '{dados['login']}' already exists."}, 400 elif UserModel.find_user_by_email(dados['email']): return { "message": f"Email '{dados['email']}' already registered." }, 400 else: user = UserModel(**dados) user.ativado = False try: user.save_user() user.send_confirmation_email() return { "message": f"User '{dados['login']}' created successfully!" }, 201 except Exception as e: user.delete_user() return { "message": f"An internal error ({e}) ocurred trying to create user '{dados['login']}'." }, 500