Example #1
0
    def post(self, current_user):
        payload = requests.only(['name', 'cellphone'])
        name = payload['name']
        cellphone = payload['cellphone']

        contact = Contact(name, cellphone)
        db.session.add(contact)
        db.session.commit()
        return marshal(contact, contact_field, 'contact')
Example #2
0
    def post(self):
        payload = requests.only(['username', 'password'])
        username = payload['username']
        password = payload['password']

        user = User(username, password)

        db.session.add(user)
        db.session.commit()

        return marshal(user, user_fields, 'user')
Example #3
0
    def post(self):
        payload = requests.only(["name", "cellphone"])

        name = payload["name"]
        cellphone = payload["cellphone"]

        contact = Contact(name, cellphone)

        db.session.add(contact)
        db.session.commit()

        return marshal(contact, contact_field, "contact")
Example #4
0
    def post(self):
        payload = requests.only(["username", "password"])

        username = payload["username"]
        password = payload["password"]

        user = User(username, password)

        db.session.add(user)
        db.session.commit()

        return marshal(user, user_field, "user")
Example #5
0
    def delete(self):
        payload = requests.only(["id"])
        _id = payload["id"]

        contact = Contact.query.get(_id)

        if not contact:
            return {"message": "Contato não existe!"}

        db.session.delete(contact)
        db.session.commit()

        return marshal(contact, contact_field, "contatc")
Example #6
0
    def delete(self, current_user):
        payload = requests.only(['id'])
        _id = payload['id']

        contact = Contact.query.get(_id)

        if not contact:
            return {'message': 'Contact not found!'}

        db.session.delete(contact)
        db.session.commit()

        return marshal(contact, contact_field, 'contact')
Example #7
0
    def post(self):
        credential = requests.only(["matricula", "password"])

        user = User.query.filter_by(matricula=credential["matricula"]).first()

        if not user or not user.compare_password(credential["password"]):
            return {"error": "Credenciais invalidas."}, 400

        payload = {
            "id": user.id,
            "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=10)
        }
        try:
            token = jwt.encode(payload, app.config['SECRET_KEY'])
            return {"token": token.decode("utf-8")}
        except:
            return {"error": "Houve um erro ao tentar processar seu pedido"}
Example #8
0
    def post(self):
        payload = requests.only(['username', 'password'])
        username = payload['username']
        password = payload['password']

        user = User.query.filter_by(username=username).first()

        if not user and not user.compare_password(password):
            return {'message': 'Credentials not valid!'}, 404

        data = {
            'id': user.id,
            'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=10),
        }

        token = jwt.encode(data, current_app.config['SECRET_KEY'])

        return {'acess_token': token.decode('utf-8')}
Example #9
0
    def put(self):
        payload = requests.only(["id", "name", "cellphone"])

        _id = payload["id"]
        name = payload["name"]
        cellphone = payload["cellphone"]

        contact = Contact.query.get(_id)

        if not contact:
            return {"message": "Contato não existe!"}

        contact.name = name
        contact.cellphone = cellphone

        db.session.add(contact)
        db.session.commit()

        return marshal(contact, contact_field, "contact")
Example #10
0
    def post(self):
        payload = requests.only(["username", "password"])

        username = payload["username"]
        password = payload["password"]

        user = User.query.filter_by(username=username).first()

        if not user and not user.compare_password(password):
            return {"message": "Credenciais Inválidas!"}, 404

        data = {
            "id": user.id,
            "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=10)
        }

        token = jwt.encode(data, current_app.config["SECRET_KEY"])

        return {"acess_token": token.decode("utf-8")}
Example #11
0
    def put(self, current_user):
        payload = requests.only(['id', 'name', 'cellphone'])
        _id = payload['id']
        name = payload['name']
        cellphone = payload['cellphone']

        contact = Contact.query.get(_id)

        if not contact:
            return {'message': 'Contact not found!'}

        if name:
            contact.name = name
        if cellphone:
            contact.cellphone = cellphone

        db.session.add(contact)
        db.session.commit()

        return marshal(contact, contact_field, 'contact')
Example #12
0
    def post(self):
        hd = requests.only(["matricula", "password"])

        matricula = str(hd["matricula"])[0:7]
        password = hd["password"]

        bl = "http://aluno.seduc.ce.gov.br/api/dados_service/boletim"
        materias = []
        base = str(matricula) + ":" + str(password)
        en = base64.b64encode(base.encode('ascii'))
        b64user = en.decode('ascii')
        headers = {
            'Authorization': 'Basic ' + b64user,
            'User-Agent': 'okhttp/3.3.0',
            'Accept-Encoding': 'gzip',
            'Host': 'aluno.seduc.ce.gov.br',
            'AppVersionName': '1.2',
            'AppVersionName': '4',
            'Accept': 'application/json',
            'Cache-Control': 'no-cache'
        }

        r = get(bl, headers=headers).text
        rj = json.loads(r)

        fd = re.findall(r"(?!\:)[0-9.]+(?=\, \'n)", str(rj))

        for i in fd:
            if float(i) <= 6:
                materias.append(i)

        freq = "http://aluno.seduc.ce.gov.br/api/dados_service/frequencia"
        faltas = 0
        r = get(freq, headers=headers).text
        rj = json.loads(r)
        fq = re.findall(r"(?!\:)\d(?=\,)", str(rj))

        for nt in fq:
            faltas += int(nt)

        return {"mediaBaixa": materias[0], "faltas": str(faltas)}
Example #13
0
    def post(self):
        url = "http://aluno.seduc.ce.gov.br/api/dados_service/valida_login"
        credential = requests.only(["matricula", "password"])

        try:
            base = credential["matricula"] + ":" + credential["password"]
            en = base64.b64encode(base.encode('ascii'))
            b64user = en.decode('ascii')

            headers = {
                'Authorization': 'Basic ' + b64user,
                'User-Agent': 'okhttp/3.3.0',
                'Accept-Encoding': 'gzip',
                'Host': 'aluno.seduc.ce.gov.br',
                'AppVersionName': '1.2',
                'AppVersionName': '4',
                'Accept': 'application/json',
                'Cache-Control': 'no-cache'
            }

            req = get(url, headers=headers).text

            if "message" in req:
                return {"error": "Matricula ou senha invalida."}, 400

            try:
                user = User(credential["matricula"], credential["password"])

                db.session.add(user)
                db.session.commit()
            except:
                return {"error": "O usuario já consta no banco de dados."}, 400

            return marshal(user, users_fields, "user"), 200
        except Exception as e:
            print(credential)
            #return {"error":str(e)},500
            return {"error": "Matricula ou senha invalida."}, 500
Example #14
0
    def post(self, current_user):
        hd = requests.only(["matricula"])
        notas = Medias.query.filter_by(matricula=hd["matricula"]).first()

        return marshal(notas, boletim_fields, "Medias")