plain.auth 0.12.0__py3-none-any.whl → 0.13.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ # plain-auth changelog
2
+
3
+ ## [0.13.0](https://github.com/dropseed/plain/releases/plain-auth@0.13.0) (2025-06-23)
4
+
5
+ ### What's changed
6
+
7
+ - Added `login_client` and `logout_client` helpers to `plain.auth.test` for easily logging users in and out of the Django test client ([eb8a023](https://github.com/dropseed/plain/commit/eb8a023)).
8
+
9
+ ### Upgrade instructions
10
+
11
+ - No changes required
plain/auth/__init__.py CHANGED
@@ -1,3 +1,8 @@
1
1
  from .sessions import get_user, get_user_model, login, logout
2
2
 
3
- __all__ = ["login", "logout", "get_user_model", "get_user"]
3
+ __all__ = [
4
+ "login",
5
+ "logout",
6
+ "get_user_model",
7
+ "get_user",
8
+ ]
plain/auth/middleware.py CHANGED
@@ -22,6 +22,7 @@ class AuthenticationMiddleware:
22
22
  "'plain.sessions.middleware.SessionMiddleware' before "
23
23
  "'plain.auth.middleware.AuthenticationMiddleware'."
24
24
  )
25
+
25
26
  request.user = SimpleLazyObject(lambda: get_user(request))
26
- response = self.get_response(request)
27
- return response
27
+
28
+ return self.get_response(request)
plain/auth/test.py ADDED
@@ -0,0 +1,40 @@
1
+ from http.cookies import SimpleCookie
2
+
3
+ from plain.http.request import HttpRequest
4
+ from plain.runtime import settings
5
+ from plain.sessions import SessionStore
6
+
7
+ from .sessions import get_user, login, logout
8
+
9
+
10
+ def login_client(client, user):
11
+ """Log a user into a test client."""
12
+ request = HttpRequest()
13
+ if client.session:
14
+ request.session = client.session
15
+ else:
16
+ request.session = SessionStore()
17
+ login(request, user)
18
+ request.session.save()
19
+ session_cookie = settings.SESSION_COOKIE_NAME
20
+ client.cookies[session_cookie] = request.session.session_key
21
+ cookie_data = {
22
+ "max-age": None,
23
+ "path": "/",
24
+ "domain": settings.SESSION_COOKIE_DOMAIN,
25
+ "secure": settings.SESSION_COOKIE_SECURE or None,
26
+ "expires": None,
27
+ }
28
+ client.cookies[session_cookie].update(cookie_data)
29
+
30
+
31
+ def logout_client(client):
32
+ """Log out a user from a test client."""
33
+ request = HttpRequest()
34
+ if client.session:
35
+ request.session = client.session
36
+ request.user = get_user(request)
37
+ else:
38
+ request.session = SessionStore()
39
+ logout(request)
40
+ client.cookies = SimpleCookie()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plain.auth
3
- Version: 0.12.0
3
+ Version: 0.13.0
4
4
  Summary: User authentication and authorization for Plain.
5
5
  Author-email: Dave Gaeddert <dave.gaeddert@dropseed.dev>
6
6
  License-File: LICENSE
@@ -0,0 +1,13 @@
1
+ plain/auth/CHANGELOG.md,sha256=2afv0YFvPDyfa1tAzZX-U4O2voP1QkIFdcF44Uhduag,378
2
+ plain/auth/README.md,sha256=RJ8ry-ukLtLqcjRVAZ5cd1JgCr-JcUTi_9Kkg4kGmHc,2408
3
+ plain/auth/__init__.py,sha256=Id4ON6caLuZoZhu_kL6aMrwnN3Y8gPGVrVGs_V3ofAE,142
4
+ plain/auth/default_settings.py,sha256=65VzDn3j61OMn78Lg6Zuds4A8QKzJJ_0G9KoFqAOIRo,466
5
+ plain/auth/middleware.py,sha256=K7e9n5vMvGnALKcjG92AhWQMsZ8brIuS9M9zNZqt_RI,954
6
+ plain/auth/sessions.py,sha256=GCfXyGQhdSvMwKK3DpqK7fYjw2PiKbcZisWfrEeTRVM,5802
7
+ plain/auth/test.py,sha256=KfZSiX9S0p3AtCFAS4dUz4ctGIpOmLAGR-8nxAtM2TY,1163
8
+ plain/auth/utils.py,sha256=eEON0Mo928l-aW5tqBuoTdVke8aP4majxVtAFoLroSE,1280
9
+ plain/auth/views.py,sha256=_igztEBQKSM4CZro2lvlK0m01eIksqbmyux4w8gY1ks,4095
10
+ plain_auth-0.13.0.dist-info/METADATA,sha256=Hn0_O5AEclxmsrudT9yYLiYbI2R3ieZjrPbG4pE7xdU,2762
11
+ plain_auth-0.13.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
+ plain_auth-0.13.0.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
13
+ plain_auth-0.13.0.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- plain/auth/README.md,sha256=RJ8ry-ukLtLqcjRVAZ5cd1JgCr-JcUTi_9Kkg4kGmHc,2408
2
- plain/auth/__init__.py,sha256=oDOVSov5os1_l-hYNlGd5hb6vy0rF5Q3VMRV1UOZeFU,123
3
- plain/auth/default_settings.py,sha256=65VzDn3j61OMn78Lg6Zuds4A8QKzJJ_0G9KoFqAOIRo,466
4
- plain/auth/middleware.py,sha256=YJrzhro89SdSNDtfwyQM8jGgU5GmXvApZWiktit6K70,980
5
- plain/auth/sessions.py,sha256=GCfXyGQhdSvMwKK3DpqK7fYjw2PiKbcZisWfrEeTRVM,5802
6
- plain/auth/utils.py,sha256=eEON0Mo928l-aW5tqBuoTdVke8aP4majxVtAFoLroSE,1280
7
- plain/auth/views.py,sha256=_igztEBQKSM4CZro2lvlK0m01eIksqbmyux4w8gY1ks,4095
8
- plain_auth-0.12.0.dist-info/METADATA,sha256=z0OlP5WlYpxP9f9JlsYP8Yk7heXwwAc9vsWVGXL-YjQ,2762
9
- plain_auth-0.12.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- plain_auth-0.12.0.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
11
- plain_auth-0.12.0.dist-info/RECORD,,