diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-25 03:40:09 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-25 03:40:09 +0300 |
| commit | 65d07ba64d45c77d2db16272710ec5702b34d641 (patch) | |
| tree | 4578793e288cd1a6dc08f87ab44d0e3568904c12 /public/app/controllers/Auth.php | |
| parent | 13753d58d6aceaea8f246040518d50f2eb06a8d9 (diff) | |
| download | classroom-65d07ba64d45c77d2db16272710ec5702b34d641.tar.gz classroom-65d07ba64d45c77d2db16272710ec5702b34d641.tar.bz2 classroom-65d07ba64d45c77d2db16272710ec5702b34d641.zip | |
front-end: putting everything together
Diffstat (limited to 'public/app/controllers/Auth.php')
| -rw-r--r-- | public/app/controllers/Auth.php | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php index b00843c..0570a5e 100644 --- a/public/app/controllers/Auth.php +++ b/public/app/controllers/Auth.php @@ -186,7 +186,7 @@ class Auth { $manager = new Classroom_manager(); if ($manager->hasUserToken()) { - echo 'user is connected'; + // user is connected; $token = $manager->getUserToken(); $user = $token->getUser(); @@ -226,9 +226,19 @@ class Auth { * to access the source * */ - public static function hasPermition($permit = []) + public static function hasPermition($permit = [0]) { - if ($permit == []) return true; + if (in_array(0, $permit)) { // permision 0 means public + return true; // permision 0 is always granted + } + + if ($user = $this->is_connected() === flase) { // if not connected + return false; // then no other permition is granted + } + + if ($user instanceof UserInterface) { + return ( !empty( array_intersect($permit, $user->getPrivileges()) ) ); + } } @@ -243,11 +253,11 @@ class Auth { * example: * [ * [ - * role => ['editor','designer'] + * role => [2, 3] * permition => ['10', '12', '18'] * ], * [ - * role => ['admin' , 'developερ'] + * role => [1 , 4] * ], * [ * permition => [ 3 ] @@ -256,12 +266,12 @@ class Auth { * * defines (and parses to) a requirements rule of: * [ - * user should be editor or designer - * and have permition 10 or 12 or 18 + * user should be creator or editor + * _AND_ have permition 10 or 12 or 18 * ] * OR * [ - * user should be an administratoe or developer + * user should be an administrator or developer * ] * OR * [ @@ -274,17 +284,25 @@ class Auth { { $authorized = false; foreach($requirements as $required) { - if ( (self::isGranted($required['role'] ?? [])) - && (self::hasPermition($required['permition'] ?? [])) ) { - $authorized = true; + + if (isset($required['role'])) { // if a role is required + if ( (self::isGranted($required['role'])) // authorize both role + && (self::hasPermition($required['permition'] ?? [ 0 ])) ) { // and permition + // $authorized = true; + return true; + } + + } else { // else, if not is not required + if (self::hasPermition($required['permition'] ?? [ 0 ])) { // authorize permition + // $authorized = true; + return true; + } } } return $authorized; } - - public static function forgot_pass() { } @@ -322,10 +340,10 @@ class Auth { } - public static function is_admin() + public static function in_admin_group() { $manager = new Classroom_manager(); - return ($manager->isGranted([1,2,3])); + return ($manager->isGranted([1, 2, 3])); } |
