Python flask_login.AnonymousUserMixin() Examples

The following are 11 code examples of flask_login.AnonymousUserMixin(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_login , or try the search function .
Example #1
Source File: __init__.py    From vulyk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def unseen_events() -> flask.Response:
    """
    The list of yet unseen events we return for currently logged in user.

    :return: Events list (may be empty) or Forbidden if not authorized.
    :rtype: flask.Response
    """
    user = flask.g.user  # type: Union[User, AnonymousUserMixin]

    if isinstance(user, User):
        return utils.json_response({
            'events': map(
                lambda e: e.to_dict(ignore_answer=True),
                EventModel.get_unread_events(user))})
    else:
        flask.abort(utils.HTTPStatus.FORBIDDEN) 
Example #2
Source File: __init__.py    From vulyk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def all_events() -> flask.Response:
    """
    The list of all events we return for currently logged in user.

    :return: Events list (may be empty) or Forbidden if not authorized.
    :rtype: flask.Response
    """
    user = flask.g.user  # type: Union[User, AnonymousUserMixin]

    if isinstance(user, User):
        return utils.json_response({
            'events': map(
                lambda e: e.to_dict(ignore_answer=True),
                EventModel.get_all_events(user))})
    else:
        flask.abort(utils.HTTPStatus.FORBIDDEN) 
Example #3
Source File: __init__.py    From vulyk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def users_state(user_id: str = None) -> flask.Response:
    """
    The collected state of the user within the gamification subsystem.
    Could be created for the very first time asked (if hasn't yet).

    :param user_id: Needed user ID
    :type user_id: str

    :return: An response with a state or 404 if user is not found.
    :rtype: flask.Response
    """

    if user_id is not None:
        user = User.get_by_id(user_id)  # type: Union[User, None]
    else:
        user = flask.g.user  # type: Union[User, AnonymousUserMixin]

    if isinstance(user, User):
        state = UserStateModel.get_or_create_by_user(user)
        return utils.json_response({'state': state.to_dict()})
    else:
        flask.abort(utils.HTTPStatus.FORBIDDEN) 
Example #4
Source File: test_index.py    From acousticbrainz-server with GNU General Public License v2.0 6 votes vote down vote up
def test_menu_logged_in_error_dont_show_no_user(self, mock_user_get):
        """ If the user is logged in, if we show a 500 error, do not show the user menu
            Don't query the database to get a current_user for the template context"""
        @self.app.route('/page_that_returns_500')
        def view500():
            raise InternalServerError('error')

        user = db_user.get_or_create('little_rsh')
        mock_user_get.return_value = user
        self.temporary_login(user['id'])
        resp = self.client.get('/page_that_returns_500')
        data = resp.data.decode('utf-8')
        # item not in user menu
        self.assertNotIn('Your profile', data)
        self.assertIn('Sign in', data)
        mock_user_get.assert_not_called()
        self.assertIsInstance(self.get_context_variable('current_user'), AnonymousUserMixin) 
Example #5
Source File: core.py    From flask-security with MIT License 5 votes vote down vote up
def _identity_loader():
    if not isinstance(current_user._get_current_object(), AnonymousUserMixin):
        identity = Identity(current_user.fs_uniquifier)
        return identity 
Example #6
Source File: ldap.py    From burp-ui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def user(self, name=None):
        """See :func:`burpui.misc.auth.interface.BUIhandler.user`"""
        if name not in self.users:
            self.users[name] = LdapUser(self.ldap, name)
        ret = self.users[name]
        if not ret.active:
            return AnonymousUserMixin()
        return ret 
Example #7
Source File: local.py    From burp-ui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def user(self, name=None):
        """See :func:`burpui.misc.auth.interface.BUIhandler.user`"""
        if name not in self.users:
            self.users[name] = LocalUser(self.local, name)
        ret = self.users[name]
        if not ret.active:
            return AnonymousUserMixin()
        return ret 
Example #8
Source File: interface.py    From burp-ui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def user(self, name=None, refresh=False):
        """The :func:`burpui.misc.auth.interface.BUIhandler.user` function
        returns the :class:`flask_login:flask_login.UserMixin` object
        corresponding to the given user name.

        :param name: Name of the user
        :type name: str

        :param refresh: Whether we need to re-create a fresh user or not
        :type refresh: bool

        :returns: :class:`burpui.misc.auth.interface.BUIuser`
        """
        return AnonymousUserMixin() 
Example #9
Source File: basic.py    From burp-ui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def user(self, name=None):
        """See :func:`burpui.misc.auth.interface.BUIhandler.user`"""
        if name not in self.users:
            self.change = self.basic.load_users()
            self.users[name] = BasicUser(self.basic, name)
        ret = self.users[name]
        if not ret.active:
            return AnonymousUserMixin()
        return ret 
Example #10
Source File: __init__.py    From vulyk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def mark_viewed() -> flask.Response:
    """
    Mark all events as viewed for currently logged in user.

    :return: Successful response or Forbidden if not authorized.
    :rtype: flask.Response
    """
    user = flask.g.user  # type: Union[User, AnonymousUserMixin]

    if isinstance(user, User):
        EventModel.mark_events_as_read(user)
        return utils.json_response({})
    else:
        flask.abort(utils.HTTPStatus.FORBIDDEN) 
Example #11
Source File: __init__.py    From vulyk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def donate() -> flask.Response:
    """
    Performs a money donation to specified fund.

    :return: Usual JSON response
    :rtype: flask.Response
    """
    user = flask.g.user  # type: Union[User, AnonymousUserMixin]

    if isinstance(user, AnonymousUserMixin):
        flask.abort(utils.HTTPStatus.FORBIDDEN)

    fund_id = flask.request.form.get('fund_id')  # type: str
    amount = flask.request.form.get('amount')  # type: int

    try:
        amount = Decimal(amount)
    except ValueError:
        return flask.abort(utils.HTTPStatus.BAD_REQUEST)

    result = DonationsService(user, fund_id, amount).donate()

    if result == DonationResult.SUCCESS:
        return utils.json_response({'done': True})
    elif result == DonationResult.BEGGAR:
        return utils.json_response(
            result={'done': False},
            errors=['Not enough money on your active account'],
            status=utils.HTTPStatus.BAD_REQUEST)
    elif result == DonationResult.STINGY:
        return utils.json_response(
            result={'done': False},
            errors=['Wrong amount passed'],
            status=utils.HTTPStatus.BAD_REQUEST)
    elif result == DonationResult.LIAR:
        return utils.json_response(
            result={'done': False},
            errors=['Wrong fund ID passed'],
            status=utils.HTTPStatus.BAD_REQUEST)
    elif result == DonationResult.ERROR:
        return utils.json_response(
            result={'done': False},
            errors=['Something wrong happened'],
            status=utils.HTTPStatus.BAD_REQUEST)