#middleware or decorators for access

12 messages · Page 1 of 1 (latest)

nocturne vale
#

In my app, a subscription is required for 95% of the features. I'm wondering if it's better to add decorators to almost all functions requiring a subscription or to use middleware to manage access. The middleware approach could allow me to exclude the few pages that don't need a subscription, so I wouldn't have to worry about it when creating new views. Which method is more effective?

silk flare
#

subscriptions => user + something else, or is subscription == active user ?

#

If it is just "must have an active account to view", you can use LoginRequiredMiddleware and login_not_required decorator

nocturne vale
silk flare
#

So they have to have a active user with "payment=up2date" ?

#

but yeah, i would probably do something like the LoginRequiredMiddleware from 5.1.

#

You could probably subclass it to fit your needs as well

nocturne vale
#

Sorry, I am not clear -
I already have login needed set on views.

What i want to implement is for certain pages for which they need to do a payment (so they have access). This is stored in the user model.

And I thought it is probably better to write a middleware for it, since it is more maintainable. so everything is 'blocked' from non subscribed users be default, and i explicitly allow the url paths that are allowed to go through without a active subscription.

silk flare
#

yes?

silk flare
#

looks like you should only have to add a few lines to process_view