def is_email_existed(email): try: ChatAppUser.get(ChatAppUser.email == email) return True except ChatAppUser.DoesNotExist: pass return False
def register(username, password, birthday, fullname, email, address, sex=None): try: ChatAppUser.create(username=username, password=password, birthday=birthday, fullname=fullname, email=email, address=address, sex=sex) return True except Exception as Ex: pass return False
def login(email, password): try: user = ChatAppUser.get((ChatAppUser.email == email) & (ChatAppUser.password == password)) return user except ChatAppUser.DoesNotExist: pass
def search_friends_by_user_id_and_friend_name(user_id, username): _ret_data = ChatAppUser.select().where( ChatAppUser.id.in_( ChatAppFriend.select(ChatAppFriend.friend).where( (ChatAppFriend.user == user_id) & (ChatAppUser.username.contains(username))))) return _ret_data
def detail_user(user_id): try: _ret_data = ChatAppUser.select( ChatAppUser.username, ChatAppUser.fullname, ChatAppUser.email, ChatAppUser.sex, ChatAppUser.birthday, ChatAppUser.address).where(ChatAppUser.id == user_id) return _ret_data except Exception as Ex: pass
def get_all_friends(user_id): try: _ret_data = (ChatAppUser.select( ChatAppUser.id, ChatAppUser.username).where( ChatAppUser.id.in_( ChatAppFriend.select(ChatAppFriend.friend).where( ChatAppFriend.user == user_id)))) return _ret_data except Exception as Ex: pass
def get_receiver_message(sender_id): try: _ret_dat = (ChatAppUser.select( ChatAppUser.id, ChatAppUser.username).where( ChatAppUser.id.in_( ChatAppMessage.select( ChatAppMessage.receiver.distinct()).where( ChatAppMessage.sender == sender_id)))) return _ret_dat except Exception as Ex: print(Ex)
def get_all_blocks_user(user_id): try: _ret_data = (ChatAppUser.select( ChatAppUser.id, ChatAppUser.username).where( ChatAppUser.id.in_( ChatAppBlockUser.select(ChatAppBlockUser.user).where( ChatAppBlockUser.blocker == user_id))).order_by( ChatAppUser.username.asc())) return _ret_data except Exception as Ex: pass
def get_sender_message(receiver_id): try: _ret_data = (ChatAppUser.select( ChatAppUser.id, ChatAppUser.username).where( ChatAppUser.id.in_( ChatAppMessage.select( ChatAppMessage.sender.distinct()).where( (ChatAppMessage.receiver == receiver_id) & (ChatAppMessage.is_read == 0))))) return _ret_data except Exception as Ex: print(Ex)
def search_user_by_id_and_by_name(user_id, username): try: _ret_data = (ChatAppUser.select( ChatAppUser.id, ChatAppUser.username).order_by(ChatAppUser.username.asc()).where( ChatAppUser.id.not_in( ChatAppBlockUser.select(ChatAppBlockUser.user).where( ChatAppBlockUser.blocker == user_id)) & (ChatAppUser.username.contains(username) & (ChatAppUser.id != user_id)))) return _ret_data except Exception as Ex: pass