summaryrefslogtreecommitdiff
path: root/html/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'html/app/models')
-rw-r--r--html/app/models/admin/History_model.php25
-rw-r--r--html/app/models/admin/User_model.php52
2 files changed, 47 insertions, 30 deletions
diff --git a/html/app/models/admin/History_model.php b/html/app/models/admin/History_model.php
index 438121e..04ce630 100644
--- a/html/app/models/admin/History_model.php
+++ b/html/app/models/admin/History_model.php
@@ -1,31 +1,30 @@
<?php
-
namespace app\models\admin;
use \Registry;
-class Histrory_model
+class History_model
{
/** track user access
*
*/
- public static function trackUserAccess($user_id, $type, $message, $note='')
+ public static function trackUserAccess($user_id, $type, $message, $note='_')
{
- $access = [
- 'user_id' => $user_id,
- 'type' => $type,
- 'message' => $message,
- 'note' => $note,
- 'ip' => Registry::get('REQUEST')->IP
- ];
Registry::use('database')->query(
"INSERT INTO history
- (user_id, `type`, `message`, note, ip)
- VALUES (:user_id, :type, :message, note, :ip)",
- [ $access ]
+ (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();
}
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
+ ];
}