Exemple #1
0
    def post(self):
        atributos = reqparse.RequestParser()
        atributos.add_argument('nome',
                               type=str,
                               required=True,
                               help='The field nome must be filled')
        atributos.add_argument('usuario',
                               type=str,
                               required=True,
                               help='The field usuario must be filled')
        atributos.add_argument('senha',
                               type=str,
                               required=True,
                               help='The field senha must be filled')
        atributos.add_argument('email',
                               type=str,
                               required=True,
                               help='The field email must be filled')
        dados = atributos.parse_args()

        if UsuarioModel.find_by_usuario(dados['usuario']):
            return {'Message': 'Usuario already exists'}, 500

        usuario = UsuarioModel(**dados)
        usuario.save_usuario()
        return {'Message': 'Usuario created with success'}, 201
Exemple #2
0
    def post(self):
        data = attributes.parse_args()
        if UsuarioModel.find_by_login(data['login']):
            return {"message": "The login '{}' already exists."
                    .format(data['login'])}

        if data['login'] and data['senha']:
            usuario = UsuarioModel(**data)
            usuario.senha = generate_password_hash(data['senha'])
            usuario.save_usuario()
            return {'message': 'Usuario created successfully!'}, 201  # Created
        return {'message': 'Request is missing required fields'}, 400
Exemple #3
0
 def put(self, cpf):
     dados = Usuario.argumentos.parse_args()
     usuario_encontrado = UsuarioModel.find_usuario(cpf)
     if usuario_encontrado:
         usuario_encontrado.update_usuario(**dados)
         usuario_encontrado.save_usuario()
         return usuario_encontrado.json(), 200  #OK
     usuario = UsuarioModel(cpf, **dados)
     try:
         usuario.save_usuario()
     except:
         return {
             'message':
             'Ocorreu um erro interno ao tentar salvar o usuario.'
         }, 500  # internal sever error
     return usuario.json(), 201  #created
Exemple #4
0
 def post(self, cpf):
     #verifica se o usuario existe
     if UsuarioModel.find_usuario(cpf):
         return {
             "messege": "Usuario de CPF '{}' já existe.".format(cpf)
         }, 400  #Bad request
     #se nao existe, cria um novo usuario
     dados = Usuario.argumentos.parse_args()
     usuario = UsuarioModel(cpf, **dados)
     try:
         usuario.save_usuario()
     except:
         return {
             'message':
             'Ocorreu um erro interno ao tentar salvar o usuario.'
         }, 500  #internal sever error
     return usuario.json()