summaryrefslogtreecommitdiff
path: root/public/app/controllers/Auth.php
diff options
context:
space:
mode:
Diffstat (limited to 'public/app/controllers/Auth.php')
-rw-r--r--public/app/controllers/Auth.php68
1 files changed, 34 insertions, 34 deletions
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
+ }
+ }
+
+
}