diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-18 01:11:37 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-18 01:11:37 +0300 |
| commit | 2b6970d33afd75be5bfef951dc3691d492004d43 (patch) | |
| tree | 39eba4206ca0c4cd3fecd5ead95580a74e50f3f9 /public/app/controllers | |
| parent | 68fc9e55e538e03f94509731ab41a0c8cf96710f (diff) | |
| download | classroom-2b6970d33afd75be5bfef951dc3691d492004d43.tar.gz classroom-2b6970d33afd75be5bfef951dc3691d492004d43.tar.bz2 classroom-2b6970d33afd75be5bfef951dc3691d492004d43.zip | |
admin back-office environment (skeleton); admin categories
Diffstat (limited to 'public/app/controllers')
| -rw-r--r-- | public/app/controllers/Admin.php | 58 | ||||
| -rw-r--r-- | public/app/controllers/Auth.php | 68 |
2 files changed, 92 insertions, 34 deletions
diff --git a/public/app/controllers/Admin.php b/public/app/controllers/Admin.php new file mode 100644 index 0000000..6f6858c --- /dev/null +++ b/public/app/controllers/Admin.php @@ -0,0 +1,58 @@ +<?php +namespace app\controllers; + +use Registry; +use Render; + +// user classes and models +use app\extends\Classroom_user; +use app\extends\Classroom_manager; +use app\models\admin\User_model; + +use app\extends\Send_mail; +use app\extends\Mail_jet; + + +/** class Auth + * + * handles user's Authentication and Authorizarion + * + */ +class Admin { + + /** admin cateogories + * + */ + public static function categories() + { + Render::view('admin/categories'); + } + + + /** admin lessons + * + */ + public static function lessons() + { + + } + + + /** admin pages + * + */ + public static function pages() + { + + } + + /** admin users + * + */ + public static function users() + { + + } + + +}
\ No newline at end of file diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php index f215388..d7b0c3b 100644 --- a/public/app/controllers/Auth.php +++ b/public/app/controllers/Auth.php @@ -41,6 +41,7 @@ class Auth { $user = (new Classroom_user()) ->setID($record['id']) ->setUserName($record['email']) + ->setName($record['first_name'] .' '. $record['last_name']) ->setPassword($record['password']) ->setEnabled($record['active']); @@ -67,7 +68,7 @@ class Auth { // set cookie for connected user setcookie( 'cluser', - 'connected', + 'connected;'. $user->getName(), time()+60*60*8, // 8 hours '/' ); @@ -138,6 +139,7 @@ class Auth { $user = (new Classroom_user()) ->setUserName($req->POST['email']) + ->setName($req->POST['name'] .' '. $req->POST['surname']) ->setPassword($password) ->setRoles([ READER ]) // Role: authorized reader ->setPrivileges([]); // none privilege until acount confirmation @@ -197,19 +199,19 @@ class Auth { } - - - public static function logout() { - $userManager = new UserManager(); + $userManager = new Classroom_manager(); $userManager->logout(); + // regeneration session ID (prevent session fixation) + session_regenerate_id(); + // remove user-conected cookie if (isset($_COOKIE['cluser'])) { unset($_COOKIE['cluser']); - setcookie('cluser', null, -1, '/'); + setcookie('cluser', '', -1, '/'); return true; } else { return false; @@ -218,34 +220,6 @@ class Auth { - /** isGranted( ROLE ) - * - * checks if the user is granted (some of) the specified role(s) - * to access the source - * - * NOTE: - * if no roles are specified then user is granted - * (because every user is granted the 'no-role') - * - * @param $roles (array): array of roles to check (if any is granted) - * - */ - public static function isGranted($roles = []) - { - // no role required ? user is granted access - if ($roles == []) return true; - - // else, UserManager knows if user isGranted - $userManager = new UserManager(); - if ($userManager->isGranted($roles)) { - return true; - - } else { - return false; - } - } - - /** hasPermition( PERMIT ) * * checks if the user owns the specified permition @@ -322,6 +296,32 @@ class Auth { } + /** allowRoles + * + * method filters access for certain roles + * if user is not grented acces, a forbiden message is sent and app ends._ + * otherwise the method returns true (app will continue) + * + * @param $allowed (array) : array of allowed roles + * @return true or die(); + */ + public static function allowRoles($allowed) + { + $manager = new Classroom_manager(); + if ($manager->isGranted($allowed)) { // if valid, return true (continue) + return true; + + } else { // no user, no access; die._ + Render::view('error/general', [ + 'title' => 'Forbidden', + 'message' => 'Access is forbidden' + ]); + die(); + return false; // this line will never run + } + } + + } |
