Skip to content

[feature discussion] Roles (partly done by the way, see admin feature) #603

@jjkirkpatrick

Description

@jjkirkpatrick

Hi, i'm not sure if this has been discussed or not yet, but i feel like user roles is part of the user creation/login process. so with a few tweeks to the database to allow roles to be assigned to a user, we could then have a function in the Auth class to check if they have the required roles to view a view or a controller. here is a quick thrown together example

public static function canUserAccsess($requiredRoles = array()) {
    $Count = count($requiredRoles);
    $i = 0;
    while ($i < $Count) {      
        $status =  (session::get('user_' . $requiredRoles[$i]) ? true : false ) ;
        //return true as soon as one of the required roles is present.
        if($status == true){
            return true;
        }
        $i++;
    }
    //of non of them passed then we don't have the roles
    return false;
}

And then in the views or where ever we can simply do something like this.

if(Auth::canUserAccsess(['Sales','Admin'])){
echo "We got in!";
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions