/    Sign up×
Community /Pin to ProfileBookmark

User Permission Design

I have a user class in my project. It’s used to create membership users as well as set administrative permissions etc.

The way this works is I have a method called validateAccess which has a function integer passed in. This checks the database to see if the user has access and returns true or false.

All members, including admins user the same user class.

I use this validateAccess method to determine if someone should have access to a page etc.

I also have a “news” class. Where people can add news etc.

One of the user functions is “add-news” and has an ID of 12. This ID comes from a small DB table where I have ID and FunctionName columns.

What I want to be able to do is within the “add-news” method, check to see if the user calling this method has this permission.

So in a method of the news class, call a method on the users class.

My questions are..

1) To do this -> would I need to pass in the user each time a method is called? such as $News->addNews($thisUser) or is there another option? perhaps using a session or cookie?

2) This issue is have and see here is with so many methods over several class – is this the best way to do this?

Currently I have database table with function names such as add news. Is there a better way of doing this?

_Of note – not all methods in a class need permissions such as getNews($ID) will get this one article._

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 30.2021 — Maybe when successfully logged in, create an array with all permissions they have and store that in $_SESSION? Then you can access it any time you need to know any of that user's permissions.
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...