Skip to content

Auth Required Decorator #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 13, 2022
Prev Previous commit
Minor changes
  • Loading branch information
Archmonger committed Jul 13, 2022
commit e69a10ca0a6b5895c425516677e5756154510b9f
6 changes: 3 additions & 3 deletions docs/features/decorators.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Auth Required

You can limit access to a component to a specific `auth_attribute` by using this decorator.
You can limit access to a component to users with a specific `auth_attribute` by using this decorator.

By default, this decorator checks if the user is logged in, and his/her account has not been deactivated.

Expand Down Expand Up @@ -72,7 +72,7 @@ def my_component():

??? question "How can I check if a user `is_staff`?"

You can set the `auth_attribute` to use `is_staff`, as seen blow.
You can set the `auth_attribute` to `is_staff`, as seen blow.

```python title="components.py"
from django_idom.decorators import auth_required
Expand All @@ -98,7 +98,7 @@ def my_component():
class CustomUserModel(AbstractBaseUser):
@property
def is_really_cool(self):
return self.name == "Groot"
return True
```

... then you would do the following within your decorator:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_app/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def django_js():
@django_idom.decorators.auth_required(
fallback=idom.html.div(
{"id": "unauthorized-user-fallback"},
"unauthorized_user: Success. User was blocked from accessing this component.",
"unauthorized_user: Success",
idom.html.hr(),
)
)
Expand All @@ -118,13 +118,13 @@ def unauthorized_user():
auth_attribute="is_anonymous",
fallback=idom.html.div(
{"id": "authorized-user-fallback"},
"authorized_user: Fail.",
"authorized_user: Fail",
idom.html.hr(),
),
)
def authorized_user():
return idom.html.div(
{"id": "authorized-user"},
"authorized_user: Success. User was not blocked from accessing this component.",
"authorized_user: Success",
idom.html.hr(),
)