From 463139601c046a5201cb8a73473f8fe5c568b760 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Thu, 27 Apr 2023 20:15:02 +0300 Subject: rearangment completed; now anything is simplel --- public/app/controllers/Auth.php | 15 +- public/app/controllers/CmsAdmin.php | 2 +- public/app/extends/Cache_service.php | 4 +- public/app/extends/Classroom_manager.php | 4 +- public/app/extends/SendMail_service.php | 212 +++++++++++++++++++ public/app/extends/Send_mail.php | 212 ------------------- public/app/models/Access_model.php | 269 ++++++++++++++++++++++++ public/app/models/History_model.php | 34 +++ public/app/models/User_model.php | 311 ---------------------------- public/app/models/admin/History_model.php | 34 --- public/app/models/admin/Privilege_model.php | 42 ---- public/app/models/todo.md | 7 +- 12 files changed, 531 insertions(+), 615 deletions(-) create mode 100644 public/app/extends/SendMail_service.php delete mode 100644 public/app/extends/Send_mail.php create mode 100644 public/app/models/Access_model.php create mode 100644 public/app/models/History_model.php delete mode 100644 public/app/models/User_model.php delete mode 100644 public/app/models/admin/History_model.php delete mode 100644 public/app/models/admin/Privilege_model.php (limited to 'public/app') diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php index aeec41c..4b3dcfb 100644 --- a/public/app/controllers/Auth.php +++ b/public/app/controllers/Auth.php @@ -7,10 +7,9 @@ use Render; // user classes and models use app\extends\Classroom_user; use app\extends\Classroom_manager; -use app\models\User_model; +use app\models\Access_model; +use app\extends\SendMail_service; -use app\extends\Send_mail; -use app\extends\Mail_jet; /** class Auth @@ -31,7 +30,7 @@ class Auth { $req = Registry::get('REQUEST'); // get the record of the target user - $record = User_model::checkUser($req->POST['email']); + $record = Access_model::checkUser($req->POST['email']); // if no user exists, return false if ($record === false) return false; @@ -51,7 +50,7 @@ class Auth { if ($userManager->isPasswordValid($user, $req->POST['password'])) { // get user's security attributes - $attributes = User_Model::getUser($record['id']); + $attributes = Access_model::getUser($record['id']); $roles = json_decode($attributes['Roles_json']); $user ->setRoles($roles) @@ -111,7 +110,7 @@ class Auth { $req = Registry::get('REQUEST'); // get the record of the target user - $check = User_model::activate($req->GET['ticket']); + $check = Access_model::activate($req->GET['ticket']); if ($check == true) { Render::view('/error/general', [ @@ -151,7 +150,7 @@ class Auth { ->setPrivileges([]); // none privilege until acount confirmation // create user record - $activation_code = User_model::registerUser($req->POST, $password); + $activation_code = Access_model::registerUser($req->POST, $password); // TODO: // handle error on user registration @@ -164,7 +163,7 @@ class Auth { // ]; // } - $send_mail = Send_mail::send_activation_code([ + $send_mail = SendMail_service::send_activation_code([ 'email' => $req->POST['email'], 'name' => $req->POST['name'] .' '. $req->POST['surname'], 'code' => $activation_code['activation'] diff --git a/public/app/controllers/CmsAdmin.php b/public/app/controllers/CmsAdmin.php index aa6ff6f..9629741 100644 --- a/public/app/controllers/CmsAdmin.php +++ b/public/app/controllers/CmsAdmin.php @@ -1,6 +1,6 @@ POST); + $register = Access_model::registerUser($req->POST); if ($register['success']) { @@ -83,7 +83,7 @@ class Classroom_manager extends UserManager public function create_OTP($id) { $otp = rand(100000,999999); - User_model::set_OTP($id, $otp); + Access_model::set_OTP($id, $otp); return true; } diff --git a/public/app/extends/SendMail_service.php b/public/app/extends/SendMail_service.php new file mode 100644 index 0000000..c717e61 --- /dev/null +++ b/public/app/extends/SendMail_service.php @@ -0,0 +1,212 @@ + user email + * name => user full name + * subject => subject + * body => email message body + * ] + * + * then send the email; + * + * @param $activator (array): [ + * email => user email, + * name => user full name, + * code => activation code + * ] + * + * @return success_starus (boolean) + * + * TODO: + * check for email templating: + * + https://stackoverflow.com/questions/2391171/how-to-get-output-from-local-script-in-php + * + https://stackoverflow.com/questions/171318/how-do-i-capture-php-output-into-a-variable + */ + public static function send_activation_code($activator) + { + $activation_url = SITE_URL ."/account/activate?ticket=". $activator['code']; + $envelope = [ + 'email' => $activator['email'], + 'name' => $activator['name'], + 'subject' => 'Εγγραφή στο Classroom', + 'body' => "Χαίρετε,
+ το παρόν αυτοποιημένο email σάς έχει σταλεί + γιατί έχει γίνει αίτημα εγγραφής σας στο Classroom.
+
+ Όνομα επαφής: ". $activator['name'] ."
+ Email : ". $activator['email'] ."
+
+ Για να ενεργοποιήσετε την πρόσβασή σας στο site + θα πρέπει ακολουθήσετε τον παρακάτω σύνδεσμο: + ". $activation_url .". +
+
+ Μετά την ενεργοποίηση θα έχετε πρόσσβαση + στο περιεχόμενο του site.
+ Μην απαντήσετε στο email, + δεν υπάρχει φυσική επαφή η οποία να λαμβάνει τυχόν replies." + ]; + + switch (DEFAULT_MAIL_SERVICE) { + case 'mailjet': + $reply = self::send_mailjet($envelope); + break; + + case 'phpMailer': + $reply = self::send_phpMailer($envelope); + break; + } + + return $reply; + + } + + + /** send phpMailer + * + * send email using phpMailer class; + * optional SMTP server configuration; + * + * @param $envelope + * @return success_starus (boolean) + */ + public static function send_phpMailer($envelope) + { + $mail = new PHPMailer(); + + # // setup smpt + $mail->SMTPDebug = 3; + $mail->IsSMTP(); + $mail->Host = MAIL_HOST; + # $mail->SMPTAuth = false; + $mail->SMTPSecure = MAIL_ENCRYPTION; + # // $mail->Protocol = 'mail'; + + $mail->Mailer = MAIL_MAILER; + $mail->Port = MAIL_PORT; + $mail->Username = MAIL_USERNAME; + $mail->Password = MAIL_PASSWORD; + + // setup format + $mail->CharSet = 'utf-8'; + $mail->IsHTML(true); + + // setup THE mail + // --- -- -- - - - + // It's important not to use the submitter's address as the from address + // as it's forgery, which will cause your messages to fail SPF checks. + // Use an address in your own domain as the from address; + // put the submitter's address in a reply-to + + $mail->setFrom(NO_REPLY_EMAIL, MAIL_FROM_NAME); + $mail->addAddress($envelope['email'], $envelope['name']); + $mail->addReplyTo(REPLY_TO_EMAIL, MAIL_FROM_NAME); + $mail->Subject = $envelope['subject']; + $mail->Body = $envelope['body']; + + return (!$mail->send()) ? false : true; + + } + + + /** send_mailjet + * + * send email using CURL mail-relay of Mailjet + * + * @param $envelope + * @return success_starus (boolean) + */ + public static function send_mailjet($envelope) + { + $body = [ + 'Messages' => [ + [ + 'From' => [ + 'Email' => REPLY_TO_EMAIL, + 'Name' => MAIL_FROM_NAME + ], + 'To' => [ + [ + 'Email' => $envelope['email'], + 'Name' => $envelope['name'] + ] + ], + 'Subject' => $envelope['subject'], + 'HTMLPart' => $envelope['body'] + ] + ] + ]; + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, "https://api.mailjet.com/v3.1/send"); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json') + ); + curl_setopt( + $ch, + CURLOPT_USERPWD, + MAILJET_APIKEY. ':'. MAILJET_SECRET + ); + $server_output = curl_exec($ch); + curl_close ($ch); + + $response = json_decode($server_output); + + return ($response->Messages[0]->Status == 'success'); + + } + + + +} + + + + + +/** NOTE: + * ----------------------------------------------------------------------------- + * (brainstorming) + * + +Optimization per concept alternative technologies +--- -- -- - - - + +## Session +File Session +Database Session +Redis Session +Memcached Session + +--- + +## Cache +File Cache +Database Cache +Redis Cache +Memcashed Cache + +--- + +## Log +File Log +Database Log +Log event to Slack +Log event to Email + + * ----------------------------------------------------------------------------- + */ diff --git a/public/app/extends/Send_mail.php b/public/app/extends/Send_mail.php deleted file mode 100644 index 52eab53..0000000 --- a/public/app/extends/Send_mail.php +++ /dev/null @@ -1,212 +0,0 @@ - user email - * name => user full name - * subject => subject - * body => email message body - * ] - * - * then send the email; - * - * @param $activator (array): [ - * email => user email, - * name => user full name, - * code => activation code - * ] - * - * @return success_starus (boolean) - * - * TODO: - * check for email templating: - * + https://stackoverflow.com/questions/2391171/how-to-get-output-from-local-script-in-php - * + https://stackoverflow.com/questions/171318/how-do-i-capture-php-output-into-a-variable - */ - public static function send_activation_code($activator) - { - $activation_url = SITE_URL ."/account/activate?ticket=". $activator['code']; - $envelope = [ - 'email' => $activator['email'], - 'name' => $activator['name'], - 'subject' => 'Εγγραφή στο Classroom', - 'body' => "Χαίρετε,
- το παρόν αυτοποιημένο email σάς έχει σταλεί - γιατί έχει γίνει αίτημα εγγραφής σας στο Classroom.
-
- Όνομα επαφής: ". $activator['name'] ."
- Email : ". $activator['email'] ."
-
- Για να ενεργοποιήσετε την πρόσβασή σας στο site - θα πρέπει ακολουθήσετε τον παρακάτω σύνδεσμο: - ". $activation_url .". -
-
- Μετά την ενεργοποίηση θα έχετε πρόσσβαση - στο περιεχόμενο του site.
- Μην απαντήσετε στο email, - δεν υπάρχει φυσική επαφή η οποία να λαμβάνει τυχόν replies." - ]; - - switch (DEFAULT_MAIL_SERVICE) { - case 'mailjet': - $reply = self::send_mailjet($envelope); - break; - - case 'phpMailer': - $reply = self::send_phpMailer($envelope); - break; - } - - return $reply; - - } - - - /** send phpMailer - * - * send email using phpMailer class; - * optional SMTP server configuration; - * - * @param $envelope - * @return success_starus (boolean) - */ - public static function send_phpMailer($envelope) - { - $mail = new PHPMailer(); - - # // setup smpt - $mail->SMTPDebug = 3; - $mail->IsSMTP(); - $mail->Host = MAIL_HOST; - # $mail->SMPTAuth = false; - $mail->SMTPSecure = MAIL_ENCRYPTION; - # // $mail->Protocol = 'mail'; - - $mail->Mailer = MAIL_MAILER; - $mail->Port = MAIL_PORT; - $mail->Username = MAIL_USERNAME; - $mail->Password = MAIL_PASSWORD; - - // setup format - $mail->CharSet = 'utf-8'; - $mail->IsHTML(true); - - // setup THE mail - // --- -- -- - - - - // It's important not to use the submitter's address as the from address - // as it's forgery, which will cause your messages to fail SPF checks. - // Use an address in your own domain as the from address; - // put the submitter's address in a reply-to - - $mail->setFrom(NO_REPLY_EMAIL, MAIL_FROM_NAME); - $mail->addAddress($envelope['email'], $envelope['name']); - $mail->addReplyTo(REPLY_TO_EMAIL, MAIL_FROM_NAME); - $mail->Subject = $envelope['subject']; - $mail->Body = $envelope['body']; - - return (!$mail->send()) ? false : true; - - } - - - /** send_mailjet - * - * send email using CURL mail-relay of Mailjet - * - * @param $envelope - * @return success_starus (boolean) - */ - public static function send_mailjet($envelope) - { - $body = [ - 'Messages' => [ - [ - 'From' => [ - 'Email' => REPLY_TO_EMAIL, - 'Name' => MAIL_FROM_NAME - ], - 'To' => [ - [ - 'Email' => $envelope['email'], - 'Name' => $envelope['name'] - ] - ], - 'Subject' => $envelope['subject'], - 'HTMLPart' => $envelope['body'] - ] - ] - ]; - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, "https://api.mailjet.com/v3.1/send"); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json') - ); - curl_setopt( - $ch, - CURLOPT_USERPWD, - MAILJET_APIKEY. ':'. MAILJET_SECRET - ); - $server_output = curl_exec($ch); - curl_close ($ch); - - $response = json_decode($server_output); - - return ($response->Messages[0]->Status == 'success'); - - } - - - -} - - - - - -/** NOTE: - * ----------------------------------------------------------------------------- - * (brainstorming) - * - -Optimization per concept alternative technologies ---- -- -- - - - - -## Session -File Session -Database Session -Redis Session -Memcached Session - ---- - -## Cache -File Cache -Database Cache -Redis Cache -Memcashed Cache - ---- - -## Log -File Log -Database Log -Log event to Slack -Log event to Email - - * ----------------------------------------------------------------------------- - */ diff --git a/public/app/models/Access_model.php b/public/app/models/Access_model.php new file mode 100644 index 0000000..d5ae19e --- /dev/null +++ b/public/app/models/Access_model.php @@ -0,0 +1,269 @@ +query( + "SELECT * FROM user WHERE email = :email AND active = 1", + [ ':email' => $email ] + )->getFirst(); + + // if no user, return false + if ($user === false) return false; + + return $user; + } + + + /** get user (by index key) + * + * user detailed array + * includes all user properties + granted roles + privileges + * + * @param $id (int) : user id + * @param $value (string) + */ + public static function getUser($id) + { + $user = Registry::use('database')->query( + "SELECT user.*, + ( -- construct array (json) of roles granted to user + SELECT CONCAT( + '[', + GROUP_CONCAT(role.id), + ']' + ) + FROM `role` + WHERE role.id IN ( + SELECT user_role.role_id + FROM user_role + WHERE user_role.user_id = :id + ) + ) AS Roles_json, + ( -- construct array of (root-)privileges granted to user + SELECT CONCAT( + '[', + GROUP_CONCAT(privilege.id), + ']' + ) + FROM privilege + WHERE privilege.id IN ( + SELECT user_privilege.privilege_id + FROM user_privilege + WHERE user_privilege.user_id = :id + ) + ) AS RootPrivileges_json, + ( -- construct array of (root-)privileges granted to user + SELECT CONCAT( + '[', + GROUP_CONCAT(privilege.includes), + ']' + ) + FROM privilege + WHERE privilege.id IN ( + SELECT user_privilege.privilege_id + FROM user_privilege + WHERE user_privilege.user_id = :id + ) + ) AS SubPrivileges_json + FROM user + WHERE id = :id", + [ ':id' => $id ] + )->getFirst(); + + + // if no user, return false + if ($user === false) return false; + + + // TODO: + // * merge root+sub privilede lists + // * convert json strings to php arrays + + + // TODO: + // cache user super array + + return $user; + } + + + /** create user + * + * creates user record; + * assigns privileged (usualy defaults); + * creates activation_code + * + * @param $data (array): Request->POST array + * @param $password (string): secure hashed password + * + * @return $activation_code + * + */ + public static function registerUser($data, $password, $privileges = DEFAULT_PRIVILEGES) + { + $required_fields = [ + 'name', + 'surname', + 'email', + 'password' + ]; + + // check required fields + $isOK = true; + foreach($required_fields as $fi) { + if (empty($data[$fi])) $isOK = false; + } + // if empty required fields exists ... return false + if (!$isOK) { + return [ "success" => false, 'error' => EMPTY_REQUIRED_FIELDS ]; + } + + // create an activation code + $activation_code = md5($data['email'].time().rand(0, 10000)); + + // if isOK go on and... + // create user record + $new_user_id = Registry::use('database')->query( + "INSERT INTO user + (`first_name`, `last_name`, `email`, `password`, `active`, `activation`) + VALUES + (:nam, :surname, :email, :pass, :act, :actcode)", + [ + ':nam' => $data['name'], + ':surname' => $data['surname'], + ':email' => $data['email'], + ':pass' => $password, + ':act' => 0, // needs email confirmation to be activated ... + ':actcode' => $activation_code // ... with the activation code + ] + )->lastInsertID(); + + // set default privileges + self::set_user_privileges($new_user_id, $privileges); + + // set reader role + self::set_user_role($new_user_id, 5); + + // update history + History_model::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'Create User Account'); + + // return success and user id + return [ + "success" => true, + 'id' => $new_user_id , + 'activation' => $activation_code + ]; + } + + + /** activate + * + * check if activation code is valid; + * if valid, set account active; + * + * @param $ticket (hex/MD5): activation code; + * + */ + public static function activate($ticket) + { + $user = Registry::use('database')->query( + "SELECT * FROM user WHERE activation = :ticket", + [ 'ticket' => $ticket ] + )->getFirst(); + + // if no user with this activation code, return false + if ($user === false) return false; + + // remove activation code from user record + Registry::use('database')->runQuery( + "UPDATE user + SET active = 1, `activation` = NULL + WHERE activation = :ticket", + [ 'ticket' => $ticket ] + ); + + // update history + History_model::trackUserAccess($user['id'], TRACK_ACCOUNT, 'User Account Activated'); + + return true; + + } + + + + ## Set permission methods + ## ------------------------------------------------------------------------- + + + /** set_user_privileges + * + * @param $privileges (array) + */ + public static function set_user_privileges($user, $privileges) + { + $db = Registry::use('database'); // database connection + foreach($privileges as $pri) { // pri = privilege id + $db->runQuery( + "INSERT INTO user_privilege (user_id, privilege_id) VALUES (:user, :pri)", + [ ':user' => $user, ":pri" => $pri ] + ); + } + return true; + } + + + /** set_user_role + * + * user, role are (int) IDs + */ + public static function set_user_role($user, $role) + { + + Registry::use('database')->runQuery( + "INSERT INTO user_role (user_id, role_id) VALUES (:user, :role)", + [ ':user' => $user, ":role" => $role ] + ); + + return true; + } + + + ## List methods + ## ------------------------------------------------------------------------- + + + /** privileges + * --- + * get all privileges (as a list) + * used by cacher; speeds up seveal things + * + * @param void + * @return privileges (array) + */ + public static function privileges() + { + return Registry::use('database')->runQuery( + "SELECT * FROM privilege",[] + ); + } + + +} diff --git a/public/app/models/History_model.php b/public/app/models/History_model.php new file mode 100644 index 0000000..f50539f --- /dev/null +++ b/public/app/models/History_model.php @@ -0,0 +1,34 @@ +query( + "INSERT INTO history + (user_id, `type`, `message`, `note`, `ip`) + VALUES + (:uid, :type, :msg, :note, :ip)", + [ + ':uid' => $user_id, + ':type' => $type, + ':msg' => $message, + ':note' => $note, + ':ip' => Registry::get('REQUEST')->IP + ] + )->lastInsertID(); + + } + + + +} \ No newline at end of file diff --git a/public/app/models/User_model.php b/public/app/models/User_model.php deleted file mode 100644 index f799dd9..0000000 --- a/public/app/models/User_model.php +++ /dev/null @@ -1,311 +0,0 @@ -query( - "SELECT * FROM user WHERE email = :email AND active = 1", - [ ':email' => $email ] - )->getFirst(); - - // if no user, return false - if ($user === false) return false; - - return $user; - } - - - /** get user (by index key) - * - * user detailed array - * includes all user properties + granted roles + privileges - * - * @param $id (int) : user id - * @param $value (string) - */ - public static function getUser($id) - { - $user = Registry::use('database')->query( - "SELECT user.*, - ( -- construct array (json) of roles granted to user - SELECT CONCAT( - '[', - GROUP_CONCAT(role.id), - ']' - ) - FROM `role` - WHERE role.id IN ( - SELECT user_role.role_id - FROM user_role - WHERE user_role.user_id = :id - ) - ) AS Roles_json, - ( -- construct array of (root-)privileges granted to user - SELECT CONCAT( - '[', - GROUP_CONCAT(privilege.id), - ']' - ) - FROM privilege - WHERE privilege.id IN ( - SELECT user_privilege.privilege_id - FROM user_privilege - WHERE user_privilege.user_id = :id - ) - ) AS RootPrivileges_json, - ( -- construct array of (root-)privileges granted to user - SELECT CONCAT( - '[', - GROUP_CONCAT(privilege.includes), - ']' - ) - FROM privilege - WHERE privilege.id IN ( - SELECT user_privilege.privilege_id - FROM user_privilege - WHERE user_privilege.user_id = :id - ) - ) AS SubPrivileges_json - FROM user - WHERE id = :id", - [ ':id' => $id ] - )->getFirst(); - - - // if no user, return false - if ($user === false) return false; - - - // TODO: - // * merge root+sub privilede lists - // * convert json strings to php arrays - - - // TODO: - // cache user super array - - return $user; - } - - - /** create user - * - * creates user record; - * assigns privileged (usualy defaults); - * creates activation_code - * - * @param $data (array): Request->POST array - * @param $password (string): secure hashed password - * - * @return $activation_code - * - */ - public static function registerUser($data, $password, $privileges = DEFAULT_PRIVILEGES) - { - $required_fields = [ - 'name', - 'surname', - 'email', - 'password' - ]; - - // check required fields - $isOK = true; - foreach($required_fields as $fi) { - if (empty($data[$fi])) $isOK = false; - } - // if empty required fields exists ... return false - if (!$isOK) { - return [ "success" => false, 'error' => EMPTY_REQUIRED_FIELDS ]; - } - - - // TODO: - // check if email exists - // ... - - // create an activation code - $activation_code = md5($data['email'].time().rand(0, 10000)); - - // if isOK go on and... - // create user record - $new_user_id = Registry::use('database')->query( - "INSERT INTO user - (`first_name`, `last_name`, `email`, `password`, `active`, `activation`) - VALUES - (:nam, :surname, :email, :pass, :act, :actcode)", - [ - ':nam' => $data['name'], - ':surname' => $data['surname'], - ':email' => $data['email'], - ':pass' => $password, - ':act' => 0, // needs email confirmation to be activated ... - ':actcode' => $activation_code // ... with the activation code - ] - )->lastInsertID(); - - // set default privileges - self::set_user_privileges($new_user_id, $privileges); - - // set reader role - self::set_user_role($new_user_id, 5); - - // update history - History_model::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'Create User Account'); - - // return success and user id - return [ - "success" => true, - 'id' => $new_user_id , - 'activation' => $activation_code - ]; - } - - - - ## Set permission methods - ## ------------------------------------------------------------------------- - - - /** set_user_privileges - * - * @param $privileges (array) - */ - public static function set_user_privileges($user, $privileges) - { - $db = Registry::use('database'); // database connection - foreach($privileges as $pri) { // pri = privilege id - $db->runQuery( - "INSERT INTO user_privilege (user_id, privilege_id) VALUES (:user, :pri)", - [ ':user' => $user, ":pri" => $pri ] - ); - } - return true; - } - - - /** set_user_role - * - * user, role are (int) IDs - */ - public static function set_user_role($user, $role) - { - - Registry::use('database')->runQuery( - "INSERT INTO user_role (user_id, role_id) VALUES (:user, :role)", - [ ':user' => $user, ":role" => $role ] - ); - - return true; - } - - - /** activate - * - * check if activation code is valid; - * if valid, set account active; - * - * @param $ticket (hex/MD5): activation code; - * - */ - public static function activate($ticket) - { - $user = Registry::use('database')->query( - "SELECT * FROM user WHERE activation = :ticket", - [ 'ticket' => $ticket ] - )->getFirst(); - - // if no user with this activation code, return false - if ($user === false) return false; - - // remove activation code from user record - Registry::use('database')->runQuery( - "UPDATE user - SET active = 1, `activation` = NULL - WHERE activation = :ticket", - [ 'ticket' => $ticket ] - ); - - // update history - History_model::trackUserAccess($user['id'], TRACK_ACCOUNT, 'User Account Activated'); - - return true; - - } - - - ## documention methods - ## methods related to properties that determin user's access - ##-------------------------------------------------------------------------- - -} - -/* example query getUser (super-array) ---- -- -- - - - - -SELECT user.*, -( -- array (json) of roles granted to user - SELECT CONCAT('[', GROUP_CONCAT(role.id), ']') - FROM `role` - WHERE role.id IN ( - SELECT user_role.role_id - FROM user_role - WHERE user_role.user_id = 1 - ) -) AS Roles_json, -( - SELECT CONCAT( - '[', - GROUP_CONCAT(privilege.id), - ']' - ) - FROM privilege - WHERE privilege.id IN ( - SELECT user_privilege.privilege_id - FROM user_privilege - WHERE user_privilege.user_id = 1 - ) -) AS RootPrivileges_json, -( - SELECT CONCAT( -- array of array of sub-privileges - '[', - GROUP_CONCAT( -- array (json) of subprivileges - ( - SELECT CONCAT( - '[', - GROUP_CONCAT(included_id), - ']' - ) - FROM privilege_includes - WHERE privilege_id = privilege.id - ) - ), - ']' - ) - FROM privilege - WHERE privilege.id IN ( - SELECT user_privilege.privilege_id - FROM user_privilege - WHERE user_id = 1 - ) -) AS SubPrivileges_json -FROM user -WHERE id = 1 ---- */ \ No newline at end of file diff --git a/public/app/models/admin/History_model.php b/public/app/models/admin/History_model.php deleted file mode 100644 index 04ce630..0000000 --- a/public/app/models/admin/History_model.php +++ /dev/null @@ -1,34 +0,0 @@ -query( - "INSERT INTO history - (user_id, `type`, `message`, `note`, `ip`) - VALUES - (:uid, :type, :msg, :note, :ip)", - [ - ':uid' => $user_id, - ':type' => $type, - ':msg' => $message, - ':note' => $note, - ':ip' => Registry::get('REQUEST')->IP - ] - )->lastInsertID(); - - } - - - -} \ No newline at end of file diff --git a/public/app/models/admin/Privilege_model.php b/public/app/models/admin/Privilege_model.php deleted file mode 100644 index c385484..0000000 --- a/public/app/models/admin/Privilege_model.php +++ /dev/null @@ -1,42 +0,0 @@ -runQuery( - "SELECT * FROM privilege",[] - ); - } - - /** edit privileges - * --- - */ - public static function edit_privileges() - { - // TODO: ... - } - - - /** update course - * --- - */ - public static function update_course() - { - // TODO: ... - } - -} \ No newline at end of file diff --git a/public/app/models/todo.md b/public/app/models/todo.md index 5a18f38..ec027a6 100644 --- a/public/app/models/todo.md +++ b/public/app/models/todo.md @@ -13,9 +13,9 @@ Rearange [ok] app\models\admin\User_model -> [*] app\models\User_model -app\models\admin\Privilege_model -> [merge_to] -> [**] app\models\User_model +[ok] app\models\admin\Privilege_model -> [merge_to] -> [**] app\models\User_model -app\models\admin\History_model -> [*] app\models\History_model +[ok] app\models\admin\History_model -> [*] app\models\History_model [ok] app\models\cms\Page_model -> [delete] @@ -23,6 +23,7 @@ app\models\admin\History_model -> [*] app\models\History_model [ok] app\models\cms\Course_model -> [*] app\models\Course_model + [*] = move @@ -34,7 +35,7 @@ app\models\admin\History_model -> [*] app\models\History_model [ok] app\models\Course_model -> [rename] app\models\Cms_model - +[ok] app\extends\Send_mail -> [rename] SendMail_service -- cgit v1.2.3