Beispiel #1
0
    def get_all_users(self) -> m_LogicReturn:
        res = self.find_all()
        users = list()
        for fl in res:
            users.append(m_User.fromDict(fl))

        return m_LogicReturn.f_success(f"Got {len(users)} users", users)
    def user_update(user_uuid, data_keys, data_values) -> m_LogicReturn:
        if not v.verify_uuid(user_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{user_uuid} is not a valid uuid")
        if len(data_keys) != len(data_values):
            return m_LogicReturn.f_error_msg("Mismatch in data!")

        for i in range(0, len(data_values)):
            data_val = data_values[i]
            if data_val == "None":
                data_values[i] = None
            elif data_val == "True":
                data_values[i] = True
            elif data_val == "False":
                data_values[i] = False

        valid_data_keys = Tools.get_types(m_UserEntries())

        db_resp = db_User().get_user(m_UserEntries.user_uuid, user_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _user = db_resp.addon_data
        _user: m_User

        _user_dict = _user.toDict()

        for i in range(0, len(data_keys)):
            key = data_keys[i]
            if key not in valid_data_keys:
                return m_LogicReturn.f_error_msg(f"{key} is not a valid key!")
            val = data_values[i]

            _user_dict[key] = val

        _user = m_User.fromDict(_user_dict)
        db_resp = db_User().update_user(_user)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)
        return m_LogicReturn.f_success_msg(db_resp.content)
Beispiel #3
0
    def update_user_data(_user_dict: dict,form_data) -> m_LogicReturn: #using
        if type(_user_dict) != dict:
            return m_LogicReturn.f_error_msg("Session type is invalid")
        
        logic_resp = UserLogic.user_data_missing(_user_dict)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg(logic_resp.content)
        missing_list = logic_resp.addon_data

        for i in missing_list:
            form_entry = form_data.get(f"{i}Input", None)
            if form_entry is not None and len(form_entry) > 0:
                _user_dict[i] = form_entry

        new_user = m_User.fromDict(_user_dict)
        db_resp = DbUser().update_user(new_user)

        if not db_resp.success:
            return m_LogicReturn.f_error_msg( db_resp.content)
        if not SessionLogic.update_session_using_db().success:
            return m_LogicReturn.f_error_msg( "Updating session gaat fout!")
        return m_LogicReturn.f_success_msg("Updated user data!")
Beispiel #4
0
 def fromSession(cls, input_session):
     if 'filo' not in input_session:
         return cls(None, None)
     return cls(input_session['filo'][SessionEntries.logged_in],
                User.fromDict(input_session['filo'][SessionEntries.User]))
Beispiel #5
0
 def fromDict(cls, input_dict: dict):
     return cls(input_dict[SessionEntries.logged_in],
                User.fromDict(input_dict[SessionEntries.User]))
Beispiel #6
0
 def create_user(self, User: m_User) -> m_LogicReturn:
     return m_LogicReturn.f_error_msg(
         "User already exists!") if self.__does_user_exist(
             User) else m_LogicReturn.f_success(
                 True, self.insert_one(User.toDict()))
Beispiel #7
0
    def get_user(self, search_type: m_UserEntries, query) -> m_LogicReturn:

        res = self.find_one({search_type: query})
        return m_LogicReturn.f_error_msg(
            "User not found!") if res is None else m_LogicReturn.f_success(
                "Found user!", m_User.fromDict(res))
Beispiel #8
0
 def update_user(self, User: m_User) -> m_LogicReturn:
     self.update_one({m_UserEntries.user_uuid: User.user_uuid},
                     {"$set": User.toDict()})
     return m_LogicReturn.f_success_msg("Updated!")