How to use the muffin.HTTPFound function in muffin

To help you get started, we’ve selected a few muffin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klen / muffin / example / admin.py View on Github external
def authorize(request):
    """ Check for current user's permissions.

    Can be redifined for each handler.

    """
    user = yield from app.ps.session.load_user(request)
    if not user or not user.is_super:
        raise muffin.HTTPFound('/')
    return user
github klen / muffin-admin / muffin_admin / handler.py View on Github external
async def post(self, request):
        """Create/Edit items."""
        form = await self.get_form(request)
        if not form.validate():
            raise muffin.HTTPBadRequest(
                text=json.dumps(form.errors), content_type='application/json')
        await self.save_form(form, request)
        raise muffin.HTTPFound(self.url)
github klen / muffin / example / views.py View on Github external
def logout(request):
    """ Implement user's logout. """
    yield from app.ps.session.logout(request)
    return muffin.HTTPFound('/')
github klen / muffin / example / views.py View on Github external
def login(request):
    """ Implement user's login. """
    data = yield from request.post()
    user = User.select().where(User.email == data.get('email')).get()
    if user.check_password(data.get('password')):
        yield from app.ps.session.login(request, user.pk)

    return muffin.HTTPFound('/')
github klen / muffin-admin / example / admin.py View on Github external
def bulk_delete(handler, request):
    """Bulk delete items"""
    ids = request.GET.getall('ids')
    Message.delete().where(Message.id << ids).execute()
    raise muffin.HTTPFound(handler.url)
github klen / muffin / example / views.py View on Github external
try:
        token = Token.select().where(Token.token == client.access_token).get()
        user = token.user
    except Exception:
        response = yield from client.request('GET', 'user')
        info = yield from response.json()

        user = User(username=info['login'], email=info['email'], password='NULL')
        user.save()

        token = Token(provider='github', token=client.access_token, user=user)
        token.save()

    yield from app.ps.session.login(request, user.id)

    return muffin.HTTPFound('/')
github klen / muffin / muffin / plugins / session.py View on Github external
def check_user(self, request, func=FUNC, location=None, **kwargs):
        """ Check for user is logged and pass func. """
        user = yield from self.load_user(request)
        func = func or self.options.default_user_checker
        if not func(user):
            raise HTTPFound(location or self.options.login_url, **kwargs)
        return user