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))
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))
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
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
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
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
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
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
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
def __init__(self, id): resource.Resource.__init__(self) self.id = id self.user = database.getUserByID(id) self.putChild('', self)