예제 #1
0
    def post(cls):
        data = attributes.parse_args()
        usuario = UsuarioModel.find_by_login(data['login'])

        if usuario and check_password_hash(usuario.senha, data['senha']):
            token_de_acesso = create_access_token(identity=usuario.usuario_id)
            return {'access_token': token_de_acesso}, 200
        return {'message': 'The username or password is incorrect.'}, 401
예제 #2
0
 def post(cls):
     dados = _ARGUMENTOS.parse_args()
     user = UsuarioModel.find_by_login(dados.get('login'))
     if user is None or user.senha != dados.get('senha'):
         return errors._NOT_FOUND, server_code.NOT_FOUND
     if not user.ativado:
         return {'message': "user has not been activated"}, 400
     token_access = create_access_token(identity=user.user_id)
     return {"access_token": token_access}, 200
예제 #3
0
    def post(cls):
        dados = arg.parse_args()

        user = UsuarioModel.find_by_login(dados['login'])

        if user and safe_str_cmp(user.senha, dados['senha']):
            if not user.ativado:
                return {'message', 'Usuário não ativado'}, 401
            token = create_access_token(identity=user.user_id)
            return {'token': token}, 200
        return {'message', 'Usuário ou senha incorreto'}, 401
예제 #4
0
    def post(cls):
        dados = atributos.parse_args()
        user = UsuarioModel.find_by_login(dados['login'])
        if user and safe_str_cmp(user.senha, dados['senha']):

            if user.ativado:
                token_acesso = create_access_token(identity=user.user_id)
                return {'access_token': token_acesso}, 200
            else:
                return {'message': 'User not confirmed.'}, 400
        
        return {'message': 'User not find.'}, 404
예제 #5
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
예제 #6
0
    def post(self):
        dados = arg.parse_args()

        if UsuarioModel.find_by_login(dados['login']):
            return {'message': 'Usuário já cadastrado'}, 400

        novo_usuario = UsuarioModel(**dados)
        novo_usuario.ativado = False
        try:
            novo_usuario.save()
        except:
            return {'message': 'An server error'}, 500

        return novo_usuario.json(), 201
예제 #7
0
    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
예제 #8
0
    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