Skip to main content

No project description provided

Project description

Muffin-Session – Implement an user sessions in Muffin Framework.

Build Status http://img.shields.io/pypi/v/muffin-session.svg?style=flat-square http://img.shields.io/pypi/dm/muffin-session.svg?style=flat-square

Requirements

  • python >= 3.3

Installation

Muffin-Session should be installed using pip:

pip install muffin-session

Usage

  • Add muffin_session to PLUGINS in your Application configuration.

  • Setup options if needed (see bellow).

Options

SESSION_AUTO_LOAD – Load session every request automatically Session will be loaded into request.session.

SESSION_DEFAULT_USER_CHECKER – A function which checks logged user (lambda x: x)

SESSION_LOGIN_URL – Redirect URL (‘/login’), or it may be a function which accepts request object and returns a string.

SESSION_SECRET – A secret code (‘Insecuresecret’)

SESSION_MAX_AGE – # Defines the lifetime of the session-cookie, in seconds

SESSION_DOMAIN – # Defines session-cookie domain

Examples

@app.ps.session.user_loader
def load_user(_id):
    """Define your own user loader. """

@app.register('/session')
def get_session(request):
    """ Load session and return it as JSON. """
    session = yield from app.ps.session(request)
    return dict(session)

@app.register('/admin')
@app.ps.session.user_pass(lambda u: u.is_admin)
def admin(request):
    """ Check for user is admin. """


@app.register('/login')
def login(request):
    """ Login user. """
    # ...
    yield from app.ps.session.login(current_user.pk)


@app.register('/logout')
def logout(request):
    """ Logout user. """
    # ...
    yield from app.ps.session.logout(curuser.pk)

@app.register('/somewhere')
def somewhere(request):
    """ Do something and leave a flash message """
    # ...
    yield from app.ps.session.flash('Something done successfully')

@app.register('/common')
def common_page(request):
    """
    This can be included in any endpoint which outputs regular page.
    If you use jinja2 or other templating engine,
    you will need to pass `request` to its context somehow.
    Also this plugin will register `get_flashed_messages` function in Jinja2 context,
    but only if Jinja2 plugin was loaded before this one.
    """
    # first we want to ensure that session is loaded,
    yield from app.ps.session.load()
    # this method is *not* a coroutine, so it can be used in templates
    messages = app.ps.session.get_flashed_messages()
    return (
        "<html><body><header>%s</header> Other content </body></html>" %
        '<br/>'.join(messages)
    )

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/muffin-session/issues

Contributing

Development of Muffin-Session happens at: https://github.com/klen/muffin-session

Contributors

  • klen (Kirill Klenov)

License

Licensed under a MIT license.

If you wish to express your appreciation for the project, you are welcome to send a postcard to:

Kirill Klenov
pos. Severny 8-3
MO, Istra, 143500
Russia

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

muffin-session-0.6.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

muffin_session-0.6.1-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file muffin-session-0.6.1.tar.gz.

File metadata

  • Download URL: muffin-session-0.6.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.3

File hashes

Hashes for muffin-session-0.6.1.tar.gz
Algorithm Hash digest
SHA256 49dff7dc58ed7603621b63d3bad4492d2843abc551b21f308f834dbed85b95fa
MD5 56ef7bcd01b4bb5f73d11a337064eb37
BLAKE2b-256 451a2ef0b1441bc39c75f0ce1e751c81dd3d7639f67f5ebfc506ec527f19ef5a

See more details on using hashes here.

File details

Details for the file muffin_session-0.6.1-py2.py3-none-any.whl.

File metadata

  • Download URL: muffin_session-0.6.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.3

File hashes

Hashes for muffin_session-0.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 571cabc2210ddf8ec1fb164b457eb3efe9532e4c693c6df1ff92fb9cbd118cd2
MD5 9437670a12b85afc888ca3bcfb4e60d7
BLAKE2b-256 2632f9d99ce2b4d6542996e9aac18bded034e6ff3a2e83764faabe97fc8d1a49

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page