Пример #1
0
 def __init__(self, id):
     resource.Resource.__init__(self)
     self.id = id
     self.user = database.getUserByID(id)
     self.user['checked']= "checked" if self.user['enabled'] else ''
     self.user['key']=encodestring(self.user['key'])
     self.putChild('', self)
     self.putChild('config', UserConfig(self.id))
     self.putChild('delete', DeleteUser(self.id))
Пример #2
0
 def __init__(self, id):
     resource.Resource.__init__(self)
     self.id = id
     self.user = database.getUserByID(id)
     self.user['checked'] = "checked" if self.user['enabled'] else ''
     self.user['key'] = encodestring(self.user['key'])
     self.putChild('', self)
     self.putChild('config', UserConfig(self.id))
     self.putChild('delete', DeleteUser(self.id))
Пример #3
0
 def connectionLost(self, reason):
     if self.hasConnected:
         if self.dbid != -1:
             obj = database.getUserByID(self.dbid)
             obj.pos = self.player.pos.dumps()
             obj.save()
         self.server.rmvClient(self.cid)
         for c in self.server.clients.values():
             c.send({'action':'RMV_ENT', 'id':self.cid, 'type':'player'})
     print 'Disconnected: %s' % reason
Пример #4
0
def get_user(id):
    # Check if specified ID is an integer
    if not function.isInt(id):
        return jsonify({"error": "id is not an integer"}), 400

    data = database.getUserByID(id)
    if data is not None:
        return jsonify(data), 200
    else:
        return jsonify({"error": "No results found"}), 404
Пример #5
0
def get_user_projects(id):
    # Check if specified ID is an integer
    if not function.isInt(id):
        return jsonify({"error": "id is not an integer"}), 400

    # Check if user actually exists
    user = database.getUserByID(id)
    if user is None:
        return jsonify({"error": "Specified user does not exist"})

    data = database.getUserProjects(id)
    if data is None:
        return jsonify({"error": "No results found"}), 404
    else:
        for projectuser in data:
            project = database.getProjectByID(
                str(projectuser['Project_projectID']))
            projectuser['project'] = project
        return jsonify(data), 200
Пример #6
0
def del_user(id):
    # Check if specified ID is an integer
    if not function.isInt(id):
        return jsonify({"error": "id is not an integer"}), 400

    # Check if token identity corresponds to the user being deleted
    if not (int(id) == get_jwt_identity()):
        return jsonify({"error": "Not allowed to delete this user"}), 403

    # Check if user actually exists
    user = database.getUserByID(id)
    if user is None:
        return jsonify({"error": "Specified user does not exist"})

    # Delete user
    if database.deleteUser(id):
        return jsonify({"Info": "User deleted successfully"}), 200
    else:
        return jsonify({"erorr": "Something went wrong deleting user"}), 500
Пример #7
0
def put_user(id):
    # Check if specified ID is an integer
    if not function.isInt(id):
        return jsonify({"error": "id is not an integer"}), 400

    # Check if token identity corresponds to the user being updated
    if not (int(id) == get_jwt_identity()):
        return jsonify(
            {"error": "Not allowed to update this users information"}), 403

    # Fetch form data
    userDetails = request.get_json()
    name = userDetails.get('name')
    password = userDetails.get('password')

    # Check if all data is supplied
    if name is None:
        return jsonify({"error": "Username not specified"}), 400
    if password is None:
        return jsonify({"error": "Password not specified"}), 400

    # Check if user actually exists
    user = database.getUserByID(id)
    if user is None:
        return jsonify({"error": "Specified user does not exist"})

    # Check is username and password comply to the requirements
    username_message = function.check_username(name)
    password_message = function.check_password(password)
    if (username_message is not "ok"):
        return jsonify({"error": username_message}), 400
    elif (password_message is not "ok"):
        return jsonify({"error": password_message}), 400

    # Hash the userpassword for secure storage
    hashedpass = function.hash_password(password)

    data = database.updateUser(id, name, hashedpass)
    if data is not None:
        return jsonify(data), 200
    else:
        return jsonify({"error": "No results found"}), 404
Пример #8
0
def get_user_posts(id):
    # Check if specified ID is an integer
    if not function.isInt(id):
        return jsonify({"error": "id is not an integer"}), 400

    # Check if user actually exists
    user = database.getUserByID(id)
    if user is None:
        return jsonify({"error": "Specified user does not exist"})

    data = database.getUserPosts(id)
    if data is None:
        return jsonify({"error": "No results found"}), 404
    else:
        userPosts = []
        for post in data:
            project = database.getProjectByID(str(post['postProject']))
            post['project'] = project
            if project is not None:
                userPosts.append(post)
        return jsonify(userPosts), 200
Пример #9
0
def add_comment(id):
    # Check if specified ID is an integer
    if not function.isInt(id):
        return jsonify({"error": "id is not an integer"}), 400

    # Fetch form data
    postDetails = request.get_json()
    content = postDetails.get('content')
    parent = postDetails.get('parent')
    # Swap userID for JWT id
    userID = get_jwt_identity()

    if content is None:
        return jsonify({"error": "Comment content not specified"}), 400
    if userID is None:
        return jsonify({"error": "Comment user id not specified"}), 400

    # Check if post actually exists
    post = database.getPostByID(id)
    if post is None:
        return jsonify({"error": "Specified post does not exist"}), 400

    # Check if you have permission to comment on this post
    userRole = function.getProjectUserRole(get_jwt_identity(), post['postProject'])
    if not function.isProjectMember(userRole):
        return jsonify({"error": "Must be a project member to comment on this post"}), 403

    # Check if parent actually exists
    if parent is not None:
        comment = database.getCommentByID(str(parent))
        if comment is None:
            return jsonify({"error": "Parent comment does not exist"}), 400

    # Add comment
    comment = database.addPostComment(content, parent, userID, id)
    user = database.getUserByID(str(comment['commentUser']))
    comment['user'] = user
    return jsonify(comment), 201
Пример #10
0
 def __init__(self, id):
     resource.Resource.__init__(self)
     self.id = id
     self.user = database.getUserByID(id)
     self.putChild('', self)
Пример #11
0
 def __init__(self, id):
     resource.Resource.__init__(self)
     self.id = id
     self.user = database.getUserByID(id)
     self.putChild('', self)