{ "info": { "author": "Kirill Klenov", "author_email": "horneds@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Natural Language :: Russian", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Testing", "Topic :: Utilities" ], "description": "Muffin-Session\n##############\n\n.. _description:\n\nMuffin-Session -- Implement an user sessions in Muffin Framework.\n\n.. _badges:\n\n.. image:: http://img.shields.io/travis/klen/muffin-session.svg?style=flat-square\n :target: http://travis-ci.org/klen/muffin-session\n :alt: Build Status\n\n.. image:: http://img.shields.io/pypi/v/muffin-session.svg?style=flat-square\n :target: https://pypi.python.org/pypi/muffin-session\n\n.. image:: http://img.shields.io/pypi/dm/muffin-session.svg?style=flat-square\n :target: https://pypi.python.org/pypi/muffin-session\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.3\n\n.. _installation:\n\nInstallation\n=============\n\n**Muffin-Session** should be installed using pip: ::\n\n pip install muffin-session\n\n.. _usage:\n\nUsage\n=====\n\n* Add **muffin_session** to **PLUGINS** in your Application configuration.\n* Setup options if needed (see bellow).\n\nOptions\n-------\n\n`SESSION_AUTO_LOAD` -- Load session every request automatically\nSession will be loaded into `request.session`.\n\n`SESSION_DEFAULT_USER_CHECKER` -- A function which checks logged user (lambda x: x)\n\n`SESSION_LOGIN_URL` -- Redirect URL ('/login'), or it may be a function\nwhich accepts `request` object and returns a string.\n\n`SESSION_SECRET` -- A secret code ('Insecuresecret')\n\n`SESSION_MAX_AGE` -- # Defines the lifetime of the session-cookie, in seconds\n\n`SESSION_DOMAIN` -- # Defines session-cookie domain\n\nExamples\n--------\n\n::\n\n @app.ps.session.user_loader\n def load_user(_id):\n \"\"\"Define your own user loader. \"\"\"\n\n @app.register('/session')\n def get_session(request):\n \"\"\" Load session and return it as JSON. \"\"\"\n session = yield from app.ps.session(request)\n return dict(session)\n\n @app.register('/admin')\n @app.ps.session.user_pass(lambda u: u.is_admin)\n def admin(request):\n \"\"\" Check for user is admin. \"\"\"\n\n\n @app.register('/login')\n def login(request):\n \"\"\" Login user. \"\"\"\n # ...\n yield from app.ps.session.login(current_user.pk)\n\n\n @app.register('/logout')\n def logout(request):\n \"\"\" Logout user. \"\"\"\n # ...\n yield from app.ps.session.logout(curuser.pk)\n\n @app.register('/somewhere')\n def somewhere(request):\n \"\"\" Do something and leave a flash message \"\"\"\n # ...\n yield from app.ps.session.flash('Something done successfully')\n\n @app.register('/common')\n def common_page(request):\n \"\"\"\n This can be included in any endpoint which outputs regular page.\n If you use jinja2 or other templating engine,\n you will need to pass `request` to its context somehow.\n Also this plugin will register `get_flashed_messages` function in Jinja2 context,\n but only if Jinja2 plugin was loaded before this one.\n \"\"\"\n # first we want to ensure that session is loaded,\n yield from app.ps.session.load()\n # this method is *not* a coroutine, so it can be used in templates\n messages = app.ps.session.get_flashed_messages()\n return (\n \"