コード例 #1
0
    def delete(self):
        parser = reqparse.RequestParser()
        parser.add_argument('image_id')
        args = parser.parse_args()
        try:
            # Check Authenticated
            result = Authentication.isAuthenticated()
            if (result == None):
                return make_response(
                    jsonify({"status": "You are not Logged In"}), 401)
            profile_id = result['profile_id']

            result = DatabaseConnection.callprocONE("GetImageUsage",
                                                    (args['image_id'], ""))
            if (result['numPosts'] == 0):
                DatabaseConnection.callprocONE("DeleteImage",
                                               (args['image_id'], ""))
                DatabaseConnection.commit()
                return make_response(
                    jsonify({"status": "Image Delete Successfully"}), 200)
            else:
                return make_response(
                    jsonify({"status": "Image is being referenced by a Post"}),
                    400)

        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)
コード例 #2
0
    def post(self):
        result = Authentication.isAuthenticated()
        if (result == None):
            return make_response(jsonify({"status": "You are not Logged In"}),
                                 401)
        profile_id = result['profile_id']

        try:
            if request.method == 'POST':
                # check if the post request has the image part
                if 'image' not in request.files:
                    print('No image part')
                    abort(404)
                image = request.files['image']
                # if user does not select image, browser also
                # submit a empty part without filename
                if image.filename == '':
                    print('No image part')
                    abort(404)
                if image and allowed_file(image.filename):
                    filename = secure_filename(image.filename)
                    unique_filename = str(
                        uuid.uuid4()) + "." + filename.rsplit('.', 1)[1]
                    image.save(
                        os.path.join(settings.UPLOAD_FOLDER, unique_filename))
                DatabaseConnection.callprocONE(
                    "NewImage", (profile_id, image.filename, unique_filename))
                DatabaseConnection.commit()
                return make_response(
                    jsonify({"status": "Image Uploaded Successfully"}), 201)
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)
コード例 #3
0
ファイル: Profile.py プロジェクト: carreath/INFO3103_Project
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('profile_id')
        args = parser.parse_args()
        try:
            profile_id = args['profile_id']

            # If profile_id is not defined return current users profile
            if args['profile_id'] == None:
                # Check Authentication
                result = Authentication.isAuthenticated()
                if (result == None):
                    return make_response(
                        jsonify({"status": "You are not Logged In"}), 401)
                profile_id = result['profile_id']

            # Get profile
            result = DatabaseConnection.callprocONE("GetProfile",
                                                    (profile_id, ""))

            # If null then 404
            if (result == None):
                return make_response(jsonify({"status": "Profile Not Found"}),
                                     404)
            else:
                return make_response(jsonify({"profile": result}), 200)
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)
コード例 #4
0
ファイル: Profile.py プロジェクト: carreath/INFO3103_Project
    def put(self):
        if not request.json:
            return make_response(jsonify({"status": "Bad Request"}),
                                 400)  # bad request

        parser = reqparse.RequestParser()
        parser.add_argument('display_name')
        args = parser.parse_args()
        try:
            # Check Authenticated
            result = Authentication.isAuthenticated()
            if (result == None):
                return make_response(
                    jsonify({"status": "You are not Logged In"}), 401)
            profile_id = result['profile_id']

            DatabaseConnection.callprocONE("UpdateProfile",
                                           (profile_id, args['display_name']))
            DatabaseConnection.commit()
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)

        return make_response(jsonify({"status": "Profile Updated"}), 202)
コード例 #5
0
ファイル: ChallengeApp.py プロジェクト: pedgc/challenge
def main():
    try:
        # - - - Pretty Print - - -
        init(autoreset=True)
        print(Back.GREEN + "\n")
        print(Fore.BLUE + "The program started correctly")

        #- - - - - Launch GUI - - - - -
        try:
            privKey = Authentication().obtainPrivateKey()
        except (UnboundLocalError) as e:
            privKey = 0x0

        if privKey != 0x0:
            textimage = TextImage(privKey)
            dogorcat = DogsOrCats(privKey)
            privKey = 0x0
            notif_lev = Notification(textimage)
            notif_dog = Notification(dogorcat)
            mi_app = App(textimage, dogorcat)
        print("Program was closed")

    except Exception as e:
        self.errorNotif.showUnexpErrorNotif(e, "main()")

    return 0
コード例 #6
0
    def delete(self):
        parser = reqparse.RequestParser()
        parser.add_argument('post_id')
        args = parser.parse_args()
        try:
            # Check Authenticated
            result = Authentication.isAuthenticated()
            if (result == None):
                abort(401, "Unauthorised")

            profile_id = result['profile_id']

            # Delete all foreign key references prior to deleting the post
            DatabaseConnection.callprocONE("DeleteAllStars",
                                           (args['post_id'], ""))
            DatabaseConnection.callprocONE("DeleteAllTags",
                                           (args['post_id'], ""))
            DatabaseConnection.callprocONE("DeletePost", (args['post_id'], ""))
            DatabaseConnection.commit()
            return make_response(jsonify({"status": "Post has been deleted"}),
                                 201)
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)
コード例 #7
0
ファイル: Star.py プロジェクト: carreath/INFO3103_Project
def getStarredPosts():
    try:
        result = Authentication.isAuthenticated()
        profile_id = result['profile_id']
        if (profile_id == None):
            return {"result": {"status", "You are not Logged In"}, "code": 402}

        # Gets a list of starred posts
        result = DatabaseConnection.callprocALL("GetStarredPosts",
                                                (profile_id, ""))

        if (result == None):
            {"result": {"status": "Posts Do not Exist"}, "code": 400}
        return {"result": {"posts": result}, "code": 200}
    except:
        return {"result": {"status": "Internal Server Error"}, "code": 500}
コード例 #8
0
def GetFollowedPosts():
    try:
        result = Authentication.isAuthenticated()
        profile_id = result['profile_id']
        if (profile_id == None):
            abort(401, "Unauthorised")

        result = DatabaseConnection.callprocALL("GetFollowedPosts",
                                                (profile_id, ""))

        if (result == None):
            return make_response(jsonify({"message": "Posts Do not Exist"}),
                                 404)
        return make_response(jsonify({"posts": result}), 200)
    except:
        return make_response(jsonify({"status": "Internal Server Error"}), 500)
コード例 #9
0
 def validateJwt(self):
     user_id = ''
     try:
         user_id = '/' + conf['user_id']
     except Exception:
         pass
     dummy = self.s.get('/user' + user_id)
     if dummy.status_code == 403:
         auth = Authentication()
         if auth.is_auth:
             return True
         else:
             return False
     elif dummy.status_code == 200:
         return True
     else:
         return False
コード例 #10
0
	def post(self):
		parser = reqparse.RequestParser()
		parser.add_argument('followed_profile_id')
		args = parser.parse_args()

		try:
			# Check Authenticated
			result = Authentication.isAuthenticated()
			if(result == None):
				return make_response(jsonify({"status": "You are not Logged In"}), 401)
			profile_id = result['profile_id']

			result = DatabaseConnection.callprocONE("CreateFollow", (args['followed_profile_id'], profile_id))
			DatabaseConnection.commit()
			return make_response(jsonify({"status": "Successfully Followed Someone"}), 201)
		except:
			DatabaseConnection.rollback()
			return make_response(jsonify({"status": "Internal Server Error"}), 500)
コード例 #11
0
def GetFollowers():
	parser = reqparse.RequestParser()
	parser.add_argument('profile_id')
	args = parser.parse_args()

	profile_id = args['profile_id']
	try:
		if(profile_id == None):
			# Check Authenticated
			result = Authentication.isAuthenticated()
			if(result == None):
				return make_response(jsonify({"status": "You are not Logged In"}), 401)
			profile_id = result['profile_id']

		results = DatabaseConnection.callprocALL("GetFollowers", (profile_id, ""))
		return make_response(jsonify({"followers":results}), 200)
	except:
		return make_response(jsonify({"status": "Internal Server Error"}), 500)
コード例 #12
0
    def delete(self):
        parser = reqparse.RequestParser()
        parser.add_argument('comment_id')
        args = parser.parse_args()

        try:
            # Check Authenticated
            result = Authentication.isAuthenticated()
            if (result == None):
                return make_response(
                    jsonify({"status": "You are not Logged In"}), 401)
            profile_id = result['profile_id']

            DatabaseConnection.callprocONE("DeleteComment",
                                           (args['comment_id'], ""))
            DatabaseConnection.commit()
            return make_response(
                jsonify({"status": "Comment has been deleted"}), 200)
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)
コード例 #13
0
from login.User import get_all_users

app = Flask(__name__)

# FLask configuration
JWT_SECRET_KEY = 't1NP63m4wnBg6nyHYKfmc2TpCOGI4nss'
app.config['JWT_SECRET_KEY'] = JWT_SECRET_KEY
app.secret_key = 't1NP63m4wnBg6nyHYKfmc2Ulvdtggbsd'
app.config['CORS_HEADERS'] = 'Content-Type'
api = Api(app)
path = os.path.dirname(__file__)
CORS(app, resources={r"/*": {"origins": "*"}})
jwt = JWTManager(app)


authentication = Authentication()


# test
class HelloWorld(Resource):
    @jwt_required
    def get(self):
        return {'hello': 'world'}


class Login(Resource):
    @cross_origin()
    def post(self):
        return authentication.login()

コード例 #14
0
        print(equipment_register_error[lang])
        quit()


no_server_error_message = {
    'spa': 'No se pudo conectar con el servidor',
    'eng': 'Cannot connect to server'
}

"""This is where it begins"""

if not is_server_up():
    print(no_server_error_message[lang])
    quit()

auth = Authentication()

if not auth.is_auth:
    quit()

thing = Thing()

print('ip: ' + str(thing.ip))
print('macs: ' + str(thing.macs))

groups = auth.getAdminGroups()

pprint(groups)
allThings = []
for group in groups:
    res = requests.get(base_url+'/group', params={'id': group['id']})
コード例 #15
0
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument('post_id')
        parser.add_argument('title')
        parser.add_argument('description')
        parser.add_argument('tags', action='append')
        args = parser.parse_args()
        try:
            # Check Authenticated
            result = Authentication.isAuthenticated()
            if (result == None):
                abort(401, "Unauthorised")

            # Update the post
            DatabaseConnection.callprocONE(
                "UpdatePost",
                (args['post_id'], args['title'], args['description']))
            DatabaseConnection.commit()
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)

        # Update the tags
        # First Get a list of the current tags on the post
        # Then get a list of the new tags being put on the post
        # then determine the tags that are new and deleted from the post
        # Then loop through the new tags create tags that dont exist and attach to DB
        # Then loop through deleted tags and remove them from the post
        try:
            # Get all tags from the current post
            result = DatabaseConnection.callprocALL("GetTags",
                                                    (args['post_id'], ""))
            currentTags = []
            for tag in result:
                currentTags.append(tag['id'])

            # Get the new and removed tags from the args list
            newTags = []
            removedTags = []
            for tag in args['tags']:
                try:
                    tag_id = -1
                    # Get tag if it exists
                    result = DatabaseConnection.callprocONE(
                        "GetTagID", (tag, ""))
                    if (result == None):
                        # Tag doesnt exist create it
                        result = DatabaseConnection.callprocONE(
                            "CreateTag", (tag, ""))
                        tag_id = result['LAST_INSERT_ID()']
                    else:
                        # tag exists set tag_id
                        tag_id = result['id']
                    # If tag_id is not currently on the post add it
                    if tag_id not in currentTags:
                        DatabaseConnection.callprocONE(
                            "AddTags", (args['post_id'], tag_id))

                    # Append all tags to the new tags array (it is the new list on the DB)
                    newTags.append(tag_id)
                except:
                    tag_id = -1

            # Loop through the old current tags on the post
            for tag_id in currentTags:
                try:
                    # If the current tag from the before update post does not exist in new tags remove it from the post
                    if tag_id not in newTags:
                        DatabaseConnection.callprocONE(
                            "DeleteTags", (args['post_id'], tag_id))

                except:
                    tag_id = -1

            DatabaseConnection.commit()
            return redirect(settings.APP_HOST + ":" + str(settings.APP_PORT) +
                            "/post?post_id=" + str(args['post_id']),
                            code=302)
        except:
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)
コード例 #16
0
    def post(self):
        if not request.json:
            return make_response(jsonify({"status": "Bad Request"}),
                                 400)  # bad request

        parser = reqparse.RequestParser()
        parser.add_argument('image_id')
        parser.add_argument('title')
        parser.add_argument('description')
        parser.add_argument('tags', action='append')
        args = parser.parse_args()
        try:
            #Check Authenticated
            result = Authentication.isAuthenticated()
            if (result == None):
                abort(401, "Unauthorised")

            profile_id = result['profile_id']

            # Check if all required args are present
            if args['image_id'] == None or args['title'] == None or args[
                    'description'] == None:
                return make_response(jsonify({"status": "Bad Request"}), 400)

            # Create the post
            result = DatabaseConnection.callprocONE(
                "NewPost", (profile_id, args['image_id'], args['title'],
                            args['description']))

            # Get the new post ID. If it is None there was an error
            if result['LAST_INSERT_ID()'] == None:
                return make_response(jsonify({"status": "Bad Request"}), 400)

            # Commit the changes to the DB
            DatabaseConnection.commit()

            # Organize and Init the tags
            post_id = result['LAST_INSERT_ID()']

            # For each tag which was passed in:
            #	Check if it exists:
            #		if not create
            #	Add the tag ID to the post
            for tag in args['tags']:
                try:
                    # Get tag if it exists in the DB already
                    result = DatabaseConnection.callprocONE(
                        "GetTagID", (tag, ""))

                    # if result is None then the tag is not yet present
                    if (result == None):
                        #create tag
                        result = DatabaseConnection.callprocONE(
                            "CreateTag", (tag, ""))

                        #get that tags new id
                        if result['LAST_INSERT_ID()'] == None:
                            return make_response(
                                jsonify({"status": "Bad Request"}), 400)
                        tag_id = result['LAST_INSERT_ID()']
                    else:
                        tag_id = result['id']

                    # tag_id is now the tag to be added to the post
                    # add the tag to the post
                    DatabaseConnection.callprocONE("AddTags",
                                                   (post_id, tag_id))
                    DatabaseConnection.commit()
                except:
                    # If we end up here we encountered a problem with one of the tags
                    # So it skips that tag and continues
                    tag_id = -1

            # When the post is fully built redirect the user to their new post
            return redirect(settings.APP_HOST + ":" + str(settings.APP_PORT) +
                            "/post?post_id=" + str(post_id),
                            code=302)
        except:
            # There was an issue if we got here...
            DatabaseConnection.rollback()
            return make_response(jsonify({"status": "Internal Server Error"}),
                                 500)