Closed bbelderbos closed 2 years ago
When a not baker user tries to access a restricted view, they are served the login page without explanation. I would like to add a message stating "restricted access" or possibly an error, but I'm not sure where I would add that since the user is being redirected by the decorator?
You can use Django's messages framework by using messages.error()
- but yeah how to do that with an existing decorator? Maybe wrap a new decorator around it? That's what my Google / SO search suggests too: https://stackoverflow.com/a/24423890
From the search link, it seems, take the functionality of login and add the messaging feature. I'll give it a shot.
Hope it does not overcomplicate it, maybe we can look at this together on our next call ...
I recommend option 2 https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html#onetoone
Need is to be able to signify a baker over a regular user to lock down coupon and treat views to "for bakers only" (for that we can use the
django.contrib.auth.decorators.user_passes_test
decorator later on.