Beispiel #1
0
    def update_findlock(device_uuid, update_type,
                        update_data) -> m_LogicReturn:
        if v.value_empty(device_uuid) \
            or v.value_empty(update_data) \
                or v.value_empty(update_type):
            return m_LogicReturn.f_error_msg("post data is missing!")

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)

        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        Findlock = db_resp.addon_data
        Findlock: m_Findlock

        valid_update_types = t.get_types(m_FindlockUpdateTypes())
        if update_type not in valid_update_types:
            return m_LogicReturn.f_error_msg("Unsupported update type!")

        if update_type == m_FindlockUpdateTypes.gps_location:
            try:
                update_data = json.loads(update_data)
                update_data = m_GpsLocation.fromDict(update_data)
            except:
                return m_LogicReturn.f_error_msg("Update data is malformed!")

        if update_type == m_FindlockUpdateTypes.gps_location:
            Findlock.GpsLocationHistory.add_location(update_data)
        else:
            return m_LogicReturn.f_error_msg(
                "this update type is not implemented...")

        db_resp = db_Findlock().update_findlock(Findlock)
        return m_LogicReturn.f_success_msg("Findlock updated!")
Beispiel #2
0
    def login(user_email, user_password) -> m_LogicReturn:
        if v.value_empty(user_email) \
           or v.value_empty(user_password):
            return m_LogicReturn.f_error_msg("Post data is missing!")

        if not v.verify_email(user_email):
            return m_LogicReturn.f_error_msg("E-mail is invalid!")
        v_pass = v.verify_password(user_password)
        if not v_pass.success:
            return m_LogicReturn.f_error_msg(v_pass.content)

        db_resp = db_User().get_user(
            m_UserEntries.email,
            user_email
        )

        if not db_resp.success:
            return m_LogicReturn.f_error_msg("Wrong email/password combination")

        _User = db_resp.addon_data
        _User: m_User

        if not Encryption.verify_password(
                user_password, _User.password_hash):
            return m_LogicReturn.f_error_msg("Wrong email/password combination")

        if not _User.verified:
            return m_LogicReturn.f_error_msg("User did not verify via email.")

        logic_resp = SessionLogic.login(_User)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg(logic_resp.content)
        return m_LogicReturn.f_success_msg("Logged in!")
Beispiel #3
0
    def google_register(google_user_id, user_email, avatar_link) -> m_LogicReturn:
        if v.value_empty(google_user_id) \
                or v.value_empty(user_email):
            return m_LogicReturn.f_error_msg("post data is missing!")

        if not v.verify_email(user_email):
            return m_LogicReturn.f_error_msg("E-mail is not valid!")

        _User = m_User(
            first_name=None,
            surname=None,
            email=user_email,
            password_hash=None,
            phone_number=None,
            nfc_id=None,
            finger_id=None,
            friend_code=Tools.generate_friend_code(),
            google_user_id=google_user_id,
            avatar_link=avatar_link,
            verified=True
        )

        db_resp = db_User().create_user(_User)
        if db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)
        return m_LogicReturn.f_success_msg(db_resp.content)
Beispiel #4
0
    def facebook_login(access_token, name, userid) -> m_LogicReturn:
        if v.value_empty(access_token) \
            or v.value_empty(name) \
                or v.value_empty(userid):
            return m_LogicReturn.f_error_msg("missing data!")

        logic_resp = SocialsLogic.fb_verify_access_token(access_token)
        if not logic_resp:
            return m_LogicReturn.f_error_msg("invalid access token")

        db_resp = db_User().get_user(
            m_UserEntries.facebook_user_id,
            userid
        )
        if not db_resp.success:
            logic_resp = AuthLogic.facebook_register(name, userid)
            if not logic_resp.success:
                return m_LogicReturn.f_error_msg(logic_resp.content)
        db_resp = db_User().get_user(
            m_UserEntries.facebook_user_id,
            userid
        )
        _User = db_resp.addon_data
        _User: m_User

        logic_resp = SessionLogic.login(_User)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg(logic_resp.content)
        return m_LogicReturn.f_success_msg("Logged in!")
Beispiel #5
0
    def add_friend(_user_uuid ,_findlock_uuid, _friendcode) -> m_LogicReturn: #using
        if not v.verify_uuid(_findlock_uuid).success:
            return m_LogicReturn.f_error_msg(f"{_findlock_uuid} is not a valid uuid!")
        if not v.verify_uuid(_user_uuid).success:
            return m_LogicReturn.f_error_msg(f"{_user_uuid} is not a valid uuid!")

        logic_resp = UserLogic.check_if_user_allowed_to_use_findlock(_user_uuid,_findlock_uuid)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg( logic_resp.content)
        
        if not v.verify_friendcode(_friendcode).success:
            return m_LogicReturn.f_error_msg(f"{_friendcode} is not a valid friendcode")
        
        friendcode_splitter = str(_friendcode).split("#")
        voornaam = friendcode_splitter[0]
        friendcode = friendcode_splitter[1]

        users_of_friendcode = DbUser().get_all_users()
        if not users_of_friendcode.success:
            return m_LogicReturn.f_error_msg( users_of_friendcode.content)
        
        users_of_friendcode = users_of_friendcode.addon_data


        user_of_friendcode = None
        for u in users_of_friendcode:
            _voornaam = u.first_name 
            _friendcode = u.friend_code

            if _voornaam == voornaam and _friendcode == friendcode:
                user_of_friendcode = u
        
        if v.value_empty(user_of_friendcode):
            return m_LogicReturn.f_error_msg( "Could not find user by this friendcode!")
        
        user_of_friendcode: m_User
            


        db_resp = DbFindlock().get_findlock(
            m_FindlockEntries.device_uuid,
            _findlock_uuid
        )
        if not db_resp.success:
            return m_LogicReturn.f_error_msg( "Could not get findlock with this uuid!")
        
        Findlock = db_resp.addon_data
        Findlock: m_Findlock

        if user_of_friendcode.user_uuid in Findlock.FindlockPermission.allowed_uuids:
            return m_LogicReturn.f_error_msg( "This user already have permissions")
        
        Findlock.FindlockPermission.addAllowedUuid(user_of_friendcode.user_uuid)

        db_resp = DbFindlock().update_findlock(Findlock)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg( db_resp.content)
        return m_LogicReturn.f_success_msg(f"{friendcode} is added!")
    def add_gps_loc_to_findlock(findlock_uuid, form_data) -> m_LogicReturn:
        lat = form_data.get("latInput", None)
        lng = form_data.get("lngInput", None)
        if v.value_empty(findlock_uuid) or \
            v.value_empty(lat) or \
                v.value_empty(lng):
            return m_LogicReturn.f_error_msg("Data is missing!")

        return AdminLogic.add_gps_location_to_findlock(findlock_uuid, lat, lng)
Beispiel #7
0
 def user_allowed_to_use_findlock(_session: m_Session, device_uuid) -> m_LogicReturn:
     if v.value_empty(_session) \
         or v.value_empty(device_uuid):
             return m_LogicReturn.f_error_msg("Data is missing!")
     
     _user_uuid = _session.User.user_uuid
     return UserLogic.check_if_user_allowed_to_use_findlock(
         _user_uuid, device_uuid, _master_only=False
     )
    def user_send_mail(user_uuid, form_data) -> m_LogicReturn:
        subject = form_data.get("subjectInput", None)
        content = form_data.get("contentInput", None)

        if v.value_empty(user_uuid) \
            or v.value_empty(subject) \
                or v.value_empty(content):
            return m_LogicReturn.f_error_msg("Data is missing!")

        return AdminLogic.user_send_mail(user_uuid, subject, content)
Beispiel #9
0
    def lock_findlock_nfc(form_data) -> m_LogicReturn:
        device_uuid = form_data.get('device_uuid', None)
        detected_nfc = form_data.get('detected_nfc', None)
        if v.value_empty(device_uuid) \
            or v.value_empty(detected_nfc):
            return m_LogicReturn.f_error_msg("Data is missing!")

        return RestLogic.set_findlock_lock_state(device_uuid,
                                                 m_EventTypes.lock,
                                                 detected_nfc,
                                                 m_UserEntries.nfc_id)
Beispiel #10
0
    def update_findlock(form_data) -> m_LogicReturn:
        device_uuid = form_data.get('device_uuid', None)
        update_type = form_data.get('update_type', None)
        update_data = form_data.get('update_data', None)

        if v.value_empty(device_uuid) \
            or v.value_empty(update_type) \
                or v.value_empty(update_data):
            return m_LogicReturn.f_error_msg("Data is missing")

        return RestLogic.update_findlock(device_uuid, update_type, update_data)
Beispiel #11
0
    def login(form_data) -> m_LogicReturn:
        email = form_data.get("emailInput", None)
        password = form_data.get("passwordInput", None)

        if v.value_empty(email) \
                or v.value_empty(password):
            return m_LogicReturn.f_error_msg("Data is missing!")
        return AuthLogic.login(
            email,
            password
        )
Beispiel #12
0
    def unlock_findlock_fingerprint(form_data) -> m_LogicReturn:
        device_uuid = form_data.get('device_uuid', None)
        detected_fp = form_data.get('detected_fp', None)
        if v.value_empty(device_uuid) \
            or v.value_empty(detected_fp):
            return m_LogicReturn.f_error_msg("Data is missing!")

        return RestLogic.set_findlock_lock_state(device_uuid,
                                                 m_EventTypes.unlock,
                                                 detected_fp,
                                                 m_UserEntries.finger_id)
Beispiel #13
0
    def pair_with_findlock(_session: m_Session, form_data) -> m_LogicReturn:        
        uuidInput = form_data.get("uuidInput", None)
        pincodeInput = form_data.get("pincodeInput", None)

        if v.value_empty(_session) \
            or v.value_empty(uuidInput) \
                or v.value_empty(pincodeInput):
            return m_LogicReturn.f_error_msg("Data is missing")
        
        _user_uuid = _session.User.user_uuid
        return UserLogic.pair_with_findlock(
            uuidInput, pincodeInput, _user_uuid
        )
Beispiel #14
0
    def add_friend(_session: m_Session, form_data) -> m_LogicReturn:
        print(form_data)
        friend_code = form_data.get("friendCode", None)
        device_uuid = form_data.get("device_uuid", default_device_uuid) #doet pijn maar moet wel

        if v.value_empty(friend_code) \
            or v.value_empty(device_uuid):
            return m_LogicReturn.f_error_msg("Data is missing!")
        if type(_session) != m_Session:
            return m_LogicReturn.f_error_msg("Session is not a valid type!")
        
        _user_uuid = _session.User.user_uuid
        return UserLogic.add_friend(
            _user_uuid, device_uuid, friend_code
        )
Beispiel #15
0
    def update_findlock_event(form_data) -> m_LogicReturn:
        device_uuid = form_data.get('device_uuid', None)
        executed = form_data.get('executed', None)
        if v.value_empty(device_uuid) \
            or v.value_empty(executed):
            return m_LogicReturn.f_error_msg("Data is missing!")

        if type(executed) == int:
            executed = True if executed == 1 else False
        elif type(executed) == str:
            executed = True if str(executed).lower() == "true" else False
        else:
            return m_LogicReturn.f_error_msg("Unknown type of executed!")

        return RestLogic.update_findlock_event(device_uuid, executed)
Beispiel #16
0
    def facebook_login(form_data) -> m_LogicReturn:
        userid = form_data.get('id', None)
        name = form_data.get('name', None)
        access_token = form_data.get('access_token', None)

        if v.value_empty(userid) or \
            v.value_empty(name) or \
                v.value_empty(access_token):
            return m_LogicReturn.f_error_msg("Data is missing!")

        return AuthLogic.facebook_login(
            access_token,
            name,
            userid
        )
Beispiel #17
0
    def register(form_data) -> m_LogicReturn:
        user_email = form_data.get("emailInput", None)
        user_password = form_data.get("passwordInput", None)
        user_password_2 = form_data.get("passwordInput2", None)

        if v.value_empty(user_email) \
            or v.value_empty(user_password) \
                or v.value_empty(user_password_2):
                return m_LogicReturn.f_error_msg("Data is missing!")
        
        return AuthLogic.register(
            user_email,
            user_password,
            user_password_2
        )
Beispiel #18
0
 def user_data_is_missing(_session: m_Session) -> m_LogicReturn:
     if v.value_empty(_session):
         return m_LogicReturn.f_error_msg("Data is missing!")
     if type(_session) != m_Session:
         return m_LogicReturn.f_error_msg("Session is not a valid type!")
     _user_dict = _session.User.toDict()
     return UserLogic.user_data_missing(_user_dict)
Beispiel #19
0
    def get_allowed_users_for_findlock(_findlock_uuid) -> m_LogicReturn:
        if not v.verify_uuid(_findlock_uuid).success:
            return m_LogicReturn.f_error_msg(f"{_findlock_uuid} is not a valid uuid!")
        
        db_resp = DbFindlock().get_findlock(
            m_FindlockEntries.device_uuid,
            _findlock_uuid
        )
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)
        
        findlock = db_resp.addon_data
        findlock: m_Findlock

        allowed_names = list()
        for u in findlock.FindlockPermission.allowed_uuids:
            db_resp = DbUser().get_user(
                m_UserEntries.user_uuid,
                u
            )
            if not db_resp.success:
                return m_LogicReturn.f_error_msg(db_resp.content)
            
            tmp_user = db_resp.addon_data
            tmp_user: m_User

            allowed_names.append(f"{tmp_user.first_name} {tmp_user.surname}")
        
        return m_LogicReturn.f_success("Ok!", allowed_names)
Beispiel #20
0
    def pair_with_findlock(_device_uuid, _device_pincode, _user_uuid) -> m_LogicReturn: #using    
        if not v.verify_uuid(_device_uuid).success:
            return m_LogicReturn.f_error_msg(f"{_device_uuid} is not a valid uuid!")
        
        db_resp = DbFindlock().get_findlock(
            m_FindlockEntries.device_uuid,
            _device_uuid
        )
        if not db_resp.success:
            return m_LogicReturn.f_error_msg( "This uuid does not exist!")
        Findlock = db_resp.addon_data
        Findlock: m_Findlock

        if Findlock.FindlockPermission.master_uuid is not None:
            return m_LogicReturn.f_error_msg( "This findlock is already paired!")

        if Findlock.master_pincode != _device_pincode:
            return m_LogicReturn.f_error_msg( "Pincode mismatch!")

        Findlock.FindlockPermission.master_uuid = _user_uuid

        db_resp = DbFindlock().update_findlock(Findlock)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg( db_resp.content)
        return m_LogicReturn.f_success_msg( "Paired!")
Beispiel #21
0
 def get_user_findlocks(_session: m_Session) -> m_LogicReturn:
     if v.value_empty(_session):
         return m_LogicReturn.f_error_msg("Data is missing!")
     if type(_session) != m_Session:
         return m_LogicReturn.f_error_msg("Session is not a valid type!")
     
     _user_uuid = _session.User.user_uuid
     return UserLogic.get_user_findlocks(_user_uuid, master_only=False)
Beispiel #22
0
    def google_login(form_data) -> m_LogicReturn:
        idtoken = form_data.get('idtoken', None)
        email = form_data.get('email', None)
        client_id = form_data.get('client_id', None)
        avatar_link = form_data.get('avatar_link', None)

        if v.value_empty(idtoken) \
                or v.value_empty(email) \
        or v.value_empty(client_id) \
        or v.value_empty(avatar_link):
            return m_LogicReturn.f_error_msg("Data is missing!")

        return AuthLogic.google_login(
            idtoken,
            email,
            client_id,
            avatar_link
        )
Beispiel #23
0
    def set_findlock_lock_state(  #using
            device_uuid,
            new_lock_state,  #mEventType
            auth_value,  #
            auth_type):  #userentries

        if not v.verify_uuid(device_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{device_uuid} is not a valid uuid!")

        event_types = t.get_types(m_EventTypes())
        if new_lock_state not in event_types:
            return m_LogicReturn.f_error_msg(
                f"{new_lock_state} is not a valid event type!")

        auth_types = t.get_types(m_UserEntries())
        if auth_type not in auth_types:
            return m_LogicReturn.f_error_msg(
                f"{auth_type} is not a valid userentry!")

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _findlock = db_resp.addon_data
        _findlock: m_Findlock

        db_resp = db_User().get_all_users()
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _users = db_resp.addon_data
        user_have_rights = False

        if auth_type == m_UserEntries.finger_id:
            for user in _users:
                if user.finger_id == auth_value:
                    if user.user_uuid == _findlock.FindlockPermission.master_uuid:
                        user_have_rights = True
                    if user.user_uuid in _findlock.FindlockPermission.allowed_uuids:
                        user_have_rights = True
        elif auth_type == m_UserEntries.nfc_id:
            for user in _users:
                if user.nfc_id == auth_value:
                    if user.user_uuid == _findlock.FindlockPermission.master_uuid:
                        user_have_rights = True
                    if user.user_uuid in _findlock.FindlockPermission.allowed_uuids:
                        user_have_rights = True
        else:
            return m_LogicReturn.f_error_msg("Unsupported auth type!")

        if not user_have_rights:
            return m_LogicReturn.f_error_msg("Permission error!")

        return RestLogic.set_findlock_event(device_uuid, new_lock_state)
Beispiel #24
0
 def facebook_register(name, userid) -> m_LogicReturn:
     if v.value_empty(name) or v.value_empty(userid):
         return m_LogicReturn.f_error_msg("data is missing!")
     _User = m_User(
         first_name=str(name).split(" ")[0],
         surname=str(name).split(" ")[1],
         email=None,
         password_hash=None,
         phone_number=None,
         nfc_id=None,
         finger_id=None,
         friend_code=Tools.generate_friend_code(),
         facebook_user_id=userid,
         verified=True
     )
     db_resp = db_User().create_user(_User)
     if db_resp.success:
         return m_LogicReturn.f_success_msg(db_resp.content)
     return m_LogicReturn.f_error_msg(db_resp.content)
Beispiel #25
0
    def get_name_by_uuid(i_uuid) -> m_LogicReturn:  #using
        if not v.verify_uuid(i_uuid).success:
            return m_LogicReturn.f_error_msg("Invalid UUID")

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

        User = db_resp.addon_data
        User: m_User
        return m_LogicReturn.f_success_msg(f"{User.first_name} {User.surname}")
Beispiel #26
0
    def user_update(user_uuid, form_data) -> m_LogicReturn:
        if v.value_empty(user_uuid):
            return m_LogicReturn.f_error_msg("Data is missing")

        data_keys = list()
        data_values = list()
        for i in form_data:
            data_keys.append(i)
            data_values.append(form_data[i])

        return AdminLogic.user_update(user_uuid, data_keys, data_values)
Beispiel #27
0
 def update_user_data(_session: m_Session,form_data) -> m_LogicReturn:
     if v.value_empty(_session):
         return m_LogicReturn.f_error_msg("Data is missing")
     
     if type(_session) != m_Session:
         return m_LogicReturn.f_error_msg("Session is not a valid type!")
     
     _user_dict = _session.User.toDict()
     return UserLogic.update_user_data(
         _user_dict, form_data
     )
Beispiel #28
0
    def register(user_email, user_password, user_password2) -> m_LogicReturn:
        if v.value_empty(user_email) \
            or v.value_empty(user_password) \
                or v.value_empty(user_password2):
            return m_LogicReturn.f_error_msg("post data is missing")

        v_pass = v.verify_password(user_password)
        if not v_pass.success:
            return m_LogicReturn.f_error_msg(v_pass.content)

        if not v.verify_email(user_email):
            return m_LogicReturn.f_error_msg("E-mail is invalid")

        if user_password != user_password2:
            return m_LogicReturn.f_error_msg("Passwords are not the same!")

        password_hash = Encryption.encrypt_password(
            user_password)
        _User = m_User(
            first_name=None,
            surname=None,
            email=user_email,
            password_hash=password_hash,
            phone_number=None,
            nfc_id=None,
            finger_id=None,
            friend_code=Tools.generate_friend_code(),
            avatar_link="https://www.clevelanddentalhc.com/wp-content/uploads/2018/03/sample-avatar-300x300.jpg"
        )

        db_resp = db_User().create_user(_User)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)
        token_code = Token.generate_confirm_token(user_email)
        print(f"Token code: {token_code}")
        email_message = Email.get_register_email(user_email, token_code)
        email_resp = Email.send_email(user_email, email_message)
        if not email_resp.success:
            return m_LogicReturn.f_error_msg("Failed to send email!")

        return m_LogicReturn.f_success_msg(db_resp.content)
Beispiel #29
0
    def get_user_info(user_uuid) -> m_LogicReturn:
        if not v.verify_uuid(user_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{user_uuid} is not a valid uuid")
        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

        return m_LogicReturn.f_success("User found!", _user)
Beispiel #30
0
    def get_findlock_info(findlock_uuid) -> m_LogicReturn:
        if not v.verify_uuid(findlock_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{findlock_uuid} is not a valid uuid")
        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             findlock_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _findlock = db_resp.addon_data
        _findlock: m_Findlock

        return m_LogicReturn.f_success("Findlock found!", _findlock)