summaryrefslogtreecommitdiff
path: root/html/app/models/admin/User_model.php
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-30 05:03:23 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-30 05:03:23 +0300
commit4f2d900af7636e6744ae14aeeefdf2d6080ac50a (patch)
tree1f80775437510591656e6ef13375516226ed27f3 /html/app/models/admin/User_model.php
parenta16d070c4f8301a8b68220aca6d3573705be9025 (diff)
downloadclassroom-4f2d900af7636e6744ae14aeeefdf2d6080ac50a.tar.gz
classroom-4f2d900af7636e6744ae14aeeefdf2d6080ac50a.tar.bz2
classroom-4f2d900af7636e6744ae14aeeefdf2d6080ac50a.zip
several mail options tested; mailhog (fake) mailer is working
Diffstat (limited to 'html/app/models/admin/User_model.php')
-rw-r--r--html/app/models/admin/User_model.php52
1 files changed, 35 insertions, 17 deletions
diff --git a/html/app/models/admin/User_model.php b/html/app/models/admin/User_model.php
index e4ac2ea..d0def1b 100644
--- a/html/app/models/admin/User_model.php
+++ b/html/app/models/admin/User_model.php
@@ -119,10 +119,18 @@ class User_model
/** 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, $privileges = ['ec.1', 'pr.1'])
+ public static function registerUser($data, $password, $privileges = ['ec.1', 'pr.1'])
{
-
$required_fields = [
'name',
'surname',
@@ -140,33 +148,43 @@ class User_model
return [ "success" => false, 'error' => EMPTY_REQUIRED_FIELDS ];
}
- // if isOK go on and create user record
- $user = [
- 'prefix' => $data['prefix'] ?? '',
- 'name' => $data['name'],
- 'surname' => $data['surname'],
- 'email' => $data['email'],
- 'password' => $data['password'],
- 'active' => 0 // needs email confirmation
- ];
- // insert new user record
+ // 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
- (`prefix`, `name`, `surname`, email, `password`, user_id)
+ (`first_name`, `last_name`, `email`, `password`, `active`, `activation`)
VALUES
- (:prefic, :name, :surname, :email, :password, :userid)"
- [ $user ]
+ (: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($privileges);
+ // self::set_user_privileges($privileges);
// update history
History::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'Create User Account');
// return success and user id
- return [ "success" => true, 'id' => $new_user_id ];
+ return [
+ "success" => true,
+ 'id' => $new_user_id ,
+ 'activation' => $activation_code
+ ];
}