示例#1
0
文件: user.py 项目: inkhey/tracim
    def execute_updated_user_actions(self, user: User) -> None:
        """
        WARNING! This method will be deprecated soon, see
        https://github.com/tracim/tracim/issues/1589 and
        https://github.com/tracim/tracim/issues/1487

        This method does post-update user actions
        """

        # TODO - G.M - 04-04-2018 - [auth]
        # Check if this is already needed with
        # new auth system
        user.ensure_auth_token(
            validity_seconds=self._config.USER__AUTH_TOKEN__VALIDITY)

        # FIXME - G.M - 2019-03-18 - move this code to another place when
        # event mechanism is ready, see https://github.com/tracim/tracim/issues/1487
        # event on_updated_user should start hook use by agenda  app code.

        app_lib = ApplicationApi(app_list=app_list)
        if app_lib.exist(AGENDA__APP_SLUG):
            agenda_api = AgendaApi(current_user=self._user,
                                   session=self._session,
                                   config=self._config)
            try:
                agenda_api.ensure_user_agenda_exists(user)
            except AgendaServerConnectionError as exc:
                logger.error(self, "Cannot connect to agenda server")
                logger.exception(self, exc)
            except Exception as exc:
                logger.error(
                    self, "Something goes wrong during agenda create/update")
                logger.exception(self, exc)
示例#2
0
    def test_unit__reset_token__ok__nominal_case(self):
        email = "*****@*****.**"

        user = User()
        user.email = email
        assert user.auth_token is None
        with freeze_time("1999-12-31 23:59:59"):
            user.ensure_auth_token(validity_seconds=5)
            assert user.auth_token
            assert user.auth_token_created == datetime.now()
            token = user.auth_token
            token_time = user.auth_token_created

        with freeze_time("2003-12-31 23:59:59"):
            user.reset_tokens()
            assert user.auth_token != token
            assert user.auth_token_created != token_time
            assert user.auth_token_created == datetime.now()
示例#3
0
    def test_unit__reset_token__ok__nominal_case(self):
        email = '*****@*****.**'

        user = User()
        user.email = email
        assert user.auth_token is None
        with freeze_time("1999-12-31 23:59:59"):
            user.ensure_auth_token(validity_seconds=5)
            assert user.auth_token
            assert user.auth_token_created == datetime.now()
            token = user.auth_token
            token_time = user.auth_token_created

        with freeze_time("2003-12-31 23:59:59"):
            user.reset_tokens()
            assert user.auth_token != token
            assert user.auth_token_created != token_time
            assert user.auth_token_created == datetime.now()
示例#4
0
文件: user.py 项目: tracim/tracim_v2
    def execute_created_user_actions(self, created_user: User) -> None:
        """
        Execute actions when user just been created
        :return:
        """
        # NOTE: Cyclic import
        # TODO - G.M - 28-03-2018 - [Calendar] Reenable Calendar stuff
        #from tracim.lib.calendar import CalendarManager
        #from tracim.model.organisational import UserCalendar

        # TODO - G.M - 04-04-2018 - [auth]
        # Check if this is already needed with
        # new auth system
        created_user.ensure_auth_token(
            validity_seconds=self._config.USER_AUTH_TOKEN_VALIDITY)

        # Ensure database is up-to-date
        self._session.flush()
        transaction.commit()
示例#5
0
文件: user.py 项目: tracim/tracim
    def execute_created_user_actions(self, created_user: User) -> None:
        """
        Execute actions when user just been created
        :return:
        """
        # NOTE: Cyclic import
        # TODO - G.M - 28-03-2018 - [Calendar] Reenable Calendar stuff
        #from tracim.lib.calendar import CalendarManager
        #from tracim.model.organisational import UserCalendar

        # TODO - G.M - 04-04-2018 - [auth]
        # Check if this is already needed with
        # new auth system
        created_user.ensure_auth_token(
            validity_seconds=self._config.USER_AUTH_TOKEN_VALIDITY
        )

        # Ensure database is up-to-date
        self._session.flush()
        transaction.commit()
示例#6
0
    def execute_created_user_actions(self, user: User) -> None:
        """
        WARNING ! This method Will be Deprecated soon, see
        https://github.com/tracim/tracim/issues/1589 and
        https://github.com/tracim/tracim/issues/1487

        This method do post-create user actions
        """

        # TODO - G.M - 04-04-2018 - [auth]
        # Check if this is already needed with
        # new auth system
        user.ensure_auth_token(
            validity_seconds=self._config.USER__AUTH_TOKEN__VALIDITY)

        # FIXME - G.M - 2019-03-18 - move this code to another place when
        # event mecanism is ready, see https://github.com/tracim/tracim/issues/1487
        # event on_created_user should start hook use by agenda  app code.

        if self._config.CALDAV__ENABLED:
            agenda_api = AgendaApi(current_user=self._user,
                                   session=self._session,
                                   config=self._config)
            try:
                agenda_already_exist = agenda_api.ensure_user_agenda_exists(
                    user)
                if agenda_already_exist:
                    logger.warning(
                        self,
                        "user {} is just created but his own agenda already exist !!"
                        .format(user.user_id),
                    )
            except AgendaServerConnectionError as exc:
                logger.error(self, "Cannot connect to agenda server")
                logger.exception(self, exc)
            except Exception as exc:
                logger.error(
                    self, "Something goes wrong during agenda create/update")
                logger.exception(self, exc)