Exemple #1
0
    def signInUserPass(self, json_data):
        if not json_data:
            return {'message': 'No input data provided'}, 400

        user = Usuario.query.filter_by(username=json_data['username']).first()
        if not user:
            return {'message': 'User does not exist'}, 400

        if user.password != json_data['password']:
            return {'message': 'Password incorrect'}, 400

        return Usuario.serialize(user)
Exemple #2
0
    def post(self):
        result = ""
        json_data = request.get_json(force=True)
        auth = request.authorization

        if not auth:
            result = self.signInUserPass(json_data)

        else:
            user = Usuario.query.filter_by(
                api_key=json_data['api_key']).first()

            if user:
                result = Usuario.serialize(user)

            else:
                result = self.signInUserPass(json_data)

        return {"status": 'success', 'data': result}, 201