def add_friend(id, aid): if len(db.select("select * from UserTable where ID = ?", aid)) == 0: return 0 if len(db.select("select * from " + "F" + str(id) + " where ID = ?", aid)) == 1: return 2 if id == aid: return 3 apply_FriendTable(id, aid) return 1
def change_List(id, fid, listname): lid = db.select("select LID from " + "L" + str(id) + " where Listname =?", listname)[0]["LID"] print("lid", lid) db.update( "update " + 'F' + str(id) + " set LID = " + str(lid) + " where ID=?", fid)
def get_groups(id): gid = select_gid(id) print("gid", gid) output = [] for i in gid: a = db.select("select * from GroupTable where GID = ?", str(i["GID"])) output.append(a[0]) return output
def get_friends(id): a = db.select("select * from %s" % 'F' + str(id)) id_list = [] nickname_list = [] status_list = [] lid_list = [] for i in a: id_list.append(i["ID"]) nickname_list.append(i["Nickname"]) status_list.append(i["Status"]) lid_list.append(i["LID"]) return id_list, nickname_list, status_list, lid_list
def post(self): #判定密码重复情况 password1 = self.get_argument("password1") password2 = self.get_argument("password2") nickname = self.get_argument("nickname") if (password1!=password2): self.write("<html><body><script type=\"text/JavaScript\">alert(\"两次密码不相同\"); window.history.back()</script></html>") return #随机用户id a = [0]#让a不为空 while (len(a)!=0): id = random.randint(100000,999999) a = db.select("select * from user where ID = ?",id) models.UserTable(ID = id,password = password1,nickname = nickname).insert() #跳转到登录成功界面 self.render("register_success.html",id = id)
def login(self,id,password): a = db.select("select * from user where ID = ? and password = ?", id,password) if len(a)==1: self.set_current_id(id) if models.Check_Friend_Table(id)==0: m = models.New_Friend_Table(id) print m.__table__ print type(m.__table__) db.update('drop table if exists %s' % m.__table__ ) db.update(m().__sql__()) #在live中通过cookie获取好友列表 self.redirect("/live",permanent = True)#跳转到listHandler get elif len(a)==0: self.write("<html><body><script type=\"text/JavaScript\">alert(\"用户名或密码错误\"); window.history.back()</script></html>") else: self.write("<html><body><script type=\"text/JavaScript\">alert(\"系统错误\"); window.history.back()</script></html>")
def post(self): nickname = self.get_argument("nickname") password1 = self.get_argument("password1") password2 = self.get_argument("password2") email = self.get_argument("email") self.set_current_nickname(nickname) if (password1 != password2): self.write( "<html><body><script type=\"text/JavaScript\">alert(\"passwords are different\"); window.history.back()</script></html>" ) a = [0] while (len(a) != 0): id = random.randint(100000, 999999) a = db.select("select * from UserTable where ID = ?", id) if (new_user(id, password1, nickname, email)): self.render("rsuccess.html", id=id, rr_nickname=nickname) else: self.write( "<html><body><script type=\"text/JavaScript\">alert(\"E-mail format is incorrect\"); window.history.back()</script></html>" )
def Check_Friend_Table(id): return db.select("select count(*) from sqlite_master where type='table' and name = ?","F"+str(id))[0]["count(*)"]
def query(self,id): return db.select("select * from user where ID = ?", id)
def Check_Friend_Table(id): return db.select( "select count(*) from sqlite_master where type='table' and name = ?", "F" + str(id))[0]["count(*)"]
def select_ListTable(id): return db.select("select * from " + "L" + str(id))
def select_ChatTable(id): return db.select("select * from " + "C" + str(id))
def select_UserTable_time(id): return db.select("select Lastdate from UserTable where ID = ?", id)[0]["Lastdate"], db.select( "select Lasttime from UserTable where ID = ?", id)[0]["Lasttime"]
def get(self): print db.select("select * from user") self.render("login.html")
def Get_Friends(id): a = db.select("select ID from %s" % 'F'+str(id)) id_list = [] for i in a: id_list.append(i["ID"]) return id_list
def check_login(id, password): return len( db.select("select * from UserTable where ID = ? and password = ?", id, password))
def select_people_in_group(gid): return db.select("select ID from GP" + str(gid))
def select_gid(id): return db.select("select GID from " + "PG" + str(id))
def on_message(self, data): id = self.get_secure_cookie(config._id) nickname = models.find_nickname(id) print "message id ", id print "on_message data:", data if data[0] == "C": interrupt = data.index('_') fid = data[1:interrupt] fmessage = data[interrupt + 1:] self.send_friend_message( fid, "C" + id + "_" + nickname + "@" + fmessage) models.insert_ChatTable(id, id, fid, fmessage) models.insert_ChatTable(fid, id, fid, fmessage) if data[0] == "A": fid = data[1:] a = models.add_friend(id, fid) self.write_message(str(a)) if data[0] == "P" or data[0] == "R": interrupt = data.index('_') applyid = data[1:interrupt] passid = data[interrupt + 1:] models.pass_FriendTable(applyid, passid) self.write_message(data[0] + "_" + applyid) self.send_apply_message(data[0], applyid, passid) if data[0] == "L" and data[1] == "A": interrupt = data.index('_') new_list_name = data[interrupt + 1:] models.insert_ListTable(id, new_list_name) if data[0] == "L" and data[1] == "C": interrupt1 = data.index('_') interrupt2 = data.index('@') fid = data[interrupt1 + 1:interrupt2] listname = data[interrupt2 + 1:] print fid, listname models.change_List(id, fid, listname) if data[0] == "G" and data[1] == "C": interrupt = data.index('_') groupname = data[interrupt + 1:] print groupname a = [0] while (len(a) != 0): gid = random.randint(1000000, 9999999) a = db.select("select * from GroupTable where GID = ?", gid) print "gid", gid models.create_group(id, gid, groupname) if data[0] == "G" and data[1] == "A": interrupt = data.index('_') groupid = data[interrupt + 1:] print groupid models.add_group(id, groupid) if data[0] == "G" and data[1] == "G": interrupt = data.index('_') groupid = data[2:interrupt] message = data[interrupt + 1:] print "groupid,message", groupid, message self.send_group_message( id, groupid, "G" + groupid + "_" + nickname + "@" + message)
def find_nickname(id): return db.select("select Nickname from UserTable where ID = ? ", id)[0]["Nickname"]