Пример #1
0
def recreate_debug_environment():
    debug.print_w("Dropping all")
    debug.print_i(db_Findlock().drop_all())

    debug.print_i("Creating dummmy user!")
    debug.print_i(db_User().create_user(debug_data.get_dummy_user()))
    debug.print_i("Creating dummy user with permissions")
    debug.print_i(db_User().create_user(
        debug_data.get_dummy_user_with_permissions()))

    debug.print_i("Adding dummy user w/ permissions to dummy findlock")

    dummy_findlock = debug_data.get_dummy_findlock()
    debug.print_i(
        dummy_findlock.FindlockPermission.addAllowedUuid(
            debug_data.get_dummy_user_with_permissions().user_uuid))

    debug.print_i("Creating dummmy findlock!")
    debug.print_i(db_Findlock().create_findlock(dummy_findlock))

    debug.print_i("Pairing dummy findlock with dummy user!")
    debug.print_i(
        UserLogic.pair_with_findlock(dummy_findlock.device_uuid,
                                     dummy_findlock.master_pincode,
                                     debug_data.get_dummy_user().user_uuid))

    debug.print_i("Sending dummy GPS location to dummy findlock")
    debug.print_i(
        RestLogic.update_findlock(dummy_findlock.device_uuid,
                                  m_FindlockUpdateTypes.gps_location,
                                  debug_data.get_dummy_location().__dict__))
Пример #2
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!")
Пример #3
0
    def remove_user(u_uuid) -> m_LogicReturn:
        db_resp = db_User().get_user(m_UserEntries.user_uuid, u_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _User = db_resp.addon_data
        _User: m_User

        db_resp = db_User().delete_user(_User)

        if db_resp.success:
            return m_LogicReturn.f_success_msg(db_resp.content)
        return m_LogicReturn.f_error_msg(db_resp.content)
Пример #4
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!")
Пример #5
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)
Пример #6
0
    def get_list_of_users() -> m_LogicReturn:
        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
        _Users: [m_User]
        return m_LogicReturn.f_success(f"List of {len(_Users)} users", _Users)
Пример #7
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)
Пример #8
0
    def process_confirmation_code(confirm_token) -> m_LogicReturn:
        email = Token.confirm_token(confirm_token)
        if email is False:
            return m_LogicReturn.f_error_msg("This link is invalid or has expired.")

        User = db_User().get_user(
            m_UserEntries.email, email
        )
        if not User.success:
            return m_LogicReturn.f_error_msg("Can't find user with this email")
        User = User.addon_data
        User: m_User

        User.verified = True

        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("User is verified now!")
Пример #9
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}")
Пример #10
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)
Пример #11
0
    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)
Пример #12
0
    def update_session_using_db() -> m_LogicReturn:
        user_session = m_Session.fromSession(session)
        db_resp = db_User().get_user(m_UserEntries.user_uuid,
                                     user_session.User.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_session.User = User
        session['filo'] = user_session.toDict()
        return m_LogicReturn.f_success_msg("Session updated!")
Пример #13
0
    def google_login(google_token_id, user_email, client_id, avatar_link) -> m_LogicReturn:
        if v.value_empty(google_token_id) \
            or v.value_empty(user_email) \
                or v.value_empty(client_id) \
                or v.value_empty(avatar_link):
            return m_LogicReturn.f_error_msg("Data is missing!")

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

        logic_resp = SocialsLogic.verify_token_id(google_token_id, client_id)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg("invalid id token")

        google_user_id = logic_resp.addon_data

        db_resp = db_User().get_user(
            m_UserEntries.google_user_id,
            google_user_id
        )
        if not db_resp.success:
            logic_resp = AuthLogic.google_register(
                google_user_id, user_email, avatar_link)
            if not logic_resp.success:
                return m_LogicReturn.f_error_msg(logic_resp.content)

        db_resp = db_User().get_user(
            m_UserEntries.google_user_id,
            google_user_id
        )
        _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!")
Пример #14
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)
Пример #15
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)
Пример #16
0
    def user_send_mail(user_uuid, subject, content) -> 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

        _user_email = _user.email
        _user_voornaam = _user.first_name

        admin_mail = Email.get_admin_email(_user_email, _user_voornaam,
                                           subject, content)
        logic_resp = Email.send_email(_user_email, admin_mail)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg(logic_resp.content)
        return m_LogicReturn.f_success_msg("Mail sent!")
Пример #17
0
    def wipe_collection(col_name) -> m_LogicReturn:
        valid_col_names = ["users", "findlocks"]

        if col_name not in valid_col_names:
            return m_LogicReturn.f_error_msg(
                f"{col_name} is not a valid col name!")

        if col_name == "users":
            db_User().drop_col()
            db_User().create_user(debug_data.get_dummy_user())
            db_User().create_user(debug_data.get_dummy_user_with_permissions())
        elif col_name == "findlocks":
            db_Findlock().drop_col()
            _findlock = debug_data.get_dummy_findlock()
            _findlock.FindlockPermission.master_uuid = debug_data.get_dummy_user(
            ).user_uuid
            _findlock.FindlockPermission.addAllowedUuid(
                debug_data.get_dummy_user_with_permissions().user_uuid)
            db_Findlock().create_findlock(_findlock)

        return m_LogicReturn.f_success_msg("Executed.")