@@ -23,20 +23,20 @@ Database
23
23
When the application runs, we initialise the DB with sample data using SQLAlchemy
24
24
ORM:
25
25
26
- .. literalinclude :: demo/database_auth/main.py
26
+ .. literalinclude :: ../ demo/database_auth/main.py
27
27
:pyobject: init_db
28
28
29
29
30
30
This will consist of 2 tables/models created in ``db.py ``:
31
31
32
32
Users:
33
33
34
- .. literalinclude :: demo/database_auth/db.py
34
+ .. literalinclude :: ../ demo/database_auth/db.py
35
35
:pyobject: User
36
36
37
37
And their permissions:
38
38
39
- .. literalinclude :: demo/database_auth/db.py
39
+ .. literalinclude :: ../ demo/database_auth/db.py
40
40
:pyobject: Permission
41
41
42
42
@@ -59,15 +59,15 @@ database-based authorization policy.
59
59
In our example we will lookup a user login in the database and, if present, return
60
60
the identity.
61
61
62
- .. literalinclude :: demo/database_auth/db_auth.py
62
+ .. literalinclude :: ../ demo/database_auth/db_auth.py
63
63
:pyobject: DBAuthorizationPolicy.authorized_userid
64
64
65
65
66
66
For permission checking, we will fetch the user first, check if he is superuser
67
67
(all permissions are allowed), otherwise check if the permission is explicitly set
68
68
for that user.
69
69
70
- .. literalinclude :: demo/database_auth/db_auth.py
70
+ .. literalinclude :: ../ demo/database_auth/db_auth.py
71
71
:pyobject: DBAuthorizationPolicy.permits
72
72
73
73
76
76
77
77
Once we have all the code in place we can install it for our application:
78
78
79
- .. literalinclude :: demo/database_auth/main.py
79
+ .. literalinclude :: ../ demo/database_auth/main.py
80
80
:pyobject: init_app
81
81
82
82
Now we have authorization and can decorate every other view with access rights
@@ -86,12 +86,12 @@ based on permissions. There are two helpers included for this::
86
86
87
87
For each view you need to protect - just apply the decorator on it.
88
88
89
- .. literalinclude :: demo/database_auth/handlers.py
89
+ .. literalinclude :: ../ demo/database_auth/handlers.py
90
90
:pyobject: Web.protected_page
91
91
92
92
or
93
93
94
- .. literalinclude :: demo/database_auth/handlers.py
94
+ .. literalinclude :: ../ demo/database_auth/handlers.py
95
95
:pyobject: Web.logout
96
96
97
97
If someone tries to access that protected page he will see::
@@ -110,7 +110,7 @@ function may do what you are trying to accomplish::
110
110
111
111
from passlib.hash import sha256_crypt
112
112
113
- .. literalinclude :: demo/database_auth/db_auth.py
113
+ .. literalinclude :: ../ demo/database_auth/db_auth.py
114
114
:pyobject: check_credentials
115
115
116
116
0 commit comments