Skip to content

Commit

Permalink
Fix literalincludes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Aug 12, 2023
1 parent c8afe8b commit 000996b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/example_db_auth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ Database
When the application runs, we initialise the DB with sample data using SQLAlchemy
ORM:

.. literalinclude:: demo/database_auth/main.py
.. literalinclude:: ../demo/database_auth/main.py
:pyobject: init_db


This will consist of 2 tables/models created in ``db.py``:

Users:

.. literalinclude:: demo/database_auth/db.py
.. literalinclude:: ../demo/database_auth/db.py
:pyobject: User

And their permissions:

.. literalinclude:: demo/database_auth/db.py
.. literalinclude:: ../demo/database_auth/db.py
:pyobject: Permission


Expand All @@ -59,15 +59,15 @@ database-based authorization policy.
In our example we will lookup a user login in the database and, if present, return
the identity.

.. literalinclude:: demo/database_auth/db_auth.py
.. literalinclude:: ../demo/database_auth/db_auth.py
:pyobject: DBAuthorizationPolicy.authorized_userid


For permission checking, we will fetch the user first, check if he is superuser
(all permissions are allowed), otherwise check if the permission is explicitly set
for that user.

.. literalinclude:: demo/database_auth/db_auth.py
.. literalinclude:: ../demo/database_auth/db_auth.py
:pyobject: DBAuthorizationPolicy.permits


Expand All @@ -76,7 +76,7 @@ Setup

Once we have all the code in place we can install it for our application:

.. literalinclude:: demo/database_auth/main.py
.. literalinclude:: ../demo/database_auth/main.py
:pyobject: init_app

Now we have authorization and can decorate every other view with access rights
Expand All @@ -86,12 +86,12 @@ based on permissions. There are two helpers included for this::

For each view you need to protect - just apply the decorator on it.

.. literalinclude:: demo/database_auth/handlers.py
.. literalinclude:: ../demo/database_auth/handlers.py
:pyobject: Web.protected_page

or

.. literalinclude:: demo/database_auth/handlers.py
.. literalinclude:: ../demo/database_auth/handlers.py
:pyobject: Web.logout

If someone tries to access that protected page he will see::
Expand All @@ -110,7 +110,7 @@ function may do what you are trying to accomplish::

from passlib.hash import sha256_crypt

.. literalinclude:: demo/database_auth/db_auth.py
.. literalinclude:: ../demo/database_auth/db_auth.py
:pyobject: check_credentials


Expand Down

0 comments on commit 000996b

Please sign in to comment.