summaryrefslogtreecommitdiff
path: root/html/app/controllers
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-04-15 08:11:01 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-04-15 08:11:01 +0300
commit84b2da85a1b452922dadb6a609533b9945afe51d (patch)
tree6ffb8e4d2a294385380332a8c148b153ed55975b /html/app/controllers
parenta584bf73b6d64dad98f150caba0f25e790cde010 (diff)
downloadclassroom-84b2da85a1b452922dadb6a609533b9945afe51d.tar.gz
classroom-84b2da85a1b452922dadb6a609533b9945afe51d.tar.bz2
classroom-84b2da85a1b452922dadb6a609533b9945afe51d.zip
several user-namagement tests and updates
Diffstat (limited to 'html/app/controllers')
-rw-r--r--html/app/controllers/Auth.php28
1 files changed, 23 insertions, 5 deletions
diff --git a/html/app/controllers/Auth.php b/html/app/controllers/Auth.php
index 6555f1c..b9314ff 100644
--- a/html/app/controllers/Auth.php
+++ b/html/app/controllers/Auth.php
@@ -31,25 +31,43 @@ class Auth {
$req = Registry::get('REQUEST');
// get the record of the target user
- $record = User_model::checkUser('email', $req->POST['email']);
+ $record = User_model::checkUser($req->POST['email']);
// if no user exists, return false
if ($record === false) return false;
-
+
+ // user is valid; check user password
// create a user object
- $user = (new User())
+ $user = (new Classroom_user())
+ ->setID($record['id'])
->setUserName($record['email'])
->setPassword($record['password'])
- ->setRoles(json_decode($record['roles']))
->setEnabled($record['active']);
// let user manager to validate user credentials
- $userManager = new UserManager();
+ $userManager = new Classroom_manager();
if ($userManager->isPasswordValid($user, $req->POST['password'])) {
+
+ // get user's security attributes
+ $attributes = User_Model::getUser($record['id']);
+ $user
+ ->setRoles(json_decode($attributes['Roles_json']))
+ ->setPrivileges(
+ explode( // example transform `[2,7] . [[1],[5,6]]` to `[2,7,1,5,6]`
+ str_replace(
+ ['[', ']'], // remove square parenthesis
+ '',
+ $attributes['RootPrivileges_json'] . $attributes['SubPrivileges_json']
+ ),
+ ','
+ )
+ );
+
// login OK, set Token in session
$userManager->createUserToken($user);
+ return true;
} else {
return false;