def create_user(user): email = user["email"] assert not conn.get("SELECT * FROM index_login WHERE login = %s", email) user["type"] = "user" user["name"] = user.get("name", "") user["salt"] = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(10)) if "password" in user: user["password"] = hashlib.sha1(user["password"] + user["salt"]).hexdigest() user["title"] = "" user["department"] = "" user["locatiion"] = "" user["mobile"] = "" user["tel"] = "" user["about"] = "" user["profile_img"] = "" user["datetime"] = datetime.datetime.now().isoformat() new_id = nomagic._new_key() assert nomagic._node(new_id).execute_rowcount("INSERT INTO entities (id, body) VALUES(%s, %s)", new_id, nomagic._pack(user)) #update indexes: email assert "@" in email assert conn.execute_rowcount("INSERT INTO index_login (login, entity_id) VALUES(%s, %s)", email, new_id) return (new_id, user)
def create_user(user): user["type"] = "user" user["name"] = user.get("name", "") user["password"] = "" user["salt"] = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(10)) user["title"] = "" user["department"] = "" user["locatiion"] = "" user["mobile"] = "" user["tel"] = "" user["about"] = "" user["profile_img"] = "" user["datetime"] = datetime.datetime.now().isoformat() new_id = _new_key() assert ring[_number(new_id)].execute_rowcount("INSERT INTO entities (id, body) VALUES(%s, %s)", new_id, _pack(user)) #do we need a user_id index? currently no #user_id = conn.execute("INSERT INTO index_user_id (entity_id) VALUES(%s)", new_id) #update indexes: email email = user["email"] assert "@" in email assert conn.execute_rowcount("INSERT INTO index_login (login, entity_id) VALUES(%s, %s)", email, new_id) email_host = email.split("@")[1] organization_id, organization = get_organization_by_email_host(email_host) users = organization.get("users", []) users.append(new_id) organization["users"] = users _update_entity_by_id(organization_id, organization) return (new_id, user)
def new_status(user_id, data): now = datetime.datetime.now() data["type"] = "status" data["user_id"] = user_id data["datetime"] = now.isoformat() data["likes"] = [] data["comment_ids"] = [] assert data.get("title") new_id = nomagic._new_key() assert nomagic._node(new_id).execute_rowcount( "INSERT INTO entities (id, body) VALUES(%s, %s)", new_id, nomagic._pack(data)) user = nomagic._get_entity_by_id(user_id) activity = user.get("activity", []) activity.append(new_id) user["activity"] = activity nomagic._update_entity_by_id(user_id, user) data["user"] = user data["like_count"] = 0 data["like"] = False data["comment_count"] = 0 assert conn.execute_rowcount( "INSERT INTO index_posts (user_id, entity_id) VALUES(%s, %s)", user_id, new_id) return new_id, data
def create_user(user): email = user["email"] login = conn.get("SELECT * FROM index_login WHERE login = %s", email) assert not login user["type"] = "user" user["name"] = user.get("name", "") user["salt"] = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(10)) user["password"] = hashlib.sha1(user["password"] + user["salt"]).hexdigest() user["title"] = "" user["department"] = "" user["locatiion"] = "" user["mobile"] = "" user["tel"] = "" user["about"] = "" user["profile_img"] = "" user["datetime"] = datetime.datetime.now().isoformat() new_id = nomagic._new_key() rowcount = nomagic._node(new_id).execute_rowcount("INSERT INTO entities (id, body) VALUES(%s, %s)", new_id, nomagic._pack(user)) assert rowcount #update indexes: email assert "@" in email rowcount = conn.execute_rowcount("INSERT INTO index_login (login, entity_id) VALUES(%s, %s)", email, new_id) assert rowcount return (new_id, user)
def new_status(user_id, data): now = datetime.datetime.now() data["type"] = "status" data["user_id"] = user_id data["datetime"] = now.isoformat() data["likes"] = [] data["comment_ids"] = [] assert data.get("title") new_id = nomagic._new_key() assert nomagic._node(new_id).execute_rowcount("INSERT INTO entities (id, body) VALUES(%s, %s)", new_id, nomagic._pack(data)) user = nomagic._get_entity_by_id(user_id) activity = user.get("activity", []) activity.append(new_id) user["activity"] = activity nomagic._update_entity_by_id(user_id, user) data["user"] = user data["like_count"] = 0 data["like"] = False data["comment_count"] = 0 assert conn.execute_rowcount("INSERT INTO index_posts (user_id, entity_id) VALUES(%s, %s)", user_id, new_id) return new_id, data
def email_invite(email): """email invite can be used for both self signup and inviting friends to join""" # valid email, existing in system? # insert into index_invite table token = uuid.uuid4().hex assert conn.execute_rowcount("INSERT INTO index_invite (email, token) VALUES(%s, %s)", email, token) # resend? signup? invite? return token
def email_invite(email): """email invite can be used for both self signup and inviting friends to join""" # valid email, existing in system? # insert into index_invite table token = uuid.uuid4().hex assert conn.execute_rowcount( "INSERT INTO index_invite (email, token) VALUES(%s, %s)", email, token) # resend? signup? invite? return token
def delete(self): collection_id = self.get_argument("id") if self.current_user: rows = conn.execute_rowcount("DELETE FROM collection WHERE id = %s and user_id = %s", collection_id, self.current_user["id"]) print rows #need to delete all likes if rows == 1: conn.execute("DELETE FROM likes WHERE collection_id = %s", collection_id) self.finish({"error":None})
def update_fileinfo(filehash, user_id, id3info = None, title = None, rev = None): if rev: if not conn.get("SELECT * FROM index_dropbox WHERE rev=%s", rev): assert conn.execute_rowcount("INSERT INTO index_dropbox (rev, entity_id) VALUES (%s, %s)", rev, filehash) fileinfo = nomagic._get_entity_by_id(filehash) if fileinfo: changed = False owners = fileinfo.get("owners", []) if user_id not in owners: owners.append(user_id) fileinfo["owners"] = owners changed = True if id3info and id3info != fileinfo.get("id3info"): fileinfo["id3info"] = id3info changed = True if title and title != fileinfo.get("title"): fileinfo["title"] = title changed = True if changed: nomagic._update_entity_by_id(filehash, fileinfo) else: fileinfo = {"owners":[user_id]} if id3info: fileinfo["id3info"] = id3info if title: fileinfo["title"] = title assert nomagic._node(filehash).execute_rowcount("INSERT INTO entities (id, body) VALUES(%s, %s)",\ filehash, nomagic._pack(fileinfo)) user = nomagic._get_entity_by_id(user_id) if user: files = user.get("files", []) if filehash not in files: files.append(filehash) user["files"] = files nomagic._update_entity_by_id(user_id, user) return fileinfo, user
def create_user(user): user["type"] = "user" user["name"] = user.get("name", "") user["password"] = "" user["salt"] = ''.join( random.choice(string.ascii_uppercase + string.digits) for x in range(10)) user["title"] = "" user["department"] = "" user["locatiion"] = "" user["mobile"] = "" user["tel"] = "" user["about"] = "" user["profile_img"] = "" user["datetime"] = datetime.datetime.now().isoformat() new_id = nomagic._new_key() assert ring[nomagic._number(new_id)].execute_rowcount( "INSERT INTO entities (id, body) VALUES(%s, %s)", new_id, nomagic._pack(user)) #do we need a user_id index? currently no #user_id = conn.execute("INSERT INTO index_user_id (entity_id) VALUES(%s)", new_id) #update indexes: email email = user["email"] assert "@" in email assert conn.execute_rowcount( "INSERT INTO index_login (login, entity_id) VALUES(%s, %s)", email, new_id) """ email_host = email.split("@")[1] organization_id, organization = nomagic.feeds.get_organization_by_email_host(email_host) users = organization.get("users", []) users.append(new_id) organization["users"] = users _update_entity_by_id(organization_id, organization) """ return (new_id, user)
#comment["like"] = self.user_id in set(comment.get("likes", [])) if self.current_user else False #comment["comment_count"] = 0 #print comment["comments"] if comment.get("comments") else [] comment_ids.append(comment["id"]) comment_ids.extend(get_comments(comment["comments"]) if comment.get("comments") else []) return comment_ids if len(sys.argv) < 2: sys.exit() print sys.argv[1] activity_id = sys.argv[1] activity = nomagic._get_entity_by_id(activity_id) print activity assert activity.get("type") == "status" comments, user_ids = nomagic.feeds.get_comments(activity) comment_ids = get_comments(comments) print comment_ids # delete comment_ids for comment_id in comment_ids: nomagic._node(comment_id).execute_rowcount("DELETE FROM entities WHERE id = %s", comment_id) # delete activity_id nomagic._node(activity_id).execute_rowcount("DELETE FROM entities WHERE id = %s", activity_id) conn.execute_rowcount("DELETE FROM index_posts WHERE entity_id = %s", activity_id)