Skip to content

Commit fae6a50

Browse files
committed
improved docs for user app, and projects
1 parent ed89196 commit fae6a50

File tree

5 files changed

+128
-17
lines changed

5 files changed

+128
-17
lines changed

docs/src/piccolo/authentication/baseuser.rst

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,81 @@
33
BaseUser
44
========
55

6-
Inherit from ``BaseUser`` to create your own User table.
6+
``BaseUser`` is a ``Table`` you can use to store and authenticate your users.
77

8-
.. code-block:: python
8+
-------------------------------------------------------------------------------
99

10-
from piccolo.apps.user.tables import BaseUser
10+
Creating the Table
11+
------------------
12+
13+
Run the migrations:
14+
15+
.. code-block:: bash
16+
17+
piccolo migrations forwards user
18+
19+
-------------------------------------------------------------------------------
20+
21+
Commands
22+
--------
23+
24+
The app comes with some useful commands.
25+
26+
user create
27+
~~~~~~~~~~~
1128

29+
Create a new user.
1230

13-
class User(BaseUser, tablename="custom_user"):
14-
pass
31+
.. code-block:: bash
1532
16-
.. hint:: A table name of `user` isn't allowed since it clashes with a keyword in Postgres - so override the ``tablename``, if you choose to name your class ``User``.
33+
piccolo user create
34+
35+
user change_password
36+
~~~~~~~~~~~~~~~~~~~~
37+
38+
Change a user's password.
39+
40+
.. code-block:: bash
41+
42+
piccolo user change_password
43+
44+
-------------------------------------------------------------------------------
45+
46+
Within your code
47+
----------------
1748

1849
login
19-
-----
50+
~~~~~
2051

21-
To login a user, do the following:
52+
To check a user's credentials, do the following:
2253

2354
.. code-block:: python
2455
56+
from piccolo.apps.user.tables import BaseUser
57+
2558
# From within a coroutine:
26-
await User.login(username="bob", password="abc123")
27-
>>> 1
59+
>>> await BaseUser.login(username="bob", password="abc123")
60+
1
2861
2962
# When not in an event loop:
30-
User.login_sync(username="bob", password="abc123")
31-
>>> 1
63+
>>> BaseUser.login_sync(username="bob", password="abc123")
64+
1
3265
3366
If the login is successful, the user's id is returned, otherwise ``None`` is
3467
returned.
3568

3669
update_password / update_password_sync
37-
--------------------------------------
70+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3871

3972
To change a user's password:
4073

4174
.. code-block:: python
4275
4376
# From within a coroutine:
44-
await User.update_password(username="bob", password="abc123")
77+
await BaseUser.update_password(username="bob", password="abc123")
4578
4679
# When not in an event loop:
47-
User.update_password_sync(username="bob", password="abc123")
80+
BaseUser.update_password_sync(username="bob", password="abc123")
4881
4982
.. warning:: Don't use bulk updates for passwords - use ``update_password`` /
5083
``update_password_sync``, and they'll correctly hash the password.

docs/src/piccolo/authentication/index.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33
Authentication
44
==============
55

6-
Piccolo ships with some basic authentication support out of the box.
6+
Piccolo ships with some authentication support out of the box.
7+
8+
-------------------------------------------------------------------------------
9+
10+
Registering the app
11+
-------------------
12+
13+
Make sure ``'piccolo.apps.user.piccolo_conf'`` is in your ``AppRegistry`` (see
14+
:ref:`PiccoloProjects`).
15+
16+
-------------------------------------------------------------------------------
17+
18+
Tables
19+
------
720

821
.. toctree::
922
:maxdepth: 1

docs/src/piccolo/projects_and_apps/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Projects and Apps
44
=================
55

6+
By using Piccolo projects and apps, you can build a larger, more modular,
7+
application.
8+
69
.. toctree::
710
:maxdepth: 1
811

docs/src/piccolo/projects_and_apps/piccolo_projects.rst

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,67 @@ Piccolo Projects
55

66
A Piccolo project is a collection of apps.
77

8+
-------------------------------------------------------------------------------
9+
10+
piccolo_conf.py
11+
---------------
12+
813
A project requires a `piccolo_conf.py` file. To create this file, use the following command:
914

1015
.. code-block:: bash
1116
1217
piccolo project new
1318
14-
The piccolo_conf file serves two important purposes:
19+
The file serves two important purposes:
1520

1621
* Contains your database settings
1722
* Is used for registering :ref:`PiccoloApps`.
23+
24+
-------------------------------------------------------------------------------
25+
26+
Example
27+
-------
28+
29+
Here's an example:
30+
31+
.. code-block:: python
32+
33+
from piccolo.engine.postgres import PostgresEngine
34+
35+
36+
from piccolo.conf.apps import AppRegistry
37+
38+
39+
DB = PostgresEngine(
40+
config={
41+
"database": "piccolo_project",
42+
"user": "postgres",
43+
"password": "",
44+
"host": "localhost",
45+
"port": 5432,
46+
}
47+
)
48+
49+
50+
APP_REGISTRY = AppRegistry(
51+
apps=["home.piccolo_app", "piccolo_admin.piccolo_app"]
52+
)
53+
54+
-------------------------------------------------------------------------------
55+
56+
DB
57+
--
58+
59+
The DB setting is an ``Engine`` instance. To learn more Engines, see
60+
:ref:`Engines`.
61+
62+
-------------------------------------------------------------------------------
63+
64+
APP_REGISTRY
65+
------------
66+
67+
The ``APP_REGISTRY`` setting is an ``AppRegistry`` instance.
68+
69+
.. currentmodule:: piccolo.conf.apps
70+
71+
.. autoclass:: AppRegistry

piccolo/conf/apps.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def register_table(self, table_class: t.Type[Table]):
7272

7373
@dataclass
7474
class AppRegistry:
75+
"""
76+
Records all of the Piccolo apps in your project.
77+
78+
:param apps:
79+
A list of paths to Piccolo apps, e.g. ['blog.piccolo_app']
80+
81+
"""
82+
7583
apps: t.List[str] = field(default_factory=list)
7684

7785
def __post_init__(self):

0 commit comments

Comments
 (0)