summaryrefslogtreecommitdiff
path: root/html/app/models/admin/User_model.php
diff options
context:
space:
mode:
Diffstat (limited to 'html/app/models/admin/User_model.php')
-rw-r--r--html/app/models/admin/User_model.php40
1 files changed, 34 insertions, 6 deletions
diff --git a/html/app/models/admin/User_model.php b/html/app/models/admin/User_model.php
index bfed5c5..187da2d 100644
--- a/html/app/models/admin/User_model.php
+++ b/html/app/models/admin/User_model.php
@@ -129,7 +129,7 @@ class User_model
* @return $activation_code
*
*/
- public static function registerUser($data, $password, $privileges = ['ec.1', 'pr.1'])
+ public static function registerUser($data, $password, $privileges = DEFAULT_PRIVILEGES)
{
$required_fields = [
'name',
@@ -174,7 +174,7 @@ class User_model
)->lastInsertID();
// set default privileges
- // self::set_user_privileges($privileges);
+ // self::set_user_privileges($new_user_id, $privileges);
// update history
History::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'Create User Account');
@@ -188,26 +188,54 @@ class User_model
}
- public static fuunction activate($ticket)
+ public static function activate($ticket)
{
$user = Registry::use('database')->query(
"SELECT * FROM user WHERE activation = :ticket",
- [ 'ticket' => $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 activated = 1 WHERE activation = :ticket",
- [ 'ticket' => $ticket]
+ "UPDATE user
+ SET activated = 1, `activation` = NULL
+ WHERE activation = :ticket",
+ [ 'ticket' => $ticket ]
);
+ // update history
+ History::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'User Account Activated');
+
return true;
}
+ /** set_user_privileges
+ *
+ * @param $user_id (int)
+ * @param $privileges (array)
+ */
+ public static function set_user_privileges($user_id, $privileges)
+ {
+
+ foreach($privileges as $pri) {
+ Registry::use('database')->runQuery(
+ "INSERT INTO user_privilege (user_id, privilege_id)
+ VALUES (:user, :privilege)",
+ [
+ ':user' => $user_id,
+ ':privilege' => $pri
+ ]
+ );
+ }
+
+ return true;
+ }
+
/** inherited privileges
*
* list of all inhereted (sub-)privileges