def set_user_info(cls, in_user_id, user_info_dict): nick_name = user_info_dict['nick_name'] # 用户昵称 signature = user_info_dict['signature'] # 用户签名 gender_id = user_info_dict['gender_id'] # 用户性别,1为男,2为女,3为保密 birthday = user_info_dict['birthday'] # 用户生日 if birthday != '': age = user_info_dict['age'] = localtime(time())[0] - int( birthday.split('-')[0]) # 用户年龄 birthday = "'{}'".format(birthday) else: age = 0 birthday = 'null' telephone = user_info_dict['telephone'] # 设置用户登录手机号,非空 email = user_info_dict['email'] # 设置登录邮箱,非空 vocation = user_info_dict['vocation'] # 用户的职业信息 db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update user_info set user_nick_name='{}',user_signature='{}',user_gender_id={}," \ "user_birthday={},user_telephone='{}',user_email='{}'," \ "user_age={},user_vocation='{}' " \ "where user_id={}".format(nick_name, signature, gender_id, birthday, telephone, email, age, vocation, in_user_id) result = db.exc_sql(sql_stm) return result
def set_status(self, status_id): self.status_id = status_id db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update user_info set user_status_id={} " \ "where user_name='{}'".format(self.status_id, self.name) return db.exc_sql(sql_stm)
def rename_group(self, new_group_name): db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update friend_group set friend_group_name='{}' where friend_group_user_id={}"\ .format(new_group_name, self.group_user_id) result = db.exc_sql(sql_stm) return result
def set_friend_policy(self, friendship_policy_id): self.friendship_policy_id = friendship_policy_id db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update user_info set user_friendship_policy_id={} " \ "where user_name='{}'".format(self.friendship_policy_id, self.name) return db.exc_sql(sql_stm)
def del_group(self): db = DBUtil() db.connect_db() db.cur_db() sql_stm = "delete from group_info where group_admin_id={} and group_name='{}'"\ .format(self.admin_id, self.group_name) result = db.exc_sql(sql_stm) return result
def del_friend_group(self): db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "delete from friend_group where friend_group_name='{}' and friend_group_user_id={}"\ .format(self.group_name, self.group_user_id) result = db.exc_sql(sql_stm) return result
def add_friend_group(self): db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "insert into friend_group(friend_group_name,friend_group_user_id) " \ "values('{}',{})".format(self.group_name, self.group_user_id) result = db.exc_sql(sql_stm) return result
def update_password(self, old_password, new_password): db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 args = (encrypted_password(new_password), self.name, encrypted_password(old_password)) sql_stm = "update user_info set user_password=%s where (user_name=%s and user_password=%s)" result = db.exc_sql(sql_stm, *args) return result
def set_group(self, group_id): self.friend_group = group_id db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update friendship_info set friendship_friend_group_id={} where friendship_user_id={} and " \ "friendship_friend_id={}".format(self.friend_group, self.user_id, self.friend_id) result = db.exc_sql(sql_stm) return result
def set_remark_name(self, remark_name): self.remark_name = remark_name db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update friendship_info set friendship_name='{}' where friendship_user_id={} and " \ "friendship_friend_id={}".format(self.remark_name, self.user_id, self.friend_id) result = db.exc_sql(sql_stm) return result
def add_self_to_group(self): db = DBUtil() db.connect_db() db.cur_db() group_info = self.get_group_info(self.group_name) group_id = eval(group_info)[0] sql_stm = "insert into group_to_user(group_user_id,group_group_id) values({},{})"\ .format(self.admin_id, group_id) result = db.exc_sql(sql_stm) return result
def del_friend(self): if self.friend_id is None or self.friend_id == self.user_id: return False db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "delete from friendship_info where (friendship_user_id={} and friendship_friend_id={}) or "\ "(friendship_user_id={} and friendship_friend_id={})"\ .format(self.user_id, self.friend_id, self.friend_id, self.user_id) result = db.exc_sql(sql_stm) return result
def add_friend(self): if self.friend_id is None or self.friend_id == self.user_id: return False db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "insert into friendship_info(friendship_user_id,friendship_friend_id," \ "friendship_name,friendship_friend_type_id,friendship_friend_group_id) " \ "values({},{},'{}',{},{}),({},{},'',1,{})"\ .format(self.user_id, self.friend_id, self.remark_name, self.friend_type, self.friend_group, self.friend_id, self.user_id, self.get_init_group_id(self.friend_id)) result = db.exc_sql(sql_stm) return result
def create_group(self): db = DBUtil() db.connect_db() db.cur_db() sql_stm = "insert into group_info(group_admin_id,group_name) values({},'{}')"\ .format(self.admin_id, self.group_name) result1 = db.exc_sql(sql_stm) if result1: result2 = self.add_self_to_group() if result2: return True else: return False return False
def register(self): __doc__ = ''' 注册用户信息 :return: 注册是否成功 ''' db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 args = (self.name, self.password, self.email) # 设置SQL语句参数 sql_stm = "insert into user_info(user_name,user_password,user_email) values(%s,%s,%s)" result = db.exc_sql(sql_stm, *args) if result: self.get_user_id() friend_group = FriendGroup(self.id) friend_group.add_friend_group() return result
def set_inf(self, nick_name="", signature="", gender_id=3, birthday=None, telephone="", email="", introduce="", head="", age=0, vocation="", nation_id=1, province_id=1, city_id=1): self.nick_name = nick_name # 用户昵称 self.signature = signature # 用户签名 self.gender_id = gender_id # 用户性别,0为男,1为女 self.birthday = birthday # 用户生日 self.telephone = telephone # 设置用户登录手机号,非空 self.email = email # 设置登录邮箱,非空 self.introduce = introduce # 用户介绍 self.head = head # 用户头像 self.age = age # 用户年龄 self.vocation = vocation # 用户的职业信息 self.nation_id = nation_id # 用户所属国家 self.province_id = province_id # 用户所属省 self.city_id = city_id # 用户所属城市 db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update user_info set user_nick_name='{}',user_signature='{}',user_gender_id={}," \ "user_birthday='{}',user_telephone='{}',user_email='{}',user_introduce='{}',user_head='{}'," \ "user_age={},user_vocation='{}',user_nation_id={},user_province_id={},user_city_id={} " \ "where user_name='{}'".format(self.nick_name, self.signature, self.gender_id, self.birthday, self.telephone, self.email, self.introduce, self.head, self.age, self.vocation, self.nation_id, self.province_id, self.city_id, self.name) result = db.exc_sql(sql_stm) return result